Sort (Array.sort Method) - MACROMEDIA FLASH 8-ACTIONSCRIPT 2.0 LANGUAGE Reference

Actionscript 2.0 language reference
Table of Contents

Advertisement

Example
The following example creates an array of five pets and uses
that contains only four-legged pets:
var myPets_array:Array = new Array("cat", "dog", "fish", "canary",
"parrot");
var myFourLeggedPets_array:Array = new Array();
var myFourLeggedPets_array = myPets_array.slice(0, 2);
trace(myFourLeggedPets_array); // Returns cat,dog.
trace(myPets_array); // Returns cat,dog,fish,canary,parrot.
The following example creates an array of five pets, and then uses
parameter to copy the last two elements from the array:
start
var myPets_array:Array = new Array("cat", "dog", "fish", "canary",
"parrot");
var myFlyingPets_array:Array = myPets_array.slice(-2);
trace(myFlyingPets_array); // Traces canary,parrot.
The following example creates an array of five pets and uses
parameter to copy the middle element from the array:
var myPets_array:Array = new Array("cat", "dog", "fish", "canary",
"parrot");
var myAquaticPets_array:Array = myPets_array.slice(2,-2);
trace(myAquaticPets_array); // Returns fish.

sort (Array.sort method)

public sort([compareFunction:Object], [options:Number]) : Array
Sorts the elements in an array. Flash sorts according to Unicode values. (ASCII is a subset of
Unicode.)
By default,
.
Array
sort()
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".
If you want to sort an array by using settings that deviate from the default settings, you can
either use one of the sorting options described in the entry for the
can create your own custom function to do the sorting. If you create a custom function, you
can use it by calling the
parameter (
compareFunction
256
ActionScript classes
works as described in the following list:
method, using the name of your custom function as the first
sort()
).
to populate a new array
slice()
with a negative
slice()
with a negative
slice()
parameter or you
options
end

Hide quick links:

Advertisement

Table of Contents
loading
Need help?

Need help?

Do you have a question about the FLASH 8-ACTIONSCRIPT 2.0 LANGUAGE and is the answer not in the manual?

This manual is also suitable for:

Flash 8

Table of Contents

Save PDF