Search code examples
actionscript-3flashscene

Flash Playhead Going to Wrong Scene, No Explainable Cause


Every now and then Flash does something unusual, even with something as simple as a little scene navigation. The problem is that instead of going to the "PitOne" scene as directed on the first scene, the Flash playhead oddly enough arrives on our "LevelOne" scene. This puzzles me, because I can't figure out what could possibly alter the path of the Flash playhead.

On the last line of the first scene I directly tell Flash to go to our "PitOne" Scene, which means that even if there are any other navigation methods called before, only this last one should be executed.

Besides this, there are no eventListeners added on the first scene, other than some mouse click events. However, since immediately after exporting the Flash movie we are immediately brought to the dreaded "LevelOne" scene, we can assume that these eventListeners have nothing to do with our problem.

I set a trace method on each scene to track the encounters of our Flash playhead. According to the traced output, Flash only enters the first scene and the "LevelOne" scene, so we go directly from the first scene to the "LevelOne" scene. This means that if there is a problem on my part, it's on the first Scene. But what could possibly alter our scene navigation path in the scenario I've just described to you? If you have any possible ideas of what it could be, please tell me! Thank you for your time.

Additional Info: Perhaps it might help if I tell you that whenever I return to the first scene the scene navigation code seems to kick in and starts working, because then we are sent to the "PitOne" scene.

I also realize that if you're like me, you'll want to see the real code at hand. Here's the significant code for the first scene (we know that the problem is on the first scene because it's this scene that launches us directly to the "LevelOne" scene):

import flash.events.MouseEvent;
import flash.geom.Point;
import flash.events.Event;
import flash.display.MovieClip;
import flash.display.Scene;
import flash.text.TextFormat;

stop();


playNewBtn.addEventListener(MouseEvent.CLICK,playNew);
function playNew(e:MouseEvent){
    playNewBtn.removeEventListener(MouseEvent.CLICK,playNew);
    settingsBtn.removeEventListener(MouseEvent.CLICK,gotoSettings);
    creditsBtn.removeEventListener(MouseEvent.CLICK,gotoCredits);
    gotoAndPlay(1,"LevelOne");
}

settingsBtn.addEventListener(MouseEvent.CLICK,gotoSettings);
function gotoSettings(e:MouseEvent){
    playNewBtn.removeEventListener(MouseEvent.CLICK,playNew);
    settingsBtn.removeEventListener(MouseEvent.CLICK,gotoSettings);
    creditsBtn.removeEventListener(MouseEvent.CLICK,gotoCredits);
    gotoAndPlay(1,"Settings");
}

creditsBtn.addEventListener(MouseEvent.CLICK,gotoCredits);
function gotoCredits(e:MouseEvent){
    playNewBtn.removeEventListener(MouseEvent.CLICK,playNew);
    settingsBtn.removeEventListener(MouseEvent.CLICK,gotoSettings);
    creditsBtn.removeEventListener(MouseEvent.CLICK,gotoCredits);
    gotoAndPlay(1,"Credits");
}


gotoAndPlay(1,"PitOne");

Solution

  • it looks like you throw the command before scene is loaded. Whatever you try, (by adding a listener wich check if scene is loaded) the flash player will stay at scene 1 frame 1 until scene "pitOne" is loaded. That's why a good practice is to create a preloader to insure you all you need is correctly loaded before throwing command to go somewhere in the timeline. You have simple and well explained sample here : http://www.republicofcode.com/tutorials/flash/as3preloader/. Another solution for you is to set your scene "pitOne" at first position when you export your movie