public static function sortChildrenByFauxZ( container:DisplayObjectContainer ) : Boolean
{
var numChildren:int = container.numChildren;
//no need to sort (zero or one child)
if( numChildren < 2 ) return false;
var depthsSwapped:Boolean;
//create an Array to sort children
var children:Array = new Array( numChildren );
var i:int = -1;
while( ++i < numChildren )
{
children[ i ] = container.getChildAt( i );
}
//sort by children's y position
children.sortOn( "y", Array.NUMERIC );
var child:DisplayObject;
i = -1;
while( ++i < (numChildren-1) )
{
child = DisplayObject( children[ i ] );
//only set new depth if necessary
if( i != container.getChildIndex( child ) )
{
depthsSwapped = true;
//set their new position
container.setChildIndex( child, i );
}
}
//returns true if 1 or more swaps were made, false otherwise
return depthsSwapped;
}
/////////////////////
///ZIndexSorter fp10
///////////////////
{
var numChildren:int = container.numChildren;
//no need to sort (zero or one child)
if( numChildren < 2 ) return false;
var depthsSwapped:Boolean;
//create an Array to sort children
var children:Array = new Array( numChildren );
var i:int = -1;
while( ++i < numChildren )
{
children[ i ] = container.getChildAt( i );
}
//sort by children's y position
children.sortOn( "y", Array.NUMERIC );
var child:DisplayObject;
i = -1;
while( ++i < (numChildren-1) )
{
child = DisplayObject( children[ i ] );
//only set new depth if necessary
if( i != container.getChildIndex( child ) )
{
depthsSwapped = true;
//set their new position
container.setChildIndex( child, i );
}
}
//returns true if 1 or more swaps were made, false otherwise
return depthsSwapped;
}
/////////////////////
///ZIndexSorter fp10
///////////////////
public class ZIndexSorter{
public static function sort(container:DisplayObjectContainer):void
{
var children_arr:Array = [];
for(var i:uint=0; i<container.numChildren; i++){
var d:DisplayObject = container.getChildAt(i);
var tM:Matrix3D = displayObject.transform.getRelativeMatrix3D(stage);
//把对应获得的数据Push到数组中准备排序
children_arr.push({
"displayObject": d,
"z": tM.position.z,
"x": Math.abs(tM.position.x - stage.stageWidth / 2)
});
}
children_arr.sortOn("z", Array.NUMERIC | Array.DESCENDING);
children_arr.sortOn("x", Array.NUMERIC | Array.DESCENDING);
var j:uint = 0;
while(j < children_arr.length){
container.setChildIndex(children_arr[j].displayObject, j);
++j;
}
}
}
浙公网安备 33010602011771号