DrakeTruber
DrakeTruber

Reputation: 327

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

Upvotes: 3

Views: 223

Answers (2)

scraaappy
scraaappy

Reputation: 2886

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

Upvotes: 1

null
null

Reputation: 5255

This is not an answer but cramping all this into a comment is tedious and not very readable.

Maybe you have a typo in one of the scenes names?

Try to run this code to get a list of all scenes:

import flash.display.Scene;

for (var i:uint = 0; i < scenes.length; i++) {
    var scene:Scene = scenes[i];
    trace("scene " + scene.name + ": " + scene.numFrames + " frames");
}

http://help.adobe.com/en_US/FlashPlatform/reference/actionscript/3/flash/display/MovieClip.html#scenes


The way you create Strings does not appear to be valid:

trace("entered "settings"");

should be

trace("entered settings");

If you want to include the " in the output, you have to escape them via \" or simply use ' instead.

In your code the " before settings marks the end of the string, instead of being a character of the string.


If you have "thousands of lines" it might be because of the amount of duplicated code.

function disableButtons():void
{
    playNewBtn.removeEventListener(MouseEvent.CLICK,playNew);
    settingsBtn.removeEventListener(MouseEvent.CLICK,gotoSettings);
    creditsBtn.removeEventListener(MouseEvent.CLICK,gotoCredits);
}

Upvotes: 2

Related Questions