250
Chapter 6: ActionScript Core Classes
Example
Usage 1: The following example shows the use of
Array.sort()
with and without a value passed
for
option
:
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); // writes
apples,cherries,oranges,pineapples,strawberries
fruits_array.sort(Array.DESCENDING);
trace(fruits_array); // writes
strawberries,pineapples,oranges,cherries,apples
Usage 2: The following example uses
Array.sort()
with a compare function:
var passwords_array:Array = new Array("mom:glam", "ana:ring", "jay:mag",
"anne:home", "regina:silly");
function order(a, b):Number {
//Entries to be sorted are in form name:password
//Sort using only the name part of the entry as a key.
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;
}
}
trace("Unsorted:");
//displays Unsorted:
trace(passwords_array);
//writes mom:glam,ana:ring,jay:mag,anne:home,regina:silly
passwords_array.sort(order);
trace("Sorted:");
//displays Sorted:
trace(passwords_array);
//writes ana:ring,anne:home,jay:mag,mom:glam,regina:silly
See also
| (bitwise OR)
,
Array.sortOn()
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...