sortOn (Array.sortOn method)
public sortOn(fieldName:Object, [options:Object]) : Array
Sorts the elements in an array according to one or more fields in the array. The array should
have the following characteristics:
The array is an indexed array, not an associative array.
Each element of the array holds an object with one or more properties.
All of the objects have at least one property in common, the values of which can be used to
sort the array. Such a property is called a field.
If you pass multiple
fieldName
second represents the next sort field, and so on. Flash sorts according to Unicode values.
(ASCII is a subset of Unicode.) If either of the elements being compared does not contain the
field that is specified in the
the elements are placed consecutively in the sorted array in no particular order.
By default,
.
Array
sortOn()
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".
Flash Player 7 added the
behavior. To sort a simple array (for example, an array with only one field), or to specify a sort
order that the
options
To pass multiple flags, separate them with the bitwise OR (
my_array.sortOn(someFieldName, Array.DESCENDING | Array.NUMERIC);
Flash Player 8 added the ability to specify a different sorting option for each field when you
sort by more than one field. In Flash Player 8, the
options such that each sort option corresponds to a sort field in the
The following example sorts the primary sort field,
sort field,
, using a numeric sort; and the tertiary sort field,
b
Array.sortOn (["a", "b", "c"], [Array.DESCENDING, Array.NUMERIC,
Array.CASEINSENSITIVE]);
The
and
fieldName
the options array is ignored. Also, the
options can be used only as the first element in the array; otherwise, they are ignored.
parameters, the first field represents the primary sort field, the
parameter, the field is assumed to be
fieldName
works in the following way:
parameter, which you can use to override the default sort
options
parameter doesn't support, use
arrays must have the same number of elements; otherwise,
options
Array.UNIQUESORT
.
Array.sort()
) operator:
|
parameter accepts an array of sort
options
fieldName
, using a descending sort; the secondary
a
, using a case-insensitive sort:
c
and
Array.RETURNINDEXDARRAY
, and
undefined
parameter.
Array
259
Need help?
Do you have a question about the FLASH 8-ACTIONSCRIPT 2.0 LANGUAGE and is the answer not in the manual?