title: Remove timer event listener
body: <p>so I need to remove a timer event. But the problem is, It's in another function so I can't access it.</p>
  
  <p>Here's how my code goes:</p>
  
  <p>-There is a Boss</p>
  
  <p>-It generates bomb</p>
  
  <p>-Bomb lasts for a couple of seconds before exploding (no error)</p>
  
  <p>-Bomb can be removed by clicking. (generates error)</p>
  
  <p>If the bomb was removed via clicking, there will be error because the time event wasn't remove. But like I said, I can't remove it because it's in another function. Help!</p>
  
  <pre><code>import flash.events.Event;
  import flash.display.MovieClip;
  
  var boss:MovieClip = new darklord();
  this.addChild(boss);
  boss.x = stage.stageWidth / 2;
  boss.y = stage.stageHeight / 2;
  
  var lives:int = 3;
  var maxHP:int = 2000;
  var currentHP:int = maxHP;
  var percentHP:Number = currentHP / maxHP;
  
  var bombcontainer:Array = [];
  var timecontainer:Array = [];
  
  function updateHealthBar():void
  {
      percentHP = currentHP / maxHP;
      healthBar.barColor.scaleX = percentHP;
  }
  
  boss.addEventListener(MouseEvent.CLICK, TapBoss);
  boss.addEventListener(Event.ENTER_FRAME, MoveBoss);
  
  function TapBoss(e:MouseEvent):void
  {
      currentHP -=  10;
      if (currentHP &lt;= 0)
      {
          currentHP = 0;
          trace("You win!");
      }
      updateHealthBar();
  }
  
  var timerBoss:Timer = new Timer(1000,60);
  timerBoss.addEventListener(TimerEvent.TIMER, bosstimerhandler);
  timerBoss.start();
  
  var secondsBoss:Number = 0;
  
  function bosstimerhandler(event:TimerEvent)
  {
  //trace("Seconds elapsed: " + seconds);
  //SpawnNote(null);
      if (secondsBoss%5==0)
      {
          RandomCoord(null);
          BossAttack(null);
      }
      secondsBoss++;
  }
  
  var HighH:int = stage.stageHeight;
  var HighW:int = stage.stageWidth;
  var LowH:int = 0;
  var LowW:int = 0;
  
  var destinationX:int;
  var destinationY:int;
  
  function RandomCoord(event:Event):void
  {
      destinationX=Math.floor(Math.random()*(1+HighW-LowW))+LowW;
      destinationY=Math.floor(Math.random()*(1+HighH-LowH))+LowH;
  
      if (destinationX &lt;= 50)
      {
          destinationX +=  50;
      }
  
      if (destinationY &lt;= 50)
  {
      destinationY +=  50;
  }
  
  if (destinationX + 50 &gt;= stage.stageWidth)
  {
      destinationX -=  50;
  }
  
  if (destinationY + 50 &gt;= stage.stageHeight)
  {
      destinationY -=  50;
  }
  
      trace("X is: ", destinationX);
      trace("Y is: ", destinationY);
  }
  
  function MoveBoss(event:Event):void
  {
      if (boss.x &lt; destinationX)
  {
      boss.x +=  1;
  }
  else if (boss.x &gt; destinationX)
  {
      boss.x -=  1;
  }
  
  if (boss.y &lt; destinationY)
  {
      boss.y +=  1;
  }
  else if (boss.y &gt; destinationY)
  {
      boss.y -=  1;
  }
  }
  
  function BossAttack(event:Event):void
  {
      var boom:MovieClip = new Bomb();
      this.addChild(boom);
      bombcontainer.push(boom);
      boom.x = boss.x;
      boom.y = boss.y;
      BombCoord(null);
      boom.addEventListener(Event.ENTER_FRAME, MoveBomb);
      boom.addEventListener(MouseEvent.CLICK, TapBomb(boom));
      BombTimer(boom);
  }
  
  function BombTimer(boom:MovieClip):void
  {       
  var time:Timer = new Timer(1000,30);    
  timecontainer.push(time);
  time.addEventListener(TimerEvent.TIMER, TimeHandler);
  time.start();
  
  var t:Number = 1;
  
  function TimeHandler(event:TimerEvent):void
  {
  
      trace("Seconds elapsed: " + t);
      t++;
      if (t==12)
      {
          lives--;
          trace("You lost a life!");
          time.removeEventListener(TimerEvent.TIMER, TimeHandler);
          RemoveBomb(boom, 0);
      }
      }
  }
  
  function RemoveBomb(boom:DisplayObject, bid:int):void
  {
  boom.removeEventListener(Event.ENTER_FRAME, MoveBomb);  
  //boom.removeEventListener(MouseEvent.CLICK, TapBomb(boom)); 
  bombcontainer.splice(bid, 1);
  trace("Bomb # :" +bid+" is popped.");
  this.removeChild(boom);
  }
  
  var BombX:int;
  var BombY:int;
  
  function BombCoord(event:Event):void
  {
  BombX=Math.floor(Math.random()*(1+HighW-LowW))+LowW;
  BombY=Math.floor(Math.random()*(1+HighH-LowH))+LowH;
  
  if (BombX &lt;= 50)
  {
      BombX +=  50;
  }
  
  if (BombY &lt;= 50)
  {
      BombY +=  50;
  }
  
  if (BombX + 50 &gt;= stage.stageWidth)
  {
      BombX -=  50;
  }
  
  if (BombY + 50 &gt;= stage.stageHeight)
  {
      BombY -=  50;
  }
  }
  
  function MoveBomb(event:Event):void
  {
  var boom:DisplayObject = event.target as DisplayObject;
  
  var fl_TimerInstance:Timer = new Timer(1000,6);
  fl_TimerInstance.addEventListener(TimerEvent.TIMER, fl_TimerHandler);
  fl_TimerInstance.start();
  
  var fl_SecondsElapsed:Number = 1;
  
  function fl_TimerHandler(event:TimerEvent):void
  {
      //trace("Seconds elapsed: " + fl_SecondsElapsed);
      fl_SecondsElapsed++;
      if (fl_SecondsElapsed==4)
      {
          boom.removeEventListener(Event.ENTER_FRAME, MoveBomb);
      }
  }
  
  if (boom.x &lt; BombX)
  {
      boom.x +=  5;
      //boom.x +=5;
  }
  else if (boom.x &gt; BombX)
  {
      boom.x -=  5;
  }//boom.x -=5;
  
  if (boom.y &lt; BombY)
  {
      boom.y +=  5;
      //boom.x +=5;
  }
  else if (boom.y &gt; BombY)
  {
      boom.y -=  5;
  }
  
  if (boom.x == BombX)
  {
      if (boom.y == BombY)
      {
          boom.removeEventListener(Event.ENTER_FRAME, MoveBomb);
      }
  }
  
  if (boom.y == BombY)
  {
      if (boom.x == BombX)
      {
          boom.removeEventListener(Event.ENTER_FRAME, MoveBomb);
      }
  }
  }
  
  function TapBomb(boom:MovieClip):Function
  {
  return function(e:MouseEvent):void {    
  var BombIndex:int = bombcontainer.indexOf(boom);
  trace("You clicked the bomb at index " + BombIndex);    
  RemoveBomb(boom, BombIndex);    
  }
  }         
  </code></pre>