![MACROMEDIA Flash Lite 2 Скачать руководство пользователя страница 122](http://html1.mh-extra.com/html/macromedia/flash-lite-2/flash-lite-2_reference_687553122.webp)
122
ActionScript language elements
Example
The following example shows two ways to create a new empty Array object; the first line uses
brackets ([]):
var my_array:Array = [];
var my_array:Array = new Array();
The following example creates an array called
employee_array
and uses the trace() statement
to send the elements to the Output panel. In the fourth line, an element in the array is
changed, and the fifth line sends the newly modified array to the Output panel:
var employee_array = ["Barbara", "George", "Mary"];
trace(employee_array); // output: Barbara,George,Mary
employee_array[2] = "Sam";
trace(employee_array); // output: Barbara,George,Sam
In the following example, the expression inside the brackets (
"piece" + i
) is evaluated and
the result is used as the name of the variable to be retrieved from the
my_mc
movie clip. In this
example, the variable
i
must live on the same Timeline as the button. If the variable
i
is equal
to 5, for example, the value of the variable
piece5
in the
my_mc
movie clip is displayed in the
Output panel:
myBtn_btn.onRelease = function() {
x = my_mc["piece"+i];
trace(x);
};
In the following example, the expression inside the brackets is evaluated, and the result is used
as the name of the variable to be retrieved from movie clip
name_mc
:
name_mc["A" + i];
If you are familiar with the Flash 4 ActionScript slash syntax, you can use the
eval()
function to accomplish the same result:
eval("name_mc.A" & i);
You can use the following ActionScript to loop over all objects in the
_root
scope, which is
useful for debugging:
for (i in _root) {
trace(i+": "+_root[i]);
}
You can also use the array access ([]) operator on the left side of an assignment statement to
dynamically set instance, variable, and object names:
employee_array[2] = "Sam";
See also
Array
,
Object
,
eval function
Содержание Flash Lite 2
Страница 1: ...Flash Lite 2 x ActionScript Language Reference...
Страница 22: ...22 Contents...
Страница 244: ...244 ActionScript language elements...
Страница 760: ...760 ActionScript classes...