2007-11-26

Don't forget the power of callLater()

Don't forget that while you are developing in Flex your applications will run inside the Flash Player. One must remember that at its core the Flash Player is but a video player, and every Flex movie has but two frames. The first frame is for initialization work (when you see that progress bar appear) and the second frame is where the application executes. The second frame is the one that gets re-drawn X times per second, and the Player determines what parts to re-draw based on information provided by the Flex framework. This is why controls have an invalidateProperties() method, basically telling Flex that "hey I changed, I need to be re-drawn".

This is all fine and dandy and works, hmmm, 95% of the time, but sometimes you fall into these weird situations where things don't occur as you coded them. Happened to me just last week where I was developing a component to include in an email client that allowed the user to type a person's name or email and it would display a list of suggestions. Well once the user clicked outside of the component, the suggestion list should disappear but it didn't. You see sometimes your code won't execute in the same frame of animation as everything else; I don't really know why and probably only a Flash Player engineer can explain it. But what you can do is use Flex to tell the Flash Player to execute something in the next frame (probably when its less busy I guess?). You do this by using the global callLater() function like so:

// use it to call some local function
callLater( someFuncName );

// or direct inline call of a nameless function
callLater(
function() : {
... some code here ...
}
);

I've mostly used the second method because what I normally have to do is very short, like 1-2 lines of code. So for me this solved my problem, as I was able to close the suggestion list I was displaying. And it might do the same for you some day, so don't forget it :)

2007-11-19

People using AIR apps

It is very cool to see people at my office, non-developers use AIR based applications. First of all, our documentation master is big a music fan, so he uses Finetune to listen to his favorite tracks while he corrects all my spelling mistakes :) Secondly one of our big DBAs loves to wheel and deal on eBay, so he has began to use the eBay Desktop to get the job done. Both of these applications offer a better experience that their browser counterparts, and I think both of them demonstrate the potential of desktop-based RIAs.

2007-11-14

Intellij 7 Flex Module

As a follow up to my previous post, nicity was kind enough to point out that Intellij 7 does allow you to add a Flex module to your project. You do this by going to 'Settings | Project Settings | Modules' and press + (New) and select "Flex". Once that is done you can specify the path to your Flex SDK which I did.

This seems to kick off the reading of the content in the Flex SDK folder (and sub-folders), but it doesn`t seem to do anything after that. I tried editing an AS class and a MXML file to see if code-hinting was provided and such and there doesn`t seem to be any new options. Oh well, I guess this is only the beginning of the Flex support.