AS3 – Getting the order of MovieClips in the stage

Here is yet another small code snippet which allows you to get the order of MovieClips that are positioned on the stage.

var boxes:Array = [box1, box2, box3, box4]; //put the MovieClips into an array

function getOrder():void
{
  boxes.sortOn("x", Array.NUMERIC); //sort array on the x positions from smallest to largest
  trace(boxes); // traces the order of the boxes according to their x positions
}

getOrder();

Source for the demo above: Download