title: collision detection on rectangle and ball
body: <p>i am build ballz game in action script3.
  i am facing a problem in corner of rectangle when hit ball it cannot determine ball next position left,or bottom. </p>
  
  <p>this is my code plz help me.
  this is the collision function that check direction of ball</p>
  
  <p>`if (isColliding)
              {
                  var brick:Rectangle = hitBrick.getBounds(this);</p>
  
  <pre><code>            var bl:int = ba.x - (ball.width / 2);
              var br:int = ba.x + (ball.width / 2);
              var bt:int = ba.y - (ball.height / 2);
              var bb:int = ba.y + (ball.height / 2);
  
              var hl:int = pt.x - (hitBrick.width / 2);
              var hr:int = pt.x + (hitBrick.width / 2);
              var ht:int = pt.y - (hitBrick.height / 2);
              var hb:int = pt.y + (hitBrick.height / 2);
  
              if (hb &lt;= bt)
              {
  
                  ConsoleUtil.consoleIt("TableScreen.as :: chkColision - " + "Bottom.");
                  _totalScore++;
                  ball._orignalYSpeed = -ball.yspeed;
                  ball.yspeed = -ball.yspeed + 5;
                  ball._stopBall = true;
                  ball._bottomOne = true;
                  ball.updateCounterInBricks(hitBrick);
  
                  return;
              }
  
              if ((hl &gt;= bl))
              {
                  ConsoleUtil.consoleIt("TableScreen.as :: chkColision - Left");
                  _hitOnWall = true;
                  ball._orignalXSpeed = -ball.xspeed;
                  var xSp:Number = ball.xspeed = -ball.xspeed - 5;
                  ball._left = true;
                  ball.updateCounterInBricks(hitBrick);
                  _totalScore++;
                  return;
              }
  
              if(hb&lt;=bb)
              {
                  ConsoleUtil.consoleIt("TableScreen.as :: chkColision - " + "Bottom.");
                  _totalScore++;
                  ball._orignalYSpeed = -ball.yspeed;
                  ball.yspeed = -ball.yspeed + 5;
                  ball._stopBall = true;
                  ball._bottomOne = true;
                  ball.updateCounterInBricks(hitBrick);
                  return;
              }
              if ((hr &lt;= br))
              {
                  ConsoleUtil.consoleIt("TableScreen.as :: chkColision - Rigth");
                  _hitOnWall = true;
                  ball._orignalXSpeed = -ball.xspeed;
                  var xSp:Number = ball.xspeed = -ball.xspeed + 5;
                  ball._left = true;
                  ball._stopBall = true;
                  ball.updateCounterInBricks(hitBrick);
                  _totalScore++;
                  return;
              }
              if (ht &gt;= bt)
              {
                  ConsoleUtil.consoleIt("TableScreen.as :: chkColision - " + "Top");
                  _totalScore++;
                  ball._orignalYSpeed = -ball.yspeed;
                  ball.yspeed = -ball.yspeed - 5;
  
                  ball._topOne = true;
                  ball._stopBall = true;
                  ball.updateCounterInBricks(hitBrick);
                  return;
              }
  
          }`
  </code></pre>