User Guide

58 Chapter 2: ActionScript Basics
To dynamically create a movie clip:
Use the MovieClip.attachMovie(), MovieClip.createEmptyMovieClip(), or
MovieClip.duplicateMovieClip() method. The following example uses the
attachMovie() method to dynamically create the purpleDot2_mc movie clip and place it on
top of the
greenBox_mc movie clip when the user rolls over the greenBox_mc clip, which is on
the Stage:
my_btn.onRollOut = function(){
this.greenBox_mc.attachMovie("purpleDot", "purpleDot2_mc", 2);
}
To identify a loaded SWF file:
Use _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 5 has the target path
_level5. In the following
example, a SWF file is loaded into level 5 and its visibility is set to
false:
//Load the SWF onto level 99.
loadMovieNum("contents.swf", 99);
//Set the visibility of level 99 to false.
loader_mc.onEnterFrame = function(){
_level99._visible = false;
};
To enter a SWF file’s target path:
In the Actions panel (Window > Development > Actions), click the Insert Target Path button
Select a movie clip from the list that appears.
For more information on target paths, see “Using absolute and relative target paths” in Using
Flash.
Using condition statements
To perform an action depending on whether a condition exists, or to repeat an action (create loop
statements), you can use
if, else, else if, for, while, do while, for..in, or switch
statements.
Checking conditions
Statements that check whether a condition is
true or false begin with the term if. If the
condition evaluates to
true, ActionScript executes the next statement. If the condition doesnt
exist, ActionScript skips to the next statement outside the block of code.
To optimize your codes performance, check for the most likely conditions first.
The following statements test three conditions. The term
else if specifies alternative tests to
perform if previous conditions are false.
if (password == null || email == null) {
gotoAndStop("reject");
} else if (password == userID){