ActionScript3:Using the Loader Class to load an external swf
|Flash11 (CS5) | Flash10 (CS4) <|
|Table of contents|
By the end of this page you will be able to:
The Loader Class in ActionScript3 allows you to load external assets (including swf's) into your movie at runtime. This allows you to only load files as required and keeps the movie easy to manage and quick to load.
Setting the Main Stage
Create a new ActionScript3 Movie, in this example the stage is set at 400 x 300px.
- Rename Layer 1 as background.
- Insert a new layer and rename Buttons.
- Insert and new layer and rename Actions.
Create a background on the background layer, and insert onto the stage in the buttons layer any number of buttons to correspond with the number of external swf files you intend to bring onto the stage. Give them each a unique name. In this sample, the buttons have been positioned over the background to give a tabbed appearance and are named
Save your movie.
The External swf's
Create two new AS3 movies at the size you require your imported movies to be. In this case they are set to the size of the yellow body portion of the main movie (387 x 242px).
Save the Fla's and compile the swf's.
The ActionScript is inserted into Frame One of the Actions layer in the main movie. Make sure to name the swf's that the
URLRequest is calling to that which you have named in the step above. In this example, each button has its
eventListener removed when the corresponding swf is loaded (in effect disabling it). Two external movies are loaded, contactMovie.swf and worldMovie.swf. The
homeButton unloads the loader and returns to the main movie.
A simple example of using the Loader Class to load external swfs into our main movie.
For other ways to link up your AS3 swf's, check out these: