I searched around a similar solution, except that I needed to sort the dictionary map and return a sorted collection associated with pairs of key values. After you did not find the published solution, I put together the approach below. This method takes the dictionary as input, creates an array that supports the association, then sorts the resulting array using array.sortOn () and returns the sorted results back as an array. For clarity, the key and value fields in the array are used in the example below, but any field name can be used.
This example assumes that the string object is the key and the numeric object as the value, although, of course, you can use any type of object and adjust the field parameters.
The approach below can also be used to sort by key instead of using the “key” value as the sort field for the sortOn method, and you can use different sorting options than the downstream numerical sorting I used here ( AS3 SortOn (Documentation ). The code below is not intentionally general to simplify it, for example, for purposes.
public static function sortDictionaryByValue(d:Dictionary):Array { var a:Array = new Array(); for (var dictionaryKey:Object in d) { a.push({key:dictionaryKey,value:d[dictionaryKey]}); } a.sortOn("value",[Array.NUMERIC|Array.DESCENDING]); return a; }
source share