# hitTest in Flash Games

**URL:** <https://forum.kirupa.com/t/hittest-in-flash-games/172034>\
**Category:** flash\
**Created:** [December 10, 2005, 4:06am UTC](https://forum.kirupa.com/t/hittest-in-flash-games/172034 "2005-12-10T04:06:21Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![redblinker](https://avatars.discourse-cdn.com/v4/letter/r/5f9b8f/32.png) [@redblinker](https://forum.kirupa.com/u/redblinker)\
**Post date:** [December 10, 2005, 4:06am UTC](https://forum.kirupa.com/t/hittest-in-flash-games/172034/1 "2005-12-10T04:06:21Z")

</div>

Hi, I just wanted to know how people code buildings so that the character doesn’t bump into them. I tried to do it, but somehow it didn’t work. Attached is a sample FLA (Flash 8) explaining my problem. Just move the blue circle with the arrow keys and try to see what happens when you bump into the gray block.

The code I have for the circle is:

```auto

onClipEvent (load) {
moveSpeed = 3;
}
onClipEvent (enterFrame) {
if (Key.isDown(Key.UP)) {
this._y -= moveSpeed;
} else if (Key.isDown(Key.DOWN)) {
this._y += moveSpeed;
} else if (Key.isDown(Key.LEFT)) {
this._x -= moveSpeed;
} else if (Key.isDown(Key.RIGHT)) {
this._x += moveSpeed;
}
}

```

And the code I have for the gray block is:

```auto

onClipEvent (enterFrame) {
if (_root.ball.hitTest(this)) {
if (Key.isDown(Key.LEFT)) {
_root.ball._x += _root.ball.moveSpeed;
} else if (Key.isDown(Key.RIGHT)) {
_root.ball._x -= _root.ball.moveSpeed;
} else if (Key.isDown(Key.UP)) {
_root.ball._y += _root.ball.moveSpeed;
} else if (Key.isDown(Key.DOWN)) {
_root.ball._y -= _root.ball.moveSpeed;
}
}
}

```

Thanks in advance for any help. 🙂
