03.05.2013 Views

FLASH® LITE™ 2.x - Adobe Help and Support

FLASH® LITE™ 2.x - Adobe Help and Support

FLASH® LITE™ 2.x - Adobe Help and Support

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

Usage 2: A value from the array; either a native type or an object instance (including an Array<br />

instance).<br />

Usage 3: A property from the object; either a native type or an object instance (including an<br />

Array instance).<br />

Example<br />

The following example shows two ways to create a new empty Array object; the first line uses<br />

brackets ([]):<br />

var my_array:Array = [];<br />

var my_array:Array = new Array();<br />

The following example creates an array called employee_array <strong>and</strong> uses the trace() statement<br />

to send the elements to the Output panel. In the fourth line, an element in the array is<br />

changed, <strong>and</strong> the fifth line sends the newly modified array to the Output panel:<br />

var employee_array = ["Barbara", "George", "Mary"];<br />

trace(employee_array); // output: Barbara,George,Mary<br />

employee_array[2] = "Sam";<br />

trace(employee_array); // output: Barbara,George,Sam<br />

In the following example, the expression inside the brackets ("piece" + i ) is evaluated <strong>and</strong><br />

the result is used as the name of the variable to be retrieved from the my_mc movie clip. In this<br />

example, the variable i must live on the same Timeline as the button. If the variable i is equal<br />

to 5, for example, the value of the variable piece5 in the my_mc movie clip is displayed in the<br />

Output panel:<br />

myBtn_btn.onRelease = function() {<br />

x = my_mc["piece"+i];<br />

trace(x);<br />

};<br />

In the following example, the expression inside the brackets is evaluated, <strong>and</strong> the result is<br />

used as the name of the variable to be retrieved from movie clip name_mc:<br />

name_mc["A" + i];<br />

If you are familiar with the Flash 4 ActionScript slash syntax, you can use the eval()<br />

function to accomplish the same result:<br />

eval("name_mc.A" & i);<br />

You can use the following ActionScript to loop over all objects in the _root scope, which is<br />

useful for debugging:<br />

for (i in _root) {<br />

trace(i+": "+_root[i]);<br />

}<br />

114 ActionScript language elements

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!