+展开-ActionScript
import mx.collections.Sort;
import mx.collections.ArrayCollection;
import mx.utils.ObjectUtil;
//the signature of a sort function must be
//function [name](a:Object, b:Object, fields:Array = null):int
private function sortFunction(a:Object, b:Object, fields:Array =
null):int {
var tempDateA:Date = new Date(Date.parse(a.dob));
var tempDateB:Date = new Date(Date.parse(b.dob));
return ObjectUtil.dateCompare(tempDateA, tempDateB);
}
private var arrColl:ArrayCollection;
private function init():void {
arrColl = new ArrayCollection([
{name:"Josh",dob:"08/17/1983"},
{name:"John",dob:"07/30/1946"},
{name:"John", dob:"07/30/1990"},
{name:"John",dob:"07/30/1986"}]);
var sort:Sort = new Sort();
sort.compareFunction = sortFunction;
arrColl.sort = sort;
arrColl.refresh();
trace(arrColl);
}