Tuesday, April 21, 2009

Depths in AS3

In AS3 it is easiest to work with depths in relative terms: Which element should be on top of the other?

Most people think this way anyway, the language reflects that now.


// get the depth of an existing sprite:
var depth:uint = getChildIndex(topMC);

//place mySprite under topMC:
addChildAt(mySprite, depth);

// or just:
addChildAt(mySprite, getChildIndex(topMC));

// directly set depth index:
setChildIndex(myMC, depth);

No comments: