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.

var employee:Array = [15, "Barbara", "Jay"];<br />

You can nest brackets to simulate multidimensional arrays. You can nest arrays up to 256<br />

levels deep. The following code creates an array called ticTacToe with three elements; each<br />

element is also an array with three elements:<br />

var ticTacToe:Array = [[1, 2, 3], [4, 5, 6], [7, 8, 9]]; // Select Debug ><br />

List Variables in test mode<br />

// to see a list of the array elements.<br />

Usage 2: Surround the index of each element with brackets ([]) to access it directly; you can<br />

add a new element to an array, or you can change or retrieve the value of an existing element.<br />

The first index in an array is always 0, as shown in the following example:<br />

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

my_array[0] = 15;<br />

my_array[1] = "Hello";<br />

my_array[2] = true;<br />

You can use brackets ([]) to add a fourth element, as shown in the following example:<br />

my_array[3] = "George";<br />

You can use brackets ([]) to access an element in a multidimensional array. The first set of<br />

brackets identifies the element in the original array, <strong>and</strong> the second set identifies the element<br />

in the nested array. The following lines of code send the number 6 to the Output panel.<br />

var ticTacToe:Array = [[1, 2, 3], [4, 5, 6], [7, 8, 9]];<br />

trace(ticTacToe[1][2]);// output: 6<br />

Usage 3: You can use the array access ([]) operator instead of the eval() function to<br />

dynamically set <strong>and</strong> retrieve values for movie clip names or any property of an object. The<br />

following line of code sends the number 6 to the Output panel.<br />

name["mc" + i] = "left_corner";<br />

Oper<strong>and</strong>s<br />

myArray : Object - myArray The name of an array.<br />

a0, a1,...aN : Object - a0,a1,...aN Elements in an array; any native type or object<br />

instance, including nested arrays.<br />

i : Number - i An integer index greater than or equal to 0.<br />

myObject : Object - myObject The name of an object.<br />

propertyName : String - propertyName A string that names a property of the object.<br />

Returns<br />

Object -<br />

Usage 1: A reference to an array.<br />

Operators 113

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

Saved successfully!

Ooh no, something went wrong!