Adding an External File to the Top of the Display List

Adding an External File to the Top of the Display List

Flash CS4 ActionScript 3.0 Tutorial


How to Place an Object on the Top Level of Display List in Flash



The Display List plays an important role in your Flash files. It keeps track of the all the objects on the stage at any given time. You can import external files or files from the Library and specify that they be added to the top, bottom or at a specific level.

It is easy to confuse the levels of the Display List and the layers in your Flash document. As you add objects to your layers, they are added to the Display List. It is possible to add external files at specific levels of the Display List or remove an object at a particular level.

In this example we will add an external file to the top of the Display List using the addChild() statement.

For more information on Display Lists, see topics, Adding a File to a Specific Level of a Display List, Adding an External File to the Bottom of the Display List, Checking the Display List Contents and Removing a File from the Display List.

Tutorial Elements

An external swf file named External.swf located in a folder named Swf. The folder should be at the same level at the host swf file.


Step One

Open a new Flash document and add a new layer.

Step Two

Name the upper layer Actions and the lower layer Content. Select frame one of the Content layer.

Step Three

Using the Oval tool, add a circle to the stage.

Step Four

Save your document and name it Main.fla. Add a new folder named Swf at the same level as your Main.fla file.

Step Five

Open a new document (File > New) named External.fla and save it in the Swf folder.

Step Six

Using the Rectangle tool, add a rectangle to the stage.

Step Seven

Publish your External movie by pressing Cmd/Return (PC - Ctrl/Enter).

Step Eight

Returning to the Main.fla file, Option double-click (PC - Alt double-click) frame one of the Actions layer.

Step Nine

Copy/Paste the following code to the ActionScript panel.

var loader01:Loader = new Loader();

loader01.load(new URLRequest("Swf/External.swf"));


Step Ten

Publish your movie by pressing Cmd/Return (PC - Ctrl/Enter). The external file is added to the stage above the oval object.

Dissecting the Code

The code at Step Nine adds a new Loader variable named loader01. The next line fills the loader with the External.swf file.

The final line adds the loader01 to the stage. By using the addChild() method, the external file is added at the top level.

Moving an Existing Asset to the Top

You can target any asset on the stage to be moved to the top of the Display List using the addChild() method.

For instance you may have a symbol with an instance name of grayBox_mc that is currently on the bottom level of the Display List.

To move it to the top, use the code:


Where's the Background?

Whenever you add an external swf file, the file's background displays as transparent. This feature is helpful as you add multiple objects cibntained in several external swf files.