# nextScene / nextFrame

**URL:** <https://forum.kirupa.com/t/nextscene-nextframe/265527>\
**Category:** flash\
**Created:** [July 9, 2008, 9:21pm UTC](https://forum.kirupa.com/t/nextscene-nextframe/265527 "2008-07-09T21:21:59Z")\
**Posts on this page:** 13\
**Page:** 1

<div class="post-metadata">

**Author:** ![gigaboost](https://avatars.discourse-cdn.com/v4/letter/g/58956e/32.png) [@gigaboost](https://forum.kirupa.com/u/gigaboost)\
**Post date:** [July 9, 2008, 9:21pm UTC](https://forum.kirupa.com/t/nextscene-nextframe/265527/1 "2008-07-09T21:21:59Z")

</div>

I have a problem with the nextScene(); command, it doesnt seem to be working at all. Code:

if(\_x \> 10){  
\_root.nextScene();  
nextScene();  
\_root.gotoAndPlay(nextScene);  
}  
I only use one of these commands at a time but none of them seem to be working, what is the propper way to format nextScene? if I put a trace command inside the same if statement that triggers correctly.

If it helps the code is inside a movie clip thats on the stage, in a enterFrame clip event.

---

<div class="post-metadata">

**Author:** ![sparkdemon](https://avatars.discourse-cdn.com/v4/letter/s/958977/32.png) [@sparkdemon](https://forum.kirupa.com/u/sparkdemon)\
**Post date:** [July 10, 2008, 6:00pm UTC](https://forum.kirupa.com/t/nextscene-nextframe/265527/2 "2008-07-10T18:00:20Z")

</div>

well it seems to work properly…  
se this sample  
[http://www.4shared.com/file/54652597/1088e0e5/scene\_navigation.html](http://www.4shared.com/file/54652597/1088e0e5/scene_navigation.html)

1. check your scene order
2. nextScene is a global function … you dont need to use \_root with it

---

<div class="post-metadata">

**Author:** ![gigaboost](https://avatars.discourse-cdn.com/v4/letter/g/58956e/32.png) [@gigaboost](https://forum.kirupa.com/u/gigaboost)\
**Post date:** [July 11, 2008, 6:06pm UTC](https://forum.kirupa.com/t/nextscene-nextframe/265527/3 "2008-07-11T18:06:59Z")

</div>

Hmm, nope, it refuses to work. Darnit!

Only workaround I can think of is gotoandplay with scenes, but thats so unpractical when I have this many scenes.

Anybody got any solutions or workarounds for this it will be appriciated!

---

<div class="post-metadata">

**Author:** ![glosrfc](https://yyz1.discourse-cdn.com/flex011/user_avatar/forum.kirupa.com/glosrfc/32/8334_2.png) [@glosrfc](https://forum.kirupa.com/u/glosrfc)\
**Post date:** [July 11, 2008, 6:58pm UTC](https://forum.kirupa.com/t/nextscene-nextframe/265527/4 "2008-07-11T18:58:57Z")

</div>

The code looks fine (although without need for \_root) but what \_x are you referring to? If it’s the \_x position of the movieclip the code is attached to, you can try this.\_x otherwise you might have to target the movieclip explicitly, e.g. that\_mc.\_x  
The obvious question is…why so many scenes? In the first place, they are only temporary as an aide to organising your objects. Any reference to scenes is deleted in your compiled SWF. Secondly, as you’ve found out, scoping scenes can cause all kinds of problems.  
Ideally you should place your content into movieclips instead of scenes and then transfer the playhead around those.

---

<div class="post-metadata">

**Author:** ![gigaboost](https://avatars.discourse-cdn.com/v4/letter/g/58956e/32.png) [@gigaboost](https://forum.kirupa.com/u/gigaboost)\
**Post date:** [July 11, 2008, 7:50pm UTC](https://forum.kirupa.com/t/nextscene-nextframe/265527/5 "2008-07-11T19:50:48Z")

</div>

Thanks for the great answer, mainly the reason to why I am using scenes is the ability to test a scene at a time, so I dont have to play through to the scene I want to test. And it helps me sort things.

I could use frames instead of scenes, but then I cant testplay a single frame without going through the entire shizzle.

EDIT: The if statement works correctly, cuz if I put any other commands or a trace command in it they trigger correctly.

---

<div class="post-metadata">

**Author:** ![glosrfc](https://yyz1.discourse-cdn.com/flex011/user_avatar/forum.kirupa.com/glosrfc/32/8334_2.png) [@glosrfc](https://forum.kirupa.com/u/glosrfc)\
**Post date:** [July 11, 2008, 8:23pm UTC](https://forum.kirupa.com/t/nextscene-nextframe/265527/6 "2008-07-11T20:23:26Z")

</div>

But you can still test individual movieclips either by dropping an instance onto the stage and using CTRL+Enter, or by editing the movieclip and just hitting Enter.

Seriously, you should do away with scenes because they’re particularly evil when you compile your SWF. I’m sure the if statement does work, for a given value of \_x (although I’m still unsure which \_x your code refers to); it’s Flash’s inability to understand which particular scene it should branch to in the compiled SWF that’s the problem.

---

<div class="post-metadata">

**Author:** ![glosrfc](https://yyz1.discourse-cdn.com/flex011/user_avatar/forum.kirupa.com/glosrfc/32/8334_2.png) [@glosrfc](https://forum.kirupa.com/u/glosrfc)\
**Post date:** [July 11, 2008, 8:27pm UTC](https://forum.kirupa.com/t/nextscene-nextframe/265527/7 "2008-07-11T20:27:07Z")

</div>

One solution you can try is to place a frame label in the first frame of each scene…call them scene1, scene2, scene3 etc. if you wish.

Then use gotoAndPlay(“sceneXX”); in your conditional statement instead of nextScene();

---

<div class="post-metadata">

**Author:** ![sparkdemon](https://avatars.discourse-cdn.com/v4/letter/s/958977/32.png) [@sparkdemon](https://forum.kirupa.com/u/sparkdemon)\
**Post date:** [July 11, 2008, 9:42pm UTC](https://forum.kirupa.com/t/nextscene-nextframe/265527/8 "2008-07-11T21:42:07Z")

</div>

can you post your fla file ?

---

<div class="post-metadata">

**Author:** ![Amymation](https://avatars.discourse-cdn.com/v4/letter/a/bc8723/32.png) [@Amymation](https://forum.kirupa.com/u/Amymation)\
**Post date:** [July 12, 2008, 6:35am UTC](https://forum.kirupa.com/t/nextscene-nextframe/265527/9 "2008-07-12T06:35:35Z")

</div>

You can test your game frame by frame I do it, When you test your game (Alt+Enter) just press enter until your at the frame you need to test (The enter thing won’t happen outside of testing in flash).  
Hope this helps.

---

<div class="post-metadata">

**Author:** ![gigaboost](https://avatars.discourse-cdn.com/v4/letter/g/58956e/32.png) [@gigaboost](https://forum.kirupa.com/u/gigaboost)\
**Post date:** [July 12, 2008, 4:31pm UTC](https://forum.kirupa.com/t/nextscene-nextframe/265527/10 "2008-07-12T16:31:32Z")

</div>

```php
	onClipEvent(enterFrame){

                if (this._x < -10) {
		nextScene();
		trace("out of bounds");
   }
}

```

Output just spams out of bounds but nothing happens to the scene.

Ive changed the nextScene(); to \_root.nextFrame(); and it works as it should, sort of. Just gotto make sure the frame this is happening in is the last one on the current scene.

> 

You can test your game frame by frame I do it, When you test your game (Alt+Enter) just press enter until your at the frame you need to test (The enter thing won’t happen outside of testing in flash).  
Hope this helps.

Thanks a lot for this man, this will come in handy for the future.

Thanks for your help GlosRFC and Sparkdemon as well, just one question:

> Seriously, you should do away with scenes \*\*because they’re particularly evil when you compile your SWF. \*\*

Are you telling there could be some trouble with exporting the flash movie because I’m using multiple scenes? 😮

---

<div class="post-metadata">

**Author:** ![glosrfc](https://yyz1.discourse-cdn.com/flex011/user_avatar/forum.kirupa.com/glosrfc/32/8334_2.png) [@glosrfc](https://forum.kirupa.com/u/glosrfc)\
**Post date:** [July 12, 2008, 4:36pm UTC](https://forum.kirupa.com/t/nextscene-nextframe/265527/11 "2008-07-12T16:36:44Z")

</div>

No, I’m telling you there **will** be trouble…the Flash Player has absolutely no concept of scenes, they are only in the Flash IDE to assist with organising symbols and simple timeline animations. When the FLA is exported, all of your scenes are concatenated into a single timeline which means, when using complex actionscripting, that references to scenes (and frame numbers in those scenes) are lost.

That’s why you should be using movieclips instead or, if you want to retain your existing scenes, use the frame label approach that I suggested earlier.

---

<div class="post-metadata">

**Author:** ![glosrfc](https://yyz1.discourse-cdn.com/flex011/user_avatar/forum.kirupa.com/glosrfc/32/8334_2.png) [@glosrfc](https://forum.kirupa.com/u/glosrfc)\
**Post date:** [July 12, 2008, 4:42pm UTC](https://forum.kirupa.com/t/nextscene-nextframe/265527/12 "2008-07-12T16:42:16Z")

</div>

Ive changed the nextScene(); to \_root.nextFrame(); and it works as it should, sort of. Just gotto make sure the frame this is happening in is the last one on the current scene.

Reread those lines again…don’t they strike you as remarkably familiar to my earlier explaination of scene behaviour in the SWF?

Scene 2 no longer exists because it’s been added to the end of Scene 1; Scene 3 is added to the end of Scene 2; Scene 3 is added to the end of…well, I’m sure you know where this is going.

That’s why nextFrame will work when you want to jump from the end of Scene 1 to Scene 2 but it won’t work if you want to go from Scene 1 to Scene 3. And it’s why it only works when the frame is the last one in the current scene.

---

<div class="post-metadata">

**Author:** ![gigaboost](https://avatars.discourse-cdn.com/v4/letter/g/58956e/32.png) [@gigaboost](https://forum.kirupa.com/u/gigaboost)\
**Post date:** [July 12, 2008, 5:43pm UTC](https://forum.kirupa.com/t/nextscene-nextframe/265527/13 "2008-07-12T17:43:45Z")

</div>

Now that just seems like poor design 😮

Thanks again for all your help glosRFC I think the problem should be solved with nextFrame instead, and thanks for deteering me from using scenes in the future!

[quote=glosrfc;2357476]No, I’m telling you there **will** be trouble…the Flash Player has absolutely no concept of scenes, they are only in the Flash IDE to assist with organising symbols and simple timeline animations. When the FLA is exported, all of your scenes are concatenated into a single timeline which means, when using complex actionscripting, that references to scenes (and frame numbers in those scenes) are lost.

That’s why you should be using movieclips instead or, if you want to retain your existing scenes, use the frame label approach that I suggested earlier.[/quote]
