About using dot syntax to target an instance

To write ActionScript that controls an instance such as a movie clip or manipulates assets in a loaded SWF file, you must specify its name and its address in code. This is called a target path. To target (or address) objects in a SWF file, you use dot syntax (also called dot notation). For example, you need to target a movie clip or button instance before you can apply an action to it. Dot syntax helps you create a path to the instance you need to target. The path to the instance that you target is sometimes called the target path.

A FLA file has a particular hierarchy. You can create instances on the Stage or you can use ActionScript. You can even create instances that are inside other instances. Or you might have instances that nest within several other instances. You can manipulate any instance as long as you name it.

You name instances using an instance name, which you can specify in two different ways (both demonstrated below):

To assign the instance an instance name in the Property inspector, type a name into the Instance Name text box.

You can also give an instance name to an object you create using ActionScript. It can be as simple as the following code:

this.createEmptyMovieClip("pic_mc", this.getNextHighestDepth());
pic_mc.loadMovie("http://www.helpexamples.com/flash/images/image1.jpg");

This code creates a new movie clip and assigns it the instance name pic_mc. Then, you can manipulate the pic_mc instance using code, such as loading an image into it as demonstrated in the previous code.

For more information on working with scope, see About scope and targeting and About variables and scope.


Flash CS3


 

Send me an e-mail when comments are added to this page | Comment Report

Current page: http://livedocs.adobe.com/flash/9.0/main/00000679.html