248
Chapter 6: ActionScript Core Classes
Description
Method; returns a new array that consists of a range of elements from the original array, without
modifying the original array. The returned array includes the
start
element and all elements up
to, but not including, the
end
element.
If you don’t pass any parameters, a duplicate of
my_array
is created.
Example
The following example creates an array of five pets and uses
slice()
to populate a new array
comprising 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
slice()
with a negative
start
parameter to copy the last two elements from the array:
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
slice()
with a negative
end
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
Array.sort()
Availability
Flash Player 5; additional capabilities added in Flash Player 7.
Usage
my_array
.sort()
: Array
my_array
.sort(
compareFunction:Function
)
: Array
my_array
.sort(
option:Number
|
option
|... )
: Array
my_array
.sort(
compareFunction:Function
,
option:Number
|
option
|... )
: Array
Parameters
compareFunction
A comparison function used to determine the sorting order of elements in
an array. Given the elements A and B, the result of
compareFunction
can have one of the
following three values:
•
-1, if A should appear before B in the sorted sequence
•
0, if A equals B
•
1, if A should appear after B in the sorted sequence
Summary of Contents for FLEX-FLEX ACTIONSCRIPT LANGUAGE
Page 1: ...Flex ActionScript Language Reference...
Page 8: ......
Page 66: ...66 Chapter 2 Creating Custom Classes with ActionScript 2 0...
Page 76: ......
Page 133: ...break 133 See also for for in do while while switch case continue throw try catch finally...
Page 135: ...case 135 See also break default strict equality switch...
Page 146: ...146 Chapter 5 ActionScript Core Language Elements See also break continue while...
Page 808: ...808 Chapter 7 ActionScript for Flash...
Page 810: ...810 Appendix A Deprecated Flash 4 operators...
Page 815: ...Other keys 815 Num Lock 144 186 187 _ 189 191 192 219 220 221 222 Key Key code...
Page 816: ...816 Appendix B Keyboard Keys and Key Code Values...
Page 822: ...822 Index...