# Hit test

**URL:** <https://forum.kirupa.com/t/hit-test/9043>\
**Category:** Uncategorized\
**Created:** [December 3, 2002, 5:50pm UTC](https://forum.kirupa.com/t/hit-test/9043 "2002-12-03T17:50:18Z")\
**Posts on this page:** 15\
**Page:** 1

<div class="post-metadata">

**Author:** ![eyeinfinitude](https://avatars.discourse-cdn.com/v4/letter/e/ed8c4c/32.png) [@eyeinfinitude](https://forum.kirupa.com/u/eyeinfinitude)\
**Post date:** [December 3, 2002, 5:50pm UTC](https://forum.kirupa.com/t/hit-test/9043/1 "2002-12-03T17:50:18Z")

</div>

What is wrong with this AS? I cant get the hittest to work on these buttons which are now movieclips.

```php
onClipEvent (enterFrame) {
 if (this.hitTest(_root._xmouse, _root._ymouse, true)) 
	if (_currentframe>=75) {
		gotoAndPlay(91);
 } else {
	if (_currentframe>=96) {
		gotoAndPlay(96);
		updateAfterEvent();
 }
}

```

---

<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:** [December 3, 2002, 6:06pm UTC](https://forum.kirupa.com/t/hit-test/9043/2 "2002-12-03T18:06:48Z")

</div>

[EDIT=Erased post] **…and he missed!** [/EDIT]

:\*(

---

<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:** [December 3, 2002, 6:45pm UTC](https://forum.kirupa.com/t/hit-test/9043/3 "2002-12-03T18:45:39Z")

</div>

Well for one you missed a curly bracket 🙂

Not sure if that is the whole problem, but I can tell that one right off the bat…

```auto
onClipEvent (enterFrame) {
	if (this.hitTest(_root._xmouse, _root._ymouse, true)) {
		if (_currentframe>=75) {
			gotoAndPlay(91);
		} else {
			if (_currentframe>=96) {
				gotoAndPlay(96);
				updateAfterEvent();
			}
		}
	}
}

```

---

<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:** [December 3, 2002, 6:52pm UTC](https://forum.kirupa.com/t/hit-test/9043/4 "2002-12-03T18:52:46Z")

</div>

create an invisible mc and attach it to the mouse using

onClipEvent (mouseMove) {  
\_x=\_root.\_xmouse  
\_y=\_root.\_ymouse  
updateAfterEvent(mouseMove)  
}

give this mc an instance name like “mouseTarget” then use hitTest -

if (this.hitTest(\_root.mouseTarget)) { }

---

<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:** [December 3, 2002, 6:56pm UTC](https://forum.kirupa.com/t/hit-test/9043/5 "2002-12-03T18:56:44Z")

</div>

I did this and worked perfect… so its not the hitTest that is the problem.

```auto
onClipEvent (enterFrame) {
	if (this.hitTest(_root._xmouse, _root._ymouse, true)) {
		trace("over");
	} else {
		trace("not over");
	}
}

```

---

<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:** [December 3, 2002, 6:57pm UTC](https://forum.kirupa.com/t/hit-test/9043/6 "2002-12-03T18:57:36Z")

</div>

You could try…

```auto
onClipEvent (enterFrame) {
	if (this.hitTest(_root._xmouse, _root._ymouse, true)) {
		if (_currentframe>=75 && _currentframe<=95) {
			gotoAndPlay(91);
		} else {
			if (_currentframe>=96) {
				gotoAndPlay(96);
				updateAfterEvent();
			}
		}
	}
}

```

---

<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:** [December 3, 2002, 9:16pm UTC](https://forum.kirupa.com/t/hit-test/9043/7 "2002-12-03T21:16:39Z")

</div>

Thanks for replying guys, but the problem continues. Basically what I have is a movie clip that alphas from 0 to 100 on rollover, that part is simple, but I also want it to control an alpha of a 2nd movie clip too. So when I rollover and rollout on that movieclip, it fades itself and another movieclip at the same time. I already achieved this with the rollover and rollout AS, but its not sensitive enough, if i roll my mouse over it too fast then it will be stuck on a state. I thought if I used the hittest, it would make it more sensitive to the mouse, but so far I havent been able to apply the hittest it. I hope you guys understand what I’m trying to do. :-\

---

<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:** [December 3, 2002, 10:27pm UTC](https://forum.kirupa.com/t/hit-test/9043/8 "2002-12-03T22:27:31Z")

</div>

Use AS to tween the alpha instead of a motion tween.

---

<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:** [December 3, 2002, 10:47pm UTC](https://forum.kirupa.com/t/hit-test/9043/9 "2002-12-03T22:47:59Z")

</div>

Thats the problem, I dont know how to do that, I wanna use the hittest to control the alphas of both movieclips, but so far no luck…

---

<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:** [December 3, 2002, 10:57pm UTC](https://forum.kirupa.com/t/hit-test/9043/10 "2002-12-03T22:57:12Z")

</div>

I will whip up an example…

::poof::

Wait… which version of Flash?

If it is MX, I can whip up an example, if it is Flash 5, hmmm, I can’t help ya there ☹

---

<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:** [December 3, 2002, 11:02pm UTC](https://forum.kirupa.com/t/hit-test/9043/11 "2002-12-03T23:02:07Z")

</div>

I’m using MX, thank goodness!! thanks Lost! I owe you big time on this cause its for a important project. =)

---

<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:** [December 3, 2002, 11:12pm UTC](https://forum.kirupa.com/t/hit-test/9043/12 "2002-12-03T23:12:53Z")

</div>

Ok, check my attachment 🙂

I set the original alpha of the rollOver clip to 10 so you can see where you were rolling over to test it, so the animation of it may seem a bit off, but the idea is there.

I hope it was close to what you wanted to do 🙂

---

<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:** [December 3, 2002, 11:17pm UTC](https://forum.kirupa.com/t/hit-test/9043/13 "2002-12-03T23:17:15Z")

</div>

Wait wait wait… I noticed a glitch in the last script where if you moused over it real fast over and over it made it invisible.

Try this one 🙂

---

<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:** [December 3, 2002, 11:41pm UTC](https://forum.kirupa.com/t/hit-test/9043/14 "2002-12-03T23:41:18Z")

</div>

crazy lost! thats exactly what i needed, thanks man!! =)

---

<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:** [December 3, 2002, 11:42pm UTC](https://forum.kirupa.com/t/hit-test/9043/15 "2002-12-03T23:42:53Z")

</div>

No problem, always glad to help 🙂

Especially on important projects :beam:
