Preload This!

Creating a Preloader in AS3

Creating a preloader in AS3 is pretty straight forward and really should be used any time your pulling resources into an SWF at runtime and yes I know the title is stupid.

There are a few steps involved so lets go one step at a time – be sure to import the appropriate class packages along the way.

Step 1 – Create an instance of the Loader class.

Step 2  – Create a URLRequest for the object you want to load making sure to pass the Url as a string

Step 3 – Add EventListeners to the Loader object and define the handlers for them

Step 4 – Initiate the load.

When you publish the file, you should see the percent loaded updating in the Output panel.

A real-world application would be to update a text field with the percent value (converted to a string of course).

Once the object is finished loading the Event.COMPLETE event is fired and the load_complete_handler adds the object to the stage.

Leave a Reply

Your email address will not be published. Required fields are marked *