nextScene / nextFrame

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.

well it seems to work properly…
se this sample
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

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!

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.

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.

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.

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();

can you post your fla file ?

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.

	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? :open_mouth:

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.

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.

Now that just seems like poor design :open_mouth:

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]