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.

The following example creates a nested array that contains two arrays. The first array has three<br />

elements: Europa, Io, <strong>and</strong> Callisto. The second array has two elements: Titan <strong>and</strong> Rhea. It<br />

joins the array by using a plus sign (+), but the elements within each nested array remain<br />

separated by commas (,).<br />

var a_nested_array:Array = new Array(["Europa", "Io", "Callisto"],<br />

["Titan", "Rhea"]);<br />

trace(a_nested_array.join(" + "));<br />

// Returns Europa,Io,Callisto + Titan,Rhea.<br />

See also<br />

split (String.split method)<br />

length (Array.length property)<br />

public length : Number<br />

A non-negative integer specifying the number of elements in the array. This property is<br />

automatically updated when new elements are added to the array. When you assign a value to<br />

an array element (for example, my_array[index] = value), if index is a number, <strong>and</strong><br />

index+1 is greater than the length property, the length property is updated to index+1.<br />

Note: If you assign a value to the length property that is shorter than the existing length, the<br />

array will be truncated.<br />

Example<br />

The following code explains how the length property is updated. The initial length is 0, <strong>and</strong><br />

then updated to 1, 2, <strong>and</strong> 10. If you assign a value to the length property that is shorter than<br />

the existing length, the array will be truncated:<br />

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

trace(my_array.length); // initial length is 0<br />

my_array[0] = "a";<br />

trace(my_array.length); // my_array.length is updated to 1<br />

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

trace(my_array.length); // my_array.length is updated to 2<br />

my_array[9] = "c";<br />

trace(my_array.length); // my_array.length is updated to 10<br />

trace(my_array);<br />

// displays:<br />

//<br />

a,b,undefined,undefined,undefined,undefined,undefined,undefined,undefine<br />

d,c<br />

// if the length property is now set to 5, the array will be truncated<br />

my_array.length = 5;<br />

trace(my_array.length); // my_array.length is updated to 5<br />

238 ActionScript classes

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

Saved successfully!

Ooh no, something went wrong!