# Hittest and Gotoandplay

**URL:** <https://forum.kirupa.com/t/hittest-and-gotoandplay/64340>\
**Category:** flash\
**Created:** [September 15, 2004, 11:00am UTC](https://forum.kirupa.com/t/hittest-and-gotoandplay/64340 "2004-09-15T11:00:40Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![flashy22](https://avatars.discourse-cdn.com/v4/letter/f/848f3c/32.png) [@flashy22](https://forum.kirupa.com/u/flashy22)\
**Post date:** [September 15, 2004, 11:00am UTC](https://forum.kirupa.com/t/hittest-and-gotoandplay/64340/1 "2004-09-15T11:00:40Z")

</div>

Hello all,  
For starters if anyone wants to see the fla i will post it,  
Ok, i did the tutorial on firing ([http://www.kirupa.com/developer/mx/fire.htm](http://www.kirupa.com/developer/mx/fire.htm))  
and i wanted to put in an enemy, that would play when hit,  
basiccly i just quickly drew a rectangle and made it a movieclip,  
i called it enemy, and put its instance name as enemy aswell,  
( the bullets instance name is bullets), then i went into the enemy movieclip and made the first frame stop, and second playing the dying animation, then stopping on the fifth with nothing there. i put this code on the enemy movieclip but it wont work, as i am new to AS i dont really know what is wrong Please help!

onClipEvent(load){  
if (\_root.enemy, hittest(\_root.bullets)) {  
\_root.enemy = gotoAndPlay(2);  
}  
}

thanks alot,  
Ben (flashy22)

---

<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:** [September 15, 2004, 12:02pm UTC](https://forum.kirupa.com/t/hittest-and-gotoandplay/64340/2 "2004-09-15T12:02:43Z")

</div>

> [@flashy22](#):
>
> onClipEvent(load){  
> if [color=red](\_root.enemy, hittest(\_root.bullets))[/color] {  
> \_root.enemy[color=red] =[/color] gotoAndPlay(2);  
> }  
> }

**[color=green]wrong syntax…[/color]**

```auto

onClipEvent(load){ 
if (_root.enemy[color=red].[/color]hit[color=red]T[/color]est(_root.bullets)) {
	 _root.enemy[color=red].[/color]gotoAndPlay(2);
}
}

```

---

<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:** [September 15, 2004, 12:11pm UTC](https://forum.kirupa.com/t/hittest-and-gotoandplay/64340/3 "2004-09-15T12:11:06Z")

</div>

No that didnt work, and i accidently, got it wrong, its instance is bullet, ill post the .fla if you need to see it,  
please help,  
Ben (flashy22)

---

<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:** [September 15, 2004, 12:27pm UTC](https://forum.kirupa.com/t/hittest-and-gotoandplay/64340/4 "2004-09-15T12:27:04Z")

</div>

onClipEvent (load) is executed only when your mc loads for the first time.  
my guess is that you’d want and  
onClipEvent(enterFrame)

---

<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:** [September 16, 2004, 1:59am UTC](https://forum.kirupa.com/t/hittest-and-gotoandplay/64340/5 "2004-09-16T01:59:03Z")

</div>

> [@virusescu](#):
>
> onClipEvent (load) is executed only when your mc loads for the first time.  
> my guess is that you’d want and  
> onClipEvent(enterFrame)

No unfortunalty that didnt work either!  
thanks in advance,  
Ben (flashy22)

---

<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:** [September 16, 2004, 4:30am UTC](https://forum.kirupa.com/t/hittest-and-gotoandplay/64340/6 "2004-09-16T04:30:06Z")

</div>

did you try just putting the if statement inside the movie clip?

---

<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:** [September 16, 2004, 5:08am UTC](https://forum.kirupa.com/t/hittest-and-gotoandplay/64340/7 "2004-09-16T05:08:26Z")

</div>

// root frame 5

if (\_root.enemy.hitTest(\_root.bullets)) {  
\_root.enemy.gotoAndPlay(2);  
}  
\_root.gotoAndPlay(4);
