# hitTest

**URL:** https://forum.kirupa.com/t/hittest/220549
**Category:** Uncategorized
**Created:** [March 27, 2007, 9:17am UTC](https://forum.kirupa.com/t/hittest/220549 "2007-03-27T09:17:56Z")
**Posts on this page:** 1
**Page:** 1

<div class="post-metadata">

### Author: ![exit](https://avatars.discourse-cdn.com/v4/letter/e/e19adc/32.png) [@exit](https://forum.kirupa.com/u/exit)
#### Post date: [March 27, 2007, 9:17am UTC](https://forum.kirupa.com/t/hittest/220549/1 "2007-03-27T09:17:56Z")

</div>

Hi / I am working on a maze (shown on the picture) and I want a hitTest function, which stops the red dot, when it hits the walls of the maze.  
I did try a simpel: if(mcDot.hitTest(mcMaze)){//code} - but this work for the entire mc and not only the walls.

Hope someone here has some advice on how to go about this…

![](http://www.exitkids.com/maze.jpg)

My script looks like this so far:  
var distance:Number = 3;  
var keyListener:Object = new Object();  
keyListener.onKeyDown = function() {  
if (Key.isDown(Key.LEFT)) {  
mcDot.\_x = Math.max(mcDot.\_x-distance, 0);  
} else if (Key.isDown(Key.RIGHT)) {  
mcDot.\_x = Math.min(mcDot.\_x+distance, Stage.width-mcDot.\_width/2);  
} else if (Key.isDown(Key.UP)) {  
mcDot.\_y = Math.max(mcDot.\_y-distance, 0);  
} else if (Key.isDown(Key.DOWN)) {  
mcDot.\_y = Math.min(mcDot.\_y+distance, Stage.height-mcDot.\_height/2);  
}  
};  
Key.addListener(keyListener);
