2013-01-21 3 views
1

나는 이걸 어떻게 처리해야할지 모르겠다. 지금은 시간이 통해 찾아 봤는데 내가 오류 읽기가 계속 :타이머가있는 AS3 - TypeError # 1009

TypeError: Error #1009: Cannot access a property or method of a null object reference. 
    at Shooter_Enemy/shotHandler() 
    at flash.utils::Timer/_timerDispatch() 
    at flash.utils::Timer/tick() 

내가 그것을 "seekingBullet는"무대에 추가되는 코드의 라인을 가리키는 디버깅 할 때. 이 문제를 해결하는 데 큰 도움이 될 것입니다. 그것은 실제의 경우

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

    public class Shooter_Enemy extends MovieClip 
    { 
     private var yMove:int = 2; 
     private var shootTimer:Timer = new Timer(500); 

     public function Shooter_Enemy() 
     { 
      this.name = "mc_shooter_enemy"; 
      this.addEventListener(Event.ENTER_FRAME,enemyMove); 

      shootTimer.start(); 
      shootTimer.addEventListener(TimerEvent.TIMER,shotHandler); 
     } 

     public function addShooterEnemy(X:int):void 
     { 
      this.x = X; 
      this.y = 0; 
     } 
     public function removeEnemy() 
     { 
      shootTimer.removeEventListener(TimerEvent.TIMER,shotHandler); 
      shootTimer.stop(); 

      this.removeEventListener(Event.ENTER_FRAME,enemyMove); 
      this.x = 0; 
      this.y = (stage.height + this.height); 
     } 
     private function shotHandler(te:TimerEvent):void 
     { 
      var seekingBullet:SeekingBullet = new SeekingBullet(); 
      Main.seekingBulletArray.push(seekingBullet); 
      stage.addChild(seekingBullet); 
      seekingBullet.addSeekingBullet(this.x,this.y); 
     } 
     private function enemyMove(e:Event) 
     { 
      this.y += yMove; 
     } 
    } 
}  
+1

무엇입니까? 초기화되고 SeekingBulletArray가 어디에서 생성 되었습니까? –

+0

'stage.addChild' 전에'trace (stage);'가 발생할 때 – Daniel

+0

실제로 Shooter_Enemy가 스테이지에 추가 된 후 타이머를 시작하십시오. 즉, Shooter_Enemy 생성자에서 Event.ADDED_TO_STAGE에 대한 이벤트 리스너를 추가하십시오. – Luis

답변

0

, 단계를 사용하기위한 좋은 방법은 *이 Event.ADDED_TO_STAGE * 듣고 다음과 같은 활동을 시작 : 홈페이지에 대한

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

    public class Shooter_Enemy extends MovieClip 
    { 
     private var yMove:int = 2; 
     private var shootTimer:Timer = new Timer(500); 

     public function Shooter_Enemy() 
     { 
      this.name = "mc_shooter_enemy"; 
      this.addEventListener(Event.ENTER_FRAME,enemyMove); 

      shootTimer.addEventListener(TimerEvent.TIMER, shotHandler); 
      addEventListener(Event.ADDED_TO_STAGE, addedToStageHandler); 
     } 

     public function addShooterEnemy(X:int):void 
     { 
      this.x = X; 
      this.y = 0; 
     } 
     public function removeEnemy() 
     { 
      shootTimer.removeEventListener(TimerEvent.TIMER,shotHandler); 
      shootTimer.stop(); 

      this.removeEventListener(Event.ENTER_FRAME,enemyMove); 
      this.x = 0; 
      this.y = (stage.height + this.height); 
     } 
     private function addedToStageHandler(e:Event) 
     { 
      shootTimer.start(); 
     } 
     private function shotHandler(te:TimerEvent):void 
     { 
      var seekingBullet:SeekingBullet = new SeekingBullet(); 
      Main.seekingBulletArray.push(seekingBullet); 
      stage.addChild(seekingBullet); 
      seekingBullet.addSeekingBullet(this.x,this.y); 
     } 
     private function enemyMove(e:Event) 
     { 
      this.y += yMove; 
     } 
    } 
} 
관련 문제