![]() ![]() ![]() | |
![]() | |
![]() | |
![]() |
You can use the dot operator (.
) and the array access operator ([]
) to access built-in or custom ActionScript object properties, including those of a movie clip.
The dot operator uses the name of an object on its left side and the name of a property or variable on its right side. The property or variable name can't be a string or a variable that evaluates to a string; it must be an identifier. The following examples use the dot operator:
year.month = "June"; year.month.day = 9;
The dot operator and the array access operator perform the same role, but the dot operator takes an identifier as its property, whereas the array access operator evaluates its contents to a name and then accesses the value of that named property. For example, the following expressions access the same variable velocity
in the movie clip rocket
:
rocket.velocity; rocket["velocity"];
You can use the array access operator to dynamically set and retrieve instance names and variables. For example, in the following code, the expression inside the []
operator is evaluated, and the result of the evaluation is used as the name of the variable to be retrieved from movie clip name
:
name["mc" + i]
You can also use the eval()
function, as shown here:
eval("mc" + i)
The array access operator can also be used on the left side of an assignment statement. This allows you to 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 = new Array(); for (var i=0; i<8; i++) { chessboard.push(new Array(8)); } function getContentsOfSquare(row, column){ chessboard[row][column]; }
You can check for matching []
operators in your scripts; see Checking syntax and punctuation.
![]() | |
![]() | |
![]() | |
![]() ![]() ![]() |