Below is simplified version of a game I am creating. Basically, the game have some circles. Each circle shoot bullets that is dispatched with timerEvent. When the circle is clicked it is removed from the stage. However, the bullet still keeps on dispatching. I couldn't figure out how to stop timerEvent of each individual circle when it is clicked.
var _timer:Timer = new Timer(1000);
var speed:int = 20;
for(var i:int=0; i<= 3; i++)
{
var _shape:MovieClip = new MovieClip();
_shape.graphics.beginFill(0x999999);
_shape.graphics.lineStyle(1, 0x000000);
_shape.graphics.drawCircle(0, 0, 20);
_shape.graphics.endFill();
addChild(_shape);
_shape.x = (stage.stageWidth)/5;
_shape.y = (stage.stageHeight)/3 + _shape.height*i*1.5;
_shape.name = "_shape"+i;
_shape.buttonMode = true;
_shape.addEventListener(MouseEvent.CLICK, removeMovieClip);
bullets(_shape);
}
function bullets(_shape:MovieClip):void
{
_timer = new Timer(Math.random()*100);
_timer.addEventListener(TimerEvent.TIMER, startFiring);
_timer.start();
function startFiring(e:TimerEvent):void
{
speed ++;
var _bullet:MovieClip = new MovieClip();
_bullet.graphics.beginFill(0x999999);
_bullet.graphics.lineStyle(1, 0x000000);
_bullet.graphics.drawRect(0, 0, 5,2);
_bullet.graphics.endFill();
addChild(_bullet);
_bullet.x = _shape.x + speed ;
_bullet.y = _shape.y;
}
}
function removeMovieClip(e:MouseEvent):void
{
removeChild(getChildByName(e.currentTarget.name));
// how to stop the timerEvent of clicked circle?
}
thanks in advance Rexon