Returns
The return value depends on whether you pass any parameters:
•
If you specify a value of 4 or Array.UNIQUE for
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 Array.RETURNINDEXEDARRAY for
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.
Description
Method; sorts the elements in an array according to one or more fields in the array. If you pass
multiple
fieldName
represents the next sort field, and so on. Flash sorts according to ASCII (Unicode) values. If either
of the elements being compared does not contain the field specified in the
the field is assumed to be
array in no particular order.
By default,
Array
•
Sorting is case sensitive (Z precedes a).
•
Sorting is ascending (a precedes b).
•
The array is modified to reflect the sort order; multiple elements that have identical sort fields
are placed consecutively in the sorted array in no particular order.
•
Numeric fields are sorted as if they were strings, so 100 precedes 99, because "1" is a lower
string value than "9".
•
Nothing is returned.
You can use the
forms of the
option
an array with only one field), or if you want to specify a sort order that the
doesn't support, use
To pass multiple flags in numeric format, separate them with the
add the values of the flags together. The following code shows three different ways to specify a
numeric descending sort:
my_Array.sortOn(someFieldName, 2 | 16);
my_Array.sortOn(someFieldName, 18);
my_Array.sortOn(someFieldName, Array.DESCENDING | Array.NUMERIC);
Code hinting (see
(for example,
DESCENDING
Consider the following array:
var my_array:Array = new Array();
my_array.push({password: "Bob", age:29});
my_array.push({password: "abcd", age:3});
my_array.push({password: "barb", age:35});
my_array.push({password: "catchy", age:4});
284
Chapter 12: ActionScript Dictionary
parameters, the first field represents the primary sort field, the second
, and the elements are placed consecutively in the sorted
undefined
.
works as follows:
sortOn()
flags to override these defaults. The following examples use different
option
flag for illustration purposes. If you want to sort a simple array (for example,
.
Array.sort()
"Using code hints" on page
) rather than the numeric form (2).
, and two or more elements being
option
| (bitwise OR)
63) is enabled if you use the string form of the flag
, Flash returns an
option
parameter,
fieldName
parameter
options
operator or
Need help?
Do you have a question about the FLASH MX 2004 - ACTIONSCRIPT and is the answer not in the manual?
Questions and answers