ActionScript 3 Layering


Example

There can be situations when you decide that one set of display objects should always be above another set of objects, for example, arrows over heads, explosions over something that just exploded, etc. To perform this as simple as possible, you need to designate and create a set of Sprites, arrange them in order from bottom to top, then just add all objects of "above" set to a layer above the one used for objects of "below" set.

var monsters:Vector.<Monster>;
var bullets:Vector.<Bullet>; // desired: bullets strictly above monsters
var monsterLayer:Sprite=new Sprite();
var bulletLayer:Sprite=new Sprite();
addChild(monsterLayer);
addChild(bulletLayer);

Then, whenever you add a Monster to the display list, add it to monsterLayer, and whenever you add a Bullet, add to bulletLayer to achieve the desired effect.