# If Statment in a Enter Frame

**URL:** <https://forum.kirupa.com/t/if-statment-in-a-enter-frame/14463>\
**Category:** flash\
**Created:** [February 26, 2003, 5:50pm UTC](https://forum.kirupa.com/t/if-statment-in-a-enter-frame/14463 "2003-02-26T17:50:58Z")\
**Posts on this page:** 11\
**Page:** 1

<div class="post-metadata">

**Author:** ![sintax321](https://avatars.discourse-cdn.com/v4/letter/s/d78d45/32.png) [@sintax321](https://forum.kirupa.com/u/sintax321)\
**Post date:** [February 26, 2003, 5:50pm UTC](https://forum.kirupa.com/t/if-statment-in-a-enter-frame/14463/1 "2003-02-26T17:50:58Z")

</div>

I have an If statment in a on(EnterFrame) in side the actions of a movie clip. For some reason it does not work. I have other if statments in on enter frames and they all work but this one jsut doesn’t.

I was told that a on(enterframe) continues to repeat the code while the frame head is over it so it should alwasy check the if statment until the conidtion comes true and moves the frame head. Is my logic not correct?

Here is the code

```php
onClipEvent (enterFrame) {
	if(_root.life <= _root.dead) {
		gotoAndPlay("main", "gameover");
	}
}

```

It is for a shooting game. “life” starts at “100” and “dead” is “0”. When my “life” drops to “0” it will be less then or equal to “dead”. It should goto the fram label “gameover” which has a stop action and display some game stats. Any ideas

---

<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:** [February 26, 2003, 6:03pm UTC](https://forum.kirupa.com/t/if-statment-in-a-enter-frame/14463/2 "2003-02-26T18:03:08Z")

</div>

**\_root**.gotoAndPlay… :sure:

---

<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:** [February 26, 2003, 6:03pm UTC](https://forum.kirupa.com/t/if-statment-in-a-enter-frame/14463/3 "2003-02-26T18:03:51Z")

</div>

\_root, or any clip you want, of course, as long as the path is correct 🙂

---

<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:** [February 26, 2003, 6:07pm UTC](https://forum.kirupa.com/t/if-statment-in-a-enter-frame/14463/4 "2003-02-26T18:07:53Z")

</div>

Ok i added the \_root( which i would have never noticed)

```php
onClipEvent(enterFrame) {
	if(_root.health <= _root.dead) {
		_root.gotoAndPlay("main", "gameover");
	}
}

```

And the paths are al right and stuff but when health reaches zerp it still won’t exicute the code. Could i e-mail u the FLA if your not to busy?

---

<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:** [February 26, 2003, 6:10pm UTC](https://forum.kirupa.com/t/if-statment-in-a-enter-frame/14463/5 "2003-02-26T18:10:00Z")

</div>

Try this:

```php
onClipEvent(enterFrame) {
	if(_root.health <= _root.dead) {
		_root.gotoAndPlay("main", "gameover");
		trace ("Ya dead!");
	}
}

```

Does it trace anything? If it does, it’s probable that it’s not working because you’re gotoAndPlaying to a scene name. Try to use frame labels instead.

pom :phil:

---

<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:** [February 26, 2003, 6:11pm UTC](https://forum.kirupa.com/t/if-statment-in-a-enter-frame/14463/6 "2003-02-26T18:11:02Z")

</div>

By the way, I hope I can see the finished game some day 🙂

---

<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:** [February 26, 2003, 6:21pm UTC](https://forum.kirupa.com/t/if-statment-in-a-enter-frame/14463/7 "2003-02-26T18:21:16Z")

</div>

are you using scenes? :!:

🙂 its a common problem with using scenes in movieclips. In short, you cant use scenes in movieclips, only from the main timeline. Though you may have written that code from the maintimeline, its still being played in the scope of that movieclip, at which case the movieclip is trying to go to the label “main”

if you want to go to a frame in the main timeling from there, you should use a frame label and say

\_root.gotoAndPlay(“frameLabel”)

---

<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:** [February 26, 2003, 6:29pm UTC](https://forum.kirupa.com/t/if-statment-in-a-enter-frame/14463/8 "2003-02-26T18:29:57Z")

</div>

Although Scenes are horrible, they really do need to fix some bugs with using 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:** [February 26, 2003, 6:38pm UTC](https://forum.kirupa.com/t/if-statment-in-a-enter-frame/14463/9 "2003-02-26T18:38:43Z")

</div>

Ya it hit zero and it started to trace yets it still wouldn’t play the goto. I changed the goto to jsut a frame numbe and now it works. but i’m having some score issues. Here is a link for the game so far. No preloaders yet and it is 58k so it might taek a bit.  
\*edit ya sen i was trying to use scenes fir the first part and that was porbably the biggest probelm. now that i’m not it works fine.

[http://www.sintax321.com/sgt/sgtgame.html](http://www.sintax321.com/sgt/sgtgame.html)

---

<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:** [February 26, 2003, 7:09pm UTC](https://forum.kirupa.com/t/if-statment-in-a-enter-frame/14463/10 "2003-02-26T19:09:41Z")

</div>

Ok i got the score working and a “play again” button. Ther is still a ton of detail i’m going to put in but thisis the bulk of it.

\*edit oh ya and thanks for all your help you guys.(-:

[http://www.sintax321.com/sgt/sgtgame.html](http://www.sintax321.com/sgt/sgtgame.html)

---

<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:** [February 26, 2003, 7:19pm UTC](https://forum.kirupa.com/t/if-statment-in-a-enter-frame/14463/11 "2003-02-26T19:19:07Z")

</div>

Cool game :cool:

You should make the dynamic text boxes unselectable… ya know… while your still working on it and all 🙂
