Array Class Extensions

Locale-specific sorting

Flash’s versions of Array.sort and Array.sortOn methods perform sorting according to Unicode values. However, this is not always in correct order, especially for languages such as French, Spanish, German, etc. In the case of Unicode sorting, all strings containing diacritic marks (e.g., umlaut, accent, acute) appear after the letter ‘z’. Thus, on sorting the array [‘á’, ‘z’, ‘a’] Flash returns [‘a’, ‘z’, ‘á’] regardless to currently set locale. However, for French the result of locale-specific sorting should be [‘a’, ‘á’, ‘z’]. To address this issue, Scaleform introduces one more option for Array.sort/sortOn methods:

Array.LOCALE:

var arr = ['á', 'z', 'a'];
var newArr1 = arr.sort(); // returns ['a', 'z', 'á']
var newArrLoc = arr.sort(Array.LOCALE); // returns ['a', 'á', 'z']
var newArrRev = arr.sort(Array.LOCALE | Array.DESCENDING); // ['z', 'á', 'a']

Case insensitive locale-specific sorting is also supported:

var arr = ['Á', 'z', 'a'];
var a = arr.sort(Array.LOCALE | Array.CASEINSENSITIVE); // returns ['a', 'Á', 'z']

Note, this functionality might not work correctly on certain platforms, which do not support appropriate functionality in kernel. In this case Array.LOCALE sorting will perform as the regular one with Unicode values.

Scaleform version: 3.0.65

See also: String.localeCompare