Note:
Array.sort()
Flash Player 7 are Flash-specific extensions to the ECMA-262 specification.
Returns
- The return value depends on whether you pass any parameters, as described in the
Array
following list:
If you specify a value of 4 or
■
more elements being sorted have identical sort fields, Flash returns a value of 0 and does
not modify the array.
If you specify a value of 8 or
■
Flash returns an array that reflects the results of the sort and does not modify the array.
Otherwise, Flash returns nothing and modifies the array to reflect the sort order.
■
Example
Usage 1: The following example shows the use of
passed for
:
options
var fruits_array:Array = new Array("oranges", "apples", "strawberries",
"pineapples", "cherries");
trace(fruits_array); // Displays
oranges,apples,strawberries,pineapples,cherries.
fruits_array.sort();
trace(fruits_array); // Displays
apples,cherries,oranges,pineapples,strawberries.
trace(fruits_array); // Writes
apples,cherries,oranges,pineapples,strawberries.
fruits_array.sort(Array.DESCENDING);
trace(fruits_array); // Displays
strawberries,pineapples,oranges,cherries,apples.
trace(fruits_array); // Writes
strawberries,pineapples,oranges,cherries,apples.
Usage 2: The following example uses
sorted in the form name:password. Sort using only the name part of the entry as a key:
var passwords_array:Array = new Array("mom:glam", "ana:ring", "jay:mag",
"anne:home", "regina:silly");
function order(a, b):Number {
var name1:String = a.split(":")[0];
var name2:String = b.split(":")[0];
if (name1<name2) {
return -1;
} else if (name1>name2) {
return 1;
} else {
return 0;
is defined in ECMA-262, but the array sorting options introduced in
Array.UNIQUESORT
Array.RETURNINDEXEDARRAY
Array.sort()
for the
parameter and two or
options
for the
with and without a value
Array.sort()
with a compare function. The entries are
parameter,
options
Array
261
Need help?
Do you have a question about the FLASH 8-FLASH LITE 2.X ACTIONSCRIPT LANGUAGE and is the answer not in the manual?
Questions and answers