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()
Содержание FLEX-FLEX ACTIONSCRIPT LANGUAGE
Страница 1: ...Flex ActionScript Language Reference...
Страница 8: ......
Страница 66: ...66 Chapter 2 Creating Custom Classes with ActionScript 2 0...
Страница 76: ......
Страница 133: ...break 133 See also for for in do while while switch case continue throw try catch finally...
Страница 135: ...case 135 See also break default strict equality switch...
Страница 146: ...146 Chapter 5 ActionScript Core Language Elements See also break continue while...
Страница 229: ...while 229 i 3 The following result is written to the log file 0 3 6 9 12 15 18 See also do while continue for for in...
Страница 808: ...808 Chapter 7 ActionScript for Flash...
Страница 810: ...810 Appendix A Deprecated Flash 4 operators...
Страница 815: ...Other keys 815 Num Lock 144 186 187 _ 189 191 192 219 220 221 222 Key Key code...
Страница 816: ...816 Appendix B Keyboard Keys and Key Code Values...
Страница 822: ...822 Index...