Removing a File from the Display List

Removing a File from the Display List

Flash CS4 ActionScript 3.0 Tutorial


How to Remove an Object from a Specific Level of the Display List Using Flash ActionScript



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.

To really understand the Display List it is helpful to know how Flash treats various objects. A document with several Merge Shapes and/or Drawing Objects on the same layer counts as one level.

A Movie Symbol that contains several objects counts as one level. A text object with several letters counts as one level. The same text object, broken apart once takes up several levels.

In this example, several items are added to the stage. Using ActionScript, we will remove an object from a specific level.

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, Adding an External File to the Top of the Display List and Checking the Display List Contents.

Tutorial Elements

Movie Symbol, Button Symbol and a Merge Shape


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 Merge Shape circle to the stage on the Content layer.

Step Four

Add a Button Symbol to the stage on the Content layer.

Step Five

Add a Movie Symbol to the stage on the Content layer.

Step Six

Option double-click (PC - Alt double-click) frame one in the Actions layer to open the ActionScript panel.

Step Seven

Copy/Paste the following code to the ActionScript panel.


Step Eight

Publish your movie by pressing Cmd/Return (PC - Ctrl/Enter). Because of the order that the objects were added to the stage, the oval was on level 0, the Button Symbol on 1 and the Movie Symbol on 2. The Button Symbol was removed with the removeChildAt(1) script.

Dissecting the Code

The code at Step Seven removes the child at level 1. Since the Button Symbol was added second, it was located on level 1.

Another option is to use the code, removeChild() and include the child's instance name in the parenthesis to remove a specific child.

Removing a Child by Name

To remove a child by name you would use the removeChild() method. For instance, if you had an instance on the stage named, greenBox_mc, you would use the following code:


Remove verses Unload

In this example we used the removeChildAt() method. Removing an object simply removes it from the display list. If you were using a loader, it would still be present in the loader.

If you wanted to totally remove an object from the loader, you would use the unload() method. To unload an object from a loader called ldr01 you would use the following code:


For more information on unloading a Loader, see topic, Removing an External File by Unloading a swf File.