Friday, May 9, 2008

Sort Display List Objects Based on Y Depth

Thanks to the example on this page:

http://www.senocular.com/flash/tutorials/as3withflashcs3/?page=2

function sortChildrenByY(container:MovieClip):void {
var i:int;
var childList:Array = new Array();
i = container.numChildren;
while(i--){
childList[i] = container.getChildAt(i);
}
childList.sortOn("y", Array.NUMERIC);
i = container.numChildren;
while(i--){
if (childList[i] != container.getChildAt(i)){
container.setChildIndex(childList[i], i);
}
}
}

sortChildrenByY(this);

No comments: