I would like to implement a sort on an ArrayCollection of composite
objects. I tried using a SortField, but I have to leave the name
property blank because the data I want to sort on is one level deeper
(object.child.property instead of object.property) than normal. When
I use a sort field in this manner, the refresh does not sort the
ArrayCollection as expected.
Here's a sample of what I'm talking about:
public function setupSort():Sort
{
var sort:Sort = new Sort();
var onlineSort:SortField = new SortField();
onlineSort.compareFunction = compareFunc;
sort.fields = [ onlineSort, new SortField("name", true) ];
return sort;
}
private function compareFunc(a:Object, b:Object):void
{
if ( a.buddyInfo.online && !b.buddyInfo.online ) return -1;
if ( b.buddyInfo.online && !a.buddyInfo.online ) return 1;
return 0;
}
(for reference, online is a Boolean)
If I call refresh on this list, I expect the online people to be
before the offline, but there is no rhyme or reason to the ordering.
Any suggestions?