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

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

endIndex:Number [optional] - A number specifying the index of the ending point for the<br />

slice. If you omit this parameter, the slice includes all elements from the starting point to the<br />

end of the array. If end is a negative number, the ending point is specified from the end of the<br />

array, where -1 is the last element.<br />

Returns<br />

Array - An array that consists of a range of elements from the original array.<br />

Example<br />

The following example creates an array of five pets <strong>and</strong> uses slice() to populate a new array<br />

that contains only four-legged pets:<br />

var myPets_array:Array = new Array("cat", "dog", "fish", "canary",<br />

"parrot");<br />

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

var myFourLeggedPets_array = myPets_array.slice(0, 2);<br />

trace(myFourLeggedPets_array); // Returns cat,dog.<br />

trace(myPets_array); // Returns cat,dog,fish,canary,parrot.<br />

The following example creates an array of five pets, <strong>and</strong> then uses slice() with a negative<br />

start parameter to copy the last two elements from the array:<br />

var myPets_array:Array = new Array("cat", "dog", "fish", "canary",<br />

"parrot");<br />

var myFlyingPets_array:Array = myPets_array.slice(-2);<br />

trace(myFlyingPets_array); // Traces canary,parrot.<br />

The following example creates an array of five pets <strong>and</strong> uses slice() with a negative end<br />

parameter to copy the middle element from the array:<br />

var myPets_array:Array = new Array("cat", "dog", "fish", "canary",<br />

"parrot");<br />

var myAquaticPets_array:Array = myPets_array.slice(2,-2);<br />

trace(myAquaticPets_array); // Returns fish.<br />

sort (Array.sort method)<br />

public sort([compareFunction:Object], [options:Number]) : Array<br />

Sorts the elements in an array. Flash sorts according to Unicode values. (ASCII is a subset of<br />

Unicode.)<br />

By default, Array.sort() works as described in the following list:<br />

■ Sorting is case-sensitive (Z precedes a).<br />

■ Sorting is ascending (a precedes b).<br />

■ The array is modified to reflect the sort order; multiple elements that have identical sort<br />

fields are placed consecutively in the sorted array in no particular order.<br />

242 ActionScript classes

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

Saved successfully!

Ooh no, something went wrong!