This content has been marked as final. Show 3 replies
To sort the children, you have to access the children, test each, and sort accordingly (depending upon what type of sort-method you want to use -- bubble-sort, merge-sort, etc.)...
You'll have to test the name of each child component (assuming that 'name' is the data-field you want to sort on), and position/reorder/swap (ie -- sort), based upon the ordering ('alphabetical'?) comparison criteria.
The code might look something like the (hopefully) attached code...
Note that areOutOfOrder() would be some sort of test...:
if child.name > nextChild.name return FALSE, else return TRUE
You can implement this one of 2 ways: internal to a subclass of VBox (such as class MyVBoxClass), or external to it, such as within the application.
If you want to assure the children remain sorted, that is to sort during dynamic runtime adding/removing children, you'll have to listing to the vBox added/removed events, and call the sorting routine to make sure the children remain sorted...
Note that on removal, assuming the items were already sorted, they PROBABLY won't need to be resorted.
Hope that helps.
I wonder if you could store information on the children (name or whatever you sort on) in an ArrayCollection, and then sort that using a sortFunction. Then if the ArrayCollection gets triggered for a resort, remove and readd the children based on their order in the AC.
Are you adding these children manually, using mxml tags? If so, then sort doesn't make much sense.
If they are being added dynamically, consider using Repeater for instantiation/removal, and then just sort the dataProvider.