Learning ActionScript 2.0 in Adobe Flash |
|
|
|
| Syntax and Language Fundamentals > About dot syntax and target paths > About using dot syntax to target an instance > Targeting dynamic instances and loaded content | |||
You can also create an object using ActionScript and target it using a target path afterwards. For example, you can use the following ActionScript to create a movie clip. Then you can change the rotation of that movie clip using ActionScript, as shown in the next example:
To target a dynamically created movie clip instance:
this.createEmptyMovieClip("rotateClip", this.getNextHighestDepth());
trace(rotateClip);
rotateClip._rotation = 50;
You can tell that you created a movie clip because of the trace statement, but you cannot see anything on the Stage. Even though you added code that creates a movie clip instance, you won't see anything on the Stage unless you add something to the movie clip. For example, you might load an image into the movie clip.
rotateClip.loadMovie("http://www.helpexamples.com/flash/images/image1.jpg");
This code loads an image into the rotateClip movie clip that you created with code. You're targeting the rotateClip instance with ActionScript.
Now you should see an image on the Stage that rotates 50º clockwise.
You can also target or identify parts of SWF files that you load into a base SWF file.
To identify a loaded SWF file: _levelX, where X is the level number specified in the loadMovie() function that loaded the SWF file.
For example, a SWF file loaded into level 99 has the target path _level99. In the following example, you load a SWF file into level 99 and set its visibility to false:
//Load the SWF onto level 99.
loadMovieNum("contents.swf", 99);
//Set the visibility of level 99 to false.
loaderClip.onEnterFrame = function(){
_level99._visible = false;
};
|
TIP |
It's generally a good idea to avoid using levels if you can load content into movie clips at different depths instead. Using the |
You can set variables for instances that you nest inside of other instances. For example, if you want to set a variable for a form that's inside another form, you can use the following code. The instance submitBtn is inside of formClip on the main timeline:
this.formClip.submitBtn.mouseOver = true;
You can express a method or property of a particular object (such as a movie clip or text field) using this pattern. For example, the property of an object would be
myClip._alpha = 50;
|
|
|
|