UPDATE: Thanks to the suggestions of Casey, I’ve updated the base class to use events from the loaderInfo instead of checking each frame, as well as using the frame label as the class name (which I believe is the idiom that Flex’s [Frame] metadata follows).
I reread the preloader post I made earlier today and it occurred to me I should make this an actual re-usable class. So, I did. Here’s the Preloader base class:
Usage is very straightforward. I made everything protected for easy sub-classing, but you shouldn’t have to override the event handlers, onProgress(), onComplete and onRemovePreloader().
As I discussed in my earlier article on the subject, you have to include a compiler argument to force your main application class to be loaded on a secondary frame. You do this using the -frame compiler argument like so: -frame frameLabel fullyQualifiedClassName.
To customize the preloader animation, override addPreloader(), updatePreloader() and removePreloader().
To create your main application class you can either pass the application class’s name into the constructor, e.g. super("com.mycompany.myapp.Application");, or you can use the class’s name as the frame label in the compiler argument, e.g. -frame com.mycompany.myapp.Application com.mycompany.myapp.Application. If you need to do something more specialized than just constructing your class and adding it to the stage, you can override createApplication().
Here’s an example of a preloader that displays progress as a percent in the top-left corner of the screen:
Tags: as3