Friday, April 15, 2011

Flex 3 sorting object fields

i have an object in actionScript3 code which i need to sort,

i iterate through the object and print out each value

for (var i:String in columnData)

however i need the data im iterating to be sorted aplhabetically. any suggestions on how to do this?

From stackoverflow
  • You can only sort Array/Lists, not fields in an object.

    If you want a sorted order, you first need to iterate thru the object and push the values in an array/list and then sort it.

    [Edit]: OK, so I assumed you just needed the data. No, flex doesn't provide a hashmap (like a TreeMap ala Java). What you could do is to store the name value pairs as objects in an array. Array provides a SortOn() method to let you sort on a specific field.

    combi001 : my problem is that the object contains name:value pairs so i cant just put into an arraylist
    combi001 : does flex provide any other datatype for storing name:value pairs , e.g like a hashmap in Java?
  • The ActionScript Foundry has an AS implementation of some of the Java collections--looks like you could find what you need there.


Post a Comment