转载http://xiazhihui321.blog.163.com/blog/static/813288932011724113134882/
import flash.display.MovieClip;
var list:Array=[];
for(var i:int=0;i<100;i++){
var mc:Test=new Test();
mc.x=Math.random()*stage.stageWidth;
mc.y=Math.random()*stage.stageHeight;
this.addChild(mc);
list.push(mc);
}
trace(getTimer());
list.sort(onSort);
function onSort(a:MovieClip,b:MovieClip){
if(a.y>b.y){
if(this.getChildIndex(a)<this.getChildIndex(b)){
this.swapChildren(a,b);
}
return 1;
}else if(a.y==b.y){
if(a.x>b.x){
if(this.getChildIndex(a)<this.getChildIndex(b)){
this.swapChildren(a,b);
}
return 1;
}
}else{
if(this.getChildIndex(a)>this.getChildIndex(b)){
this.swapChildren(a,b);
}
return -1;
}
}
trace(getTimer());
输出:
//15
//18