# Looking for a new hitTest

**URL:** <https://forum.kirupa.com/t/looking-for-a-new-hittest/62232>\
**Category:** Uncategorized\
**Created:** [August 26, 2004, 2:31am UTC](https://forum.kirupa.com/t/looking-for-a-new-hittest/62232 "2004-08-26T02:31:40Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![JoMan](https://avatars.discourse-cdn.com/v4/letter/j/2bfe46/32.png) [@JoMan](https://forum.kirupa.com/u/JoMan)\
**Post date:** [August 26, 2004, 2:31am UTC](https://forum.kirupa.com/t/looking-for-a-new-hittest/62232/1 "2004-08-26T02:31:40Z")

</div>

I have been using the "single line hitTest " method for a LONG while:td:, and I was wondering if anyone could teach me a better hitTest method. But please teach it to me in onClipHandlers (I dont like functions 😉 ). Thanks in advance.

peace

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [August 26, 2004, 9:41pm UTC](https://forum.kirupa.com/t/looking-for-a-new-hittest/62232/2 "2004-08-26T21:41:31Z")

</div>

Well, I made one just now, but it is REALLY messed and I dont know why…

```auto

onClipEvent (enterFrame) {
	if (_root.b.hitTest(_x+x+b.xmin+5, _y+y+b.ymin+5, true)) {
		_x -= 5;
	}
	if (_root.b.hitTest(_x+x+b.xmax-5, _y+y+b.ymin+5, true)) {
		_x += 5;
	}
	if (_root.b.hitTest(_x+x+b.xmin+5, _y+y+b.ymax-5, true)) {
		_y -= 6;
	}
	if (_root.b.hitTest(_x+x+b.xmax-5, _y+y+b.ymax-5, true)) {
		_y += 6;
	}
}

```

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [August 26, 2004, 9:44pm UTC](https://forum.kirupa.com/t/looking-for-a-new-hittest/62232/3 "2004-08-26T21:44:18Z")

</div>

Okay, I made one of my own, but it is REALLY messed and I dont know why… Anyone know?

```auto
 
onClipEvent (enterFrame) { 
b = this.getBounds(this);
if (_root.limits.hitTest(_x+x+b.xmin+5, _y+y+b.ymin+5, true)) {
_x += 6;
}
if (_root.limits.hitTest(_x+x+b.xmax-5, _y+y+b.ymin+5, true)) {
_x -= 6;
} 
if (_root.limits.hitTest(_x+x+b.xmin+5, _y+y+b.ymax-5, true)) {
_y -= 6;
}
if (_root.limits.hitTest(_x+x+b.xmax-5, _y+y+b.ymax-5, true)) {
_y += 6;
}
}
 

```

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [August 27, 2004, 8:26am UTC](https://forum.kirupa.com/t/looking-for-a-new-hittest/62232/4 "2004-08-27T08:26:44Z")

</div>

You’re forgetting the first curly brackets after the conditions.

🙂

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [August 27, 2004, 4:34pm UTC](https://forum.kirupa.com/t/looking-for-a-new-hittest/62232/5 "2004-08-27T16:34:20Z")

</div>

I have those, but I think you have to scroll the coding box to see the curly brackets

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [August 27, 2004, 5:51pm UTC](https://forum.kirupa.com/t/looking-for-a-new-hittest/62232/6 "2004-08-27T17:51:55Z")

</div>

You cant scroll it left or right… double check to see if you put them

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [August 27, 2004, 5:54pm UTC](https://forum.kirupa.com/t/looking-for-a-new-hittest/62232/7 "2004-08-27T17:54:42Z")

</div>

Here, I put it on regular:

onClipEvent (enterFrame) {  
b = this.getBounds(this);  
if (\_root.limits.hitTest(\_x+x+b.xmin+5, \_y+y+b.ymin+5, true)) {  
\_x += 6;  
}  
if (\_root.limits.hitTest(\_x+x+b.xmax-5, \_y+y+b.ymin+5, true)) {  
\_x -= 6;  
}  
if (\_root.limits.hitTest(\_x+x+b.xmin+5, \_y+y+b.ymax-5, true)) {  
\_y -= 6;  
}  
if (\_root.limits.hitTest(\_x+x+b.xmax-5, \_y+y+b.ymax-5, true)) {  
\_y += 6;  
}  
}
