Flash CS4 Preloading Exported Classes

2

Posted by Tyler Madison | Posted in Actionscript Tips | Posted on 10-07-2009

I have been utilizing AS3 for a little over 3 years and have always wanted to have the same control over preloading assets in my main .FLA , as I did with AS2. The main difference is that with Flash CS4 and AS3 , you can truly export your classes on a desired frame without having to dump all of the linked library assets on the stage prior to instantiating any of those exported assets with actionscript. This also allows you to keep the “Document Class” or main application class the entry point for the application.

Here’s the trick:

  1. 1. Go to File > Publish Settings > Click on the Flash tab. Under the player version next where it says script type , click on the “Settings” button. Where it says “Export classes in frame” type anything BUT 1 (2 is my standard). Click the ok buttons to exit out of those dialogs.
  2. Create a new MovieClip symbol in the library.
  3. In the Symbol Properties Dialog where it says “Linkage” click the checkbox that says “Export for ActionScript” , make sure the name of the symbol is the name of the class that you are using as your main application class or “Document Class”.
  4. Now all you have to do is instantiate a ExportTroller object and pass it the main movieclip reference (this) , the name of your main application class , the frameĀ  number you targeted for exporting your classes on in step 1, and optionally an update method to monitor download progress of the .SWF. (JUST LIKE in AS2!).
  5. publish the movie and you can see if you bring up the bandwidth profiler that the bulk of the .swf bytes has been deffered until your export frame! So you can do anything you want in the first frame to show progress, and get the user to start viewing your swf right away instead of waiting until the whole .swf has completely downloaded before they see anything,

If you followed the steps above correctly this is the only code you should need in your whole .FLA to get this to work!

//import the trolling class
import info.tylermadison.ExportTroller;

//instantiates the trolling object
var troller:ExportTroller = new ExportTroller(this , “Main” , 2 , updateMethod);

//the optional but recommended update method to show download progress
function updateMethod(prct:Number):void{
iLoader.width = prct * stage.stageWidth;
}

Download the source and demo Here!

Comments (2)

sorry to double post… here is the code

public function Main() {
trace(“Your Main Class Has been Created! ” + stage.stageWidth);
}

TypeError: Error #1009: bla bla null object
at Main()
at info.tylermadison::ExportTroller/initialize()
at info.tylermadison::ExportTroller/pollForExports()

send me the code source. tdmadison@gmail.com

Write a comment