Sort an ArrayCollection

By | 29 December, 2011

If you have an ArrayCollection and need to sort it, heres a quick example:

import mx.collections.ISort;
import mx.collections.ISortField;

var sort:ISort = new Sort();
var sortfieldNome:ISortField = new SortField(“name”,true); // “name” is a field on the arraycollection
var sortfieldEmail:ISortField = new SortField(“email”,true); // “email” is another field on the arraycollection
sort.fields = [sortfieldNome, sortfieldEmail];
myArrayCollection.sort = sort;

// this next line is used if you want the sort to be reversed.

// sort.reverse();

// Apply the sort to the collection.
myArrayCollection.refresh();

References:

from Adobe Help – spark.collections.sort – read it. its a good source of information