# Mouse hitTest?

**URL:** <https://forum.kirupa.com/t/mouse-hittest/34457>\
**Category:** flash\
**Created:** [November 2, 2003, 7:18pm UTC](https://forum.kirupa.com/t/mouse-hittest/34457 "2003-11-02T19:18:00Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![Fargate](https://avatars.discourse-cdn.com/v4/letter/f/dbc845/32.png) [@Fargate](https://forum.kirupa.com/u/Fargate)\
**Post date:** [November 2, 2003, 7:18pm UTC](https://forum.kirupa.com/t/mouse-hittest/34457/1 "2003-11-02T19:18:00Z")

</div>

How would I make a hittest so that flash would detect when the mouse enters contact with the target and the target plays? I’ve attached the file I’ve been trying to do the mouse hittest with. Any help would be greatly appreciated.

---

<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:** [November 2, 2003, 8:50pm UTC](https://forum.kirupa.com/t/mouse-hittest/34457/2 "2003-11-02T20:50:44Z")

</div>

Well, your cross hair is following the mouse, so one way you can do this is to check if the mouse is over using hitTest. On your target clip add these actions… [AS]onClipEvent(enterFrame){  
if (this.hitTest(\_root.\_xmouse, \_root.\_ymouse, true)){  
//do what you want when the mouse is over  
}  
}[/AS]

---

<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:** [November 3, 2003, 1:09am UTC](https://forum.kirupa.com/t/mouse-hittest/34457/3 "2003-11-03T01:09:27Z")

</div>

I tried what you told me, but it still doesnt seem to be working out.

It put the below script in my target movie clip

[AS]onClipEvent (enterFrame) {  
if (this.hitTest(\_root.\_xmouse, \_root.\_ymouse, true)) {  
this.play;  
}  
}  
[/AS]

and I put this script in the first fram where everything is located…this seems to be working fine…

[AS]startDrag ("/crosshair", true);  
Mouse.hide();  
[/AS]

And for some reason it doesn’t work…no errors just doesn’t work…I’ve attached the current fla. Also how would I make it work only when I press the mouse button so that it just doesn’t hit test when I mouse over??Help!!!

---

<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:** [November 3, 2003, 2:08am UTC](https://forum.kirupa.com/t/mouse-hittest/34457/4 "2003-11-03T02:08:29Z")

</div>

So close yet so far 😛

this.play should be this.play() (the parenthesis make all the difference)

The little things can drive one nuts :hr:

---

<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:** [November 3, 2003, 10:14pm UTC](https://forum.kirupa.com/t/mouse-hittest/34457/5 "2003-11-03T22:14:02Z")

</div>

aha! Thank you!:beam:Now it works…but it works as soon as I mouse over, how can I do it so it only works when I click on the target with the crosshair???

---

<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:** [November 3, 2003, 11:01pm UTC](https://forum.kirupa.com/t/mouse-hittest/34457/6 "2003-11-03T23:01:58Z")

</div>

Bah… I thought you were trying to do it onRollOver… sorry. That method is a lot easier… Replace the current actions on the clip with [AS]onClipEvent (load) {  
//don’t use the hand cursor when you are over the clip  
this.useHandCursor = false;  
}  
on (press) {  
//when you press, play the clip  
this.play();  
}[/AS]

---

<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:** [November 4, 2003, 8:58pm UTC](https://forum.kirupa.com/t/mouse-hittest/34457/7 "2003-11-04T20:58:18Z")

</div>

YES!!! Thank you so much :beam:!! It works!!!

---

<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:** [November 4, 2003, 9:15pm UTC](https://forum.kirupa.com/t/mouse-hittest/34457/8 "2003-11-04T21:15:45Z")

</div>

No problem
