Archive for April, 2009

ActionScript 3 – Z index function

Saturday, April 25th, 2009

This function lets you calculate the z-index or depth of an object in a flash movie based on its vertical position. The greater the y component the closer to the viewer the object is.

elements.sortOn("y", Array.NUMERIC);

var i:int = this.numChildren;
var a:int = elements.length;
while(a--){
i--;
setChildIndex(elements[a], i);
}