Reparenting Display Objects : Sprite : Development Flash / Flex / ActionScript examples


Flash / Flex / ActionScript examples » Development » Sprite »

 

Reparenting Display Objects


 
package {
    import flash.display.*;
    import flash.events.*;

    public class Main extends Sprite
    {
        var squareOne:Sprite = new Sprite();
        var squareTwo:Sprite = new Sprite();

        var shapeInst:Shape = new Shape();

        public function Main()
        {
            squareOne.graphics.beginFill(0x00ff001);
            squareOne.graphics.drawRect(00200200);
            squareOne.graphics.endFill();
    
            squareTwo.graphics.beginFill(0x00ff001);
            squareTwo.graphics.drawRect(00200200);
            squareTwo.graphics.endFill();
    
            addChild(squareOne);
            addChild(squareTwo);
    
            squareTwo.x = 300;
    
            squareOne.addEventListener(MouseEvent.MOUSE_DOWN, addShape);
            squareTwo.addEventListener(MouseEvent.MOUSE_DOWN, addShape);
        }

        private function addShape(event:Event):void
        {
            event.target.addChild(shapeInst);
        }
    }
}

        



Leave a Comment / Note


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


Flash / Flex / ActionScript examples

 Navioo Development
» Sprite