Tutorial :Flex 3 sorting object fields



Question:

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 I am iterating to be sorted alphabetically. Any suggestions on how to do this?


Solution:1

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.


Solution:2

The ActionScript Foundry has an AS implementation of some of the Java collections--looks like you could find what you need there.


Note:If u also have question or solution just comment us below or mail us on toontricks1994@gmail.com
Previous
Next Post »