How to make a Flash PreLoader in AS3 Only

actionscript-3apache-flexflashpreloader

I want to incorporate a Flash Pre-loader in my application, but I am using only Flex SDK/AS3/Notepad to code this beast. I don't have access to the Flash IDE.

There are many tutorials and helpfiles online for how to do it within CS4, but not in the code itself. Can anyone give me direction here?

Most examples seem to pivot around placing a loader symbol into the first frame, before the rest of your application – but I don't have access to the timeline or frames from within flex (or at least, I don't think I do!).

Best Answer

You will want to read about some of the AS3 compiler directives--the relevant one in this case being factory class.

Essentially, you will need to create a class to load your main class that extends MovieClip. The 'preloader' class can monitor the bytesloaded/bytestotal and then instantiate your main class. The non-intuitive portion of this (for me at least) was including the diective: [Frame(factoryClass="pathToYourLoaderClass")]

in the top of your main class you want to preload.

Below is a great blog with more info and a good solution.

http://www.bit-101.com/blog/?p=946