Swapping the Depths of Children : Sprite : Development Flash / Flex / ActionScript examples


Flash / Flex / ActionScript examples » Development » Sprite »

 

Swapping the Depths of Children


 
package
{
    import flash.display.Sprite;
    import flash.events.*;
    public class Main extends Sprite
    {
        public function Main()
        {
            var aSpr:Sprite = new Sprite();
            var bSpr:Sprite = new Sprite();
            var cSpr:Sprite = new Sprite();
            var dSpr:Sprite = new Sprite();
    
            aSpr.addEventListener(MouseEvent.MOUSE_DOWN, swapSprites);
            bSpr.addEventListener(MouseEvent.MOUSE_DOWN, swapSprites);
            cSpr.addEventListener(MouseEvent.MOUSE_DOWN, swapSprites);
            dSpr.addEventListener(MouseEvent.MOUSE_DOWN, swapSprites);
    
            addChild(aSpr);
            addChild(bSpr);
            addChild(cSpr);
            addChild(dSpr);
        }
    
        private function swapSprites(evt:Event):void
        {
            swapChildren((evt.target as Sprite), getChildAt(numChildren - 1));
        }
    }
}

        



Leave a Comment / Note


 
Verification is used to prevent unwanted posts (spam). .


Flash / Flex / ActionScript examples

 Navioo Development
» Sprite