title: AS3: Class can't find another class to interact with
body: <p>So I have this code inside of one of my enemy class for my flash game.</p>
  
  <pre><code>package  
  {   
      import flash.events.*;
      import flash.display.*;
      import flash.geom.*;
  
      public class JumpBall extends MovieClip 
      {
          var MTL:MovieClip = MovieClip(root);
          var charMTL:MovieClip;
          var bullet:Bullet = new Bullet;
  
          public function JumpBall() 
          {
              this.addEventListener(Event.ENTER_FRAME, EnemyBallUpdate);
  
          }
  
          function EnemyBallUpdate(event:Event):void 
          {
              charMTL = MTL.char1;
  
              var enemy:Rectangle = this.getBounds(this);
              var enemy_matrix:Matrix = this.transform.matrix;
              var enemyBitmap:BitmapData = new BitmapData(enemy.width, enemy.height, true, 0);
                  enemyBitmap.draw(this,enemy_matrix);
  
              enemy_matrix.tx = this.x - enemy.x;
              enemy_matrix.ty = this.y - enemy.y;
  
              var char:Rectangle = charMTL.getBounds(this);
              var char_matrix:Matrix = charMTL.transform.matrix;
              var charBitmap:BitmapData = new BitmapData(char.width, char.height, true, 0);
                  charBitmap.draw(charMTL,char_matrix);
  
              char_matrix.tx = charMTL.x - char.x;
              char_matrix.ty = charMTL.y - char.y;
  
              var enemyPoint:Point = new Point(enemy.x, enemy.y);
              var charPoint:Point = new Point(char.x, char.y);
  
              if(enemyBitmap.hitTest(enemyPoint, 0, charBitmap, charPoint, 0) &amp;&amp; MTL.currentFrame == 2)
              {
  
                  if(MTL.HP == 0)
                  {
                      MTL.RemoveListeners();
                      MTL.vcam_2.x = 400.2;
                      MTL.vcam_2.y = 224.9;
                      MTL.gotoAndStop(3);
                      MTL.HP = 3;
                      MTL.CC = 0;
                      MTL.removeChild(charMTL);
                  }else{              
                      MTL.removeKeyboardEvts();
                      MTL.KeysOFF();
                      MTL.fade_mc.gotoAndPlay(2);
                      charMTL.gotoAndStop(1);
                      MTL.ySpeed = 0;
                      MTL.removeChild(charMTL);
                  }
              }
              enemyBitmap.dispose();
              charBitmap.dispose();
  
          }
  
          public function removeJumpBallEL(event:Event):void
          {
                  this.removeEventListener(Event.ENTER_FRAME, EnemyBallUpdate);
          }
  
      }
  
  }
  </code></pre>
  
  <p>Upon entering frame 2 I get the silly error:</p>
  
  <pre><code>TypeError: Error #1009: Cannot access a property or method of a null object reference.
      at JumpBall/EnemyBallUpdate()
  </code></pre>
  
  <p>I can't find out why the class can't talk to the char1 MovieClip (character of my game).
  I have the same type of class for a reset box with the exception that this class uses <code>.hitTestPoint</code> method. No errors there.
  I'm trying to add my enemies to an array for interaction with a bullet class.</p>
  
  <p>Here's the main timeline code:</p>
  
  <pre><code>function addJumpBall():void
      {
      var jumpball:JumpBall = new JumpBall;
      jumpball.x = 673;
      jumpball.y = 318;
      addChild(jumpball);
  
      jumpball.addEventListener(Event.REMOVED, jumpballRemoved);
      JumpBallArray.push(jumpball);
      }
  
  function jumpballRemoved(event:Event):void
      {
     event.currentTarget.removeEventListener(Event.REMOVED, jumpballRemoved); 
      JumpBallArray.splice(JumpBallArray.indexOf(event.currentTarget), 1);
      }   
  
  addJumpBall();
  </code></pre>
  
  <p>Thanks to anybody willing to help me!</p>