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.

How does it behave when it comes to passing a variable from HTML code to Main.as ? i.e. when using SWFAddress ?
fh
17 Jan 09 at 12:13
This is not like loading another swf who is not in the same ApplicationDomain and SecurityDomain. I have not tested, but I don’t think there should be any problem.
1) Flashvars can be accessed from any place as long as it has a reference to the stage, also the Main.as as long as the ADDED_TO_STAGE event is caught. And in other situations there is always a possibility to store the flashvars in Preloader.as and in Main.as access them trough the parent property.
2) SWFAddress does not need to have any connection to the stage whatsoever, the job is done by accessing ststic methods of SWFAddress class. There are no changes required if you are adding the preloader logic to a project.
edzis
20 Jan 09 at 09:14
So I tried to add the preloader to my project. I put it in my project directory where my Main class is, and I still get an error saying it doesn’t know what Main is when it is supposed to switch to my document class. I did that thing “-frame start Main” in that spot.. so any ideas on why it’s not working? I’d appreciate your help. Thanks for sharing the preloader by the way. I hope I can use it.
Thanks
Dan
6 Aug 09 at 04:04
It is hard for me to debug by not seeing it.
An idea that I want to chech is maybe you have a different classpath?
edzis
6 Aug 09 at 09:59
I have the same problem as Dan did – we’ve completed a project and are trying to add the preloader afterwards. The “Frame 2:start tags” (in your class browser image) need to be added manually and I’m having great trouble finding the article I used last time I needed to do this.
pjbaron
8 Dec 09 at 07:02
Actually, just revisted Dan’s post, his problem was probably that he didn’t specify the package name:
-frame start pkg.Main
My problem is that even after adding this option, I’m not seeing anything get moved to frame 2.
pjbaron
8 Dec 09 at 07:24
Pjbaron, I wonder if you have marked the Preloader class to “Always Compile”? If so, how far in that class is your build advancing? Try setting trace statements in checkFrame and startup methods.
edzis
8 Dec 09 at 09:48