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(0x00ff00, 1);
squareOne.graphics.drawRect(0, 0, 200, 200);
squareOne.graphics.endFill();
squareTwo.graphics.beginFill(0x00ff00, 1);
squareTwo.graphics.drawRect(0, 0, 200, 200);
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);
}
}
}
Related examples in the same category