User Guide

Specifying an object’s path 57
function barGetProp():String {
return "bar";
}
function barSetProp(str:String):Void {
}
bar.addProperty("someProp", barGetProp, barSetProp);
//trace(bar.someProp); // generates an error
trace(bar["someProp"]); // no error
You can use the eval() function to dynamically set and retrieve instance names and variables, as
shown in the following example:
eval("mc" + i)
The array access operator can also be used on the left side of an assignment statement. This lets
you dynamically set instance, variable, and object names, as shown in the following example:
name[index] = "Gary";
You create multidimensional arrays in ActionScript by constructing an array, the elements of
which are also arrays. To access elements of a multidimensional array, you can nest the array access
operator with itself, as shown in the following example:
var chessboard:Array = new Array();
for (var i=0; i<8; i++) {
chessboard.push(new Array(8));
}
function getContentsOfSquare(row, column){
chessboard[row][column];
}
When you use the array access operator, the ActionScript compiler cannot check if the accessed
element is a valid property of the object.
You can check for matching
[] operators in your scripts; see “Checking syntax and punctuation
on page 150.
Specifying an object’s path
To use an action to control a movie clip or loaded SWF file, you must specify its name and its
address, called a target path.
In ActionScript, you identify a movie clip by its instance name, either in the Property inspector or
dynamically, at runtime. For example, in the following statement, the
_alpha property of the
movie clip named
star is set to 50% visibility:
star._alpha = 50;
To give a movie clip on the Stage an instance name:
1.
Select the movie clip on the Stage.
2.
Enter an instance name in the Property inspector in the Instance Name text box.