title: Checking for a collision between multiple dynamic instances in AS3
body: <p>Okay, here's the rub. I'm making a little maze game. In this maze game, I have walls. They link to a class called Wall.as. In order to collision detect with the player, I do this:</p>
  
  <pre><code>MovieClip(parent).checkCollisonWithPlayer(this);
  </code></pre>
  
  <p>Where (parent) is a manager logic class. The parent does this</p>
  
  <pre><code>public function checkCollisonWithPlayer(wall:MovieClip)
      {
  
          if(player != null)
          {
              Collision.block(player,wall);
          }
      }
  </code></pre>
  
  <p>Now here's my problem. I have a class of Bullet.as that does much the same thing:</p>
  
  <pre><code>private function onEnterFrame(event:Event):void
      {
           x+= _vx;
           //Check for collisions with walls and enemies
           MovieClip(parent).checkCollisionWithEnemies(this);
           //Remove if it leads off the stage
          if (x &gt; stage.stageWidth)
          {
              parent.removeChild(this);
          }
      }
  </code></pre>
  
  <p>What if I wanted to check for a collision between one of these bullets() and one of these walls()? How can I do that? They're never in the same function at the same time and there's almost certainly more than one of each in play at any time. I'm new to AS and this feels like a common issue, but I couldn;t dig up any material that made sense. </p>
  
  <p>Here;s what I need:</p>
  
  <pre><code>public function checkCollisonWithWall(wall:MovieClip,bullet:MovieClip)
  {
  
      if(bullet.hitTestObject(wall))
          Collision.block(bullet,wall);
      }
  }
  </code></pre>
  
  <p>But of course that doesn't work. What are my options?</p>