title: AS3 Getting an Error #1009 on a Timer variable
body: <p>I'm having Error #1009: Cannot access a property or method of a null object reference.  I'm not exactly sure how to solve this problem myself, I've traced to see if the object var enemySpawnTimer:Timer is actually null and it isn't.  So I don't understand why I'm getting this error.</p>
  
  <p>Anyway here is my code, it's a class I use to spawn blocks that fall from the top of the screen to the bottom and is removed from the stage once it reaches the bottom of the screen.</p>
  
  <pre><code>package scripts
  {
      import flash.events.Event;
      import flash.display.Stage;
      import flash.events.Event;
      import flash.events.TimerEvent;
      import flash.utils.Timer;
      import flash.display.DisplayObject;
  
      public class EnemySpawner
      {
          var stageRef:Stage;
          var target:Player;
  
          //vector variables
          public static var vectorBlock:Vector.&lt;Block&gt; = new Vector.&lt;Block&gt;();
  
          //enemy variables
          public static var block:Block;
  
          //timer variables
          var enemySpawnTimer:Timer = new Timer(250);
  
          //score variables
          public static var pointsBlock:Number = 0;
  
          public function EnemySpawner(stageRef:Stage, target:Player)
          {
              this.stageRef = stageRef;
              this.target = target;
  
              enemySpawnTimer.addEventListener(TimerEvent.TIMER, SpawnBlocks, false, 0, true);
              enemySpawnTimer.start();
          }
  
          private function SpawnBlocks(e:TimerEvent):void
          {
              block = new Block(stageRef);
              pointsBlock = block.pointsGiven;
  
              vectorBlock.push(block);
              stageRef.addChild(block);
  
              block.addEventListener(Event.ENTER_FRAME, Update, false, 0, true);
          }
  
          private function Update(e:Event):void
          {
              //remove enemies when they pass the bottom of the stage
              for each(var block:Block in vectorBlock)
              {
                  if(block.y &gt; Bounds.rectH + block.height)
                  {
                      RemoveFromList(block);
                  }
              }
  
              target.addEventListener("playerDeath", StopSpawning, false, 0, true);
          }
  
          private function RemoveFromList(block:Block):void
          {
              vectorBlock.splice(vectorBlock.indexOf(block), 1);
  
              if(stageRef.contains(block))
              {
                  stageRef.removeChild(block);
              }
          }
  
          private function StopSpawning(e:Event):void
          {
              enemySpawnTimer.stop();
          }
      }
  }
  </code></pre>
  
  <p>This is the error I get, unfortunately using the script editor in flash is not too helpful with where or what is causing the error exactly.</p>
  
  <pre><code>TypeError: Error #1009: Cannot access a property or method of a null object reference.
  at scripts::EnemySpawner/SpawnBlocks()
  at flash.utils::Timer/_timerDispatch()
  at flash.utils::Timer/tick()
  </code></pre>