title: AS3 2D Rectangular Collision Blocking
body: <p>I need to block two rectangles colliding with each other in Action Script. The code I have works only dimentionally(only a X on X collision or a Y on Y). When I test if it's colliding on the X axis and the Y, they interfere.</p>
  
  <p>function collisionTest(obj1, obj2)
  {</p>
  
  <pre><code>var b1 = getBound(obj1);
  var b2 = getBound(obj2);
  
  if(((b1.x &lt; b2.x + b2.width) &amp;&amp; (b1.x + b1.width &gt; b2.x)) &amp;&amp; ((b1.y + b1.height &gt; b2.y) &amp;&amp; (b1.y &lt; b2.y + b2.height)))
  {
      if(b1.x + b1.width &gt; b2.x + b2.width)
          obj1.x = b2.x + b2.width;
      else if(b1.x &lt; b2.x)
          obj1.x = b2.x - obj1.width;
      else if(b1.y &lt; b2.y)
          obj1.y = b2.y - obj1.height;
      else if(b1.y + b1.height &gt; b2.y + b2.height)
          obj1.y = b2.y + b2.height;
  }
  </code></pre>
  
  <p>}</p>
  
  <p>If there is any other way to test for a collision and block it, then please tell me, but I've searched on Google, and stackoverflow, and haven't found anything useful for blocking the collision, however I've found a lot about testing for them.</p>