(I’ve inherited a Flex/AIR project and it’s been a while since I worked with Flex so forgive me if this is a basic question)
I have a Flex/AIR project which loads a directory of image file names and presents them in a Tree component. The user can then click on a file name to display the image.
I am stumped on why the sort (order of file names) is different in the Flex Tree component view from the (OSX) directory view. OSX is doing the smart thing and sorting on numeric as well as alpha value. The Flex Tree is not being so smart…as the screen shot below indicates.
I’ve been searching out the spark Sort and SortField collections but am not clear yet how I can use these. Is there a simple solution for doing the kind of sort I need: a way to tell Flex to consider the numeric portion of the file name?
Update:
Guess I am hunting the Snark.. called “natural sort” (sorting-for-humans-natural-sort-order)
…


The function to sort ‘naturally’ already exists in the as3-commons-lang project. In the
StringUtilsclass, look for the naturalCompare() function.Now all that is left to do, is to apply it to all the collections in your hierarchical structure. You’ll have to recursively loop through all the nodes in the tree and apply a sort function to each node’s
children.