# hitTest

**URL:** <https://forum.kirupa.com/t/hittest/25530>\
**Category:** Uncategorized\
**Created:** [July 14, 2003, 1:52am UTC](https://forum.kirupa.com/t/hittest/25530 "2003-07-14T01:52:24Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![Illuminae](https://avatars.discourse-cdn.com/v4/letter/i/b5ac83/32.png) [@Illuminae](https://forum.kirupa.com/u/Illuminae)\
**Post date:** [July 14, 2003, 1:52am UTC](https://forum.kirupa.com/t/hittest/25530/1 "2003-07-14T01:52:24Z")

</div>

Hey people,  
I am trying to get a MC to play when it collides with another MC named “light”. Here is my code. It is on the MC that I want to play (called “rap”)  
[AS]  
onClipEvent (enterFrame) {  
if (this.hitTest(\_root.light)) {  
this.gotoAndPlay(2);  
} else {  
this.gotoAndStop(1);  
}  
}  
[/AS]

the two MCs are called “rap” which is on the fuzzButt layer, and “light” which is just below it in the light layer.  
Any help is appreciated. thanks!

[CLICK HERE FOR THE ZIP FILE](http://www.redgolgi.com/temp/site.zip)

---

<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:** [July 14, 2003, 2:13am UTC](https://forum.kirupa.com/t/hittest/25530/2 "2003-07-14T02:13:10Z")

</div>

just downloaded it, im gonna try to see what i can do…

did you try using the coordinates of your movie clip instead?

like:

```auto
onClipEvent (enterFrame) {
        if (this.hitTest(this._x, this._y, true) {
                this.gotoAndPlay(2);
        } else {
                this.gotoAndStop(1);
        }
}

```

---

<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:** [July 14, 2003, 2:20am UTC](https://forum.kirupa.com/t/hittest/25530/3 "2003-07-14T02:20:34Z")

</div>

yeah, i tried doing that first (only reading the coordinates on light, cuz thats the one that’s moving), but i couldn’t get it right, because, well, i dunno, it’s a bad day in flash for me i guess. lol! actually, i tried doign something like  
[AS]  
onClipEvent(enterFrame) {  
if (\_root.light.\_X\>60 && \_root.light.\_X\<65)  
{  
this.gotoAndPlay(2);  
} else {  
this.gotoAndStop(1);  
}  
[/AS]  
but… no workie. thanks for takin a look liam :beam:

---

<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:** [July 14, 2003, 2:24am UTC](https://forum.kirupa.com/t/hittest/25530/4 "2003-07-14T02:24:11Z")

</div>

haha yeah oops i messed up my code!

ill have it workin for u shortly. 🙂

---

<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:** [July 14, 2003, 2:25am UTC](https://forum.kirupa.com/t/hittest/25530/5 "2003-07-14T02:25:31Z")

</div>

you’re the best :flower:

---

<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:** [July 14, 2003, 3:00am UTC](https://forum.kirupa.com/t/hittest/25530/6 "2003-07-14T03:00:15Z")

</div>

```auto
onClipEvent (enterFrame) {
	if (_parent.light.hitTest(this._x, this._y, true) && !hit) {
		this.gotoAndPlay(2);
	} else if (!_parent.light.hitTest(this._x, this._y, true) && hit) {
		this.gotoAndStop(1);
	}
	hit = _parent.light.hitTest(this._x, this._y, true);
}

```

😉

---

<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:** [July 14, 2003, 3:03am UTC](https://forum.kirupa.com/t/hittest/25530/7 "2003-07-14T03:03:59Z")

</div>

thank you thank you thank you!!!  
you’re the best too! 😉

---

<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:** [July 14, 2003, 3:06am UTC](https://forum.kirupa.com/t/hittest/25530/8 "2003-07-14T03:06:49Z")

</div>

… I know that. 😛 [size=1]just kidding!![/size]

You’re welcome. =)

**Edit.** I modified the code a bit to save CPU usage… nothing really important but still. 🙂
