Saw this post on preloaders today. I see a lot of similar examples. What I don’t like about any of them is the fact that they use the [Frame] metadata, which—as far as I can tell—requires you to use IFlexModuleFactory which means you have to bring in some minimal portion of the Flex SDK. That, I don’t like.
I’m not sure why Adobe dictated this in mxmlc, there’s no reason that [Frame] would require this to be implemented correctly. Unfortunately, they did, so we have to resort to using a compiler argument to get the result we want.
[Frame] metadata basically equates to the -frame compiler argument, but a little reversed. With [Frame] you specify which class should be placed in the frame previous to the class it decorates; with -frame, you specify which frame a class should appear on.
My standard preloader is named for the application’s SWF (so I don’t have to add any extra compiler arguments in Flex Builder), and once it finishes preloading it instantiates the actual application’s root class, which I normally name Application.
Because the application usually does some additional remote service calls and asset loading after the SWF completes, I don’t remove the preloader until it’s notified by the application that’s it’s ready. I use an event to do this so that there’s no hard-references either way.
This is an important point: whatever you reference in your preloader will be placed in the first frame of your SWF, so you have to be sure and not reference your application class (or really, any classes outside of the flash.* packages) statically. What you do is load them by name using getClassDefinition() once you’ve determined that the entire SWF has loaded.
Tags: as3