I am creating multiple instances of a movie class with the same variable name. The movie is then added random on the stage with a tween. On a mouse handler click, i want to remove the movie from the stage.
I am getting error -
ArgumentError: Error #2025: The supplied DisplayObject must be a child of the caller.
at flash.display::DisplayObjectContainer/removeChild()
at Untitled_fla::MainTimeline/removeBlock()
What am I doing wrong?
import gs.TweenLite;
import flash.utils.*;
var block:block_mc;
var myTimer:Timer = new Timer(1000, 15);
myTimer.start();
myTimer.addEventListener(TimerEvent.TIMER, run);
function run(event:TimerEvent):void {
trace("run");
trace(myTimer.currentCount);
block = new block_mc;
block.x = Math.round(Math.random() * 400);
block.y = Math.round(Math.random() * 400);
block.alpha = 0;
block.mouseChildren = false;
stage.addChild(block);
TweenLite.to(block, 1, {alpha:1});
stage.addEventListener(MouseEvent.CLICK, removeBlock);
}
function removeBlock(event:MouseEvent):void{
removeChild(event.target);
}