Using operators to manipulate values in expressions 49
Dot and array access operators
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";
%=
Modulo and assignment
/=
Division and assignment
<<=
Bitwise shift left and assignment
>>=
Bitwise shift right and assignment
>>>=
Shift right zero fill and assignment
^=
Bitwise XOR and assignment
|=
Bitwise OR and assignment
&=
Bitwise AND and assignment
Operator Operation performed