Archive for January 16th, 2009
AS3 preloaders made easy in FlashDevelop
In my code based approach to development I frequently come across the problem of adding a preloader. For projects which are made in Flash authoring the typical one file approach is to add a light preloader in frame 1 of your fla and stuck everything else (including the classes) in frame 2. But how do you make that if you don’t even have an fla file? My favorite code editor FlashDevelop has this feature for AS2 already quite a while. As of beta8 release a similar preloader solution was added also for AS3 projects and today, inspired by Pretty Loaded from Big Spaceship, I finally put my hands on it and created an test project.
As a developer you only need to:
1. create a new project using the template AS3 Project with Preloader,
2. add preloader visuals and logic in the generated Preloader.as,
3. add all the rest of the project in the generated Main.as, the same as for a regular project,
4. compile and enjoy.
If you look at my screenshot or explore your resulting swf, it is can be understood that the first frame contain only the Preloader class and the rest is stuffed on frame 2. Bot how is it done? In step 1 FlashDevelop does a couple of things behind the scenes to tie together the Preloader and Test classes, but most of the magic comes from adding a compiler option -frame start com.edzis.preloadertest.Test. This tells the Flex compiler to add an additional frame, add a label start to it and include class com.edzis.preloadertest.Test in it. You may read the discussion about this feature on FlashDevelop forum or take a look at compiler option documentation. Note that the used -frame option is just a shortcut to the official -frames.frame.
You have to be careful if you change the name of your Main.as to something else; this requires changes in 2 other places:
1. var mainClass:Class = getDefinitionByName("YourClass") as Class; in Preloader.as,
2. -frame start YourClass in Project Properties -> Compiler Options -> Additional Compiler Options.
I don’t have much experience with Flex Builder or FDT, but I guess they do not have such feature. But as long as you use the same templates for Preloader and Main classes and find the right place to add the compiler options, there are no other limits.
Feel free to view the preloader in action and download project source.
