I have implemented a VERY simple State Loop based off of some examples in the book: "The Essential guide to Flash Games" by Jeff and Steve Fulton; In this state machine I have a loop that updates the stage to the target gameState var through an Enter_Frame event.
Inside my Menu state I have a button with a MovieClip inside the OVER state that would normally loop ad infinitum so long as the button is in the OVER state, but the clip does not even play through once; I'm guessing its due to the Enter_Frame event placing a new instance every frame, My question is: Is there a better way to update the State loop only when the gameState var is changed or does that sound like the wrong guess at the problem?
Let me know if this is too vague on the details, I was not sure if posting the code snippets would really help for this question... Thanks for reading and for any responses ahead of time! Here's the code! :-)
//imports here
public class Loop extends MovieClip {
public static const STATE_MMENU:int = 10;
public static const STATE_OPTIONS:int = 11;
public static const STATE_NGAME:int = 20;
public static const STATE_CHARSELECT:int = 21;
public static const STATE_BATMAP:int = 22;
public static const STATE_BATSTORY:int = 23
public static const STATE_BATTLE:int = 30;
public static const STATE_DOMDICEPHASE:int = 31;
public static const STATE_ROLLPROCESS:int = 32;
public static const STATE_WINLOSSPHASE:int = 33;
public var gameState:int = 0;
public function Loop():void {
addEventListener(Event.ENTER_FRAME, gameLoop);
gameState = STATE_MMENU;
}
public function gameLoop(e:Event):void{
switch(gameState){
case STATE_MMENU: mainMenu(); break;
case STATE_OPTIONS: optionsMenu(); break;
case STATE_NGAME: newGame(); break;
case STATE_CHARSELECT: charaSelect(); break;
case STATE_BATMAP: battleMap(); break;
case STATE_BATSTORY: battleStory(); break;
case STATE_BATTLE: battlePhase(); break;
case STATE_DOMDICEPHASE: domDicePhase(); break;
case STATE_ROLLPROCESS: rollProcessPhase(); break;
case STATE_WINLOSSPHASE: winLossPhase(); break;
}
}
//insert functions for phases/states here lol :-0
public function mainMenu(){
var titleText:title_gfx = new title_gfx();
titleText.x = 520; titleText.y = 150;
addChild(titleText);
var newGameSel:newGame_btn = new newGame_btn();
newGameSel.x = 512; newGameSel.y = 300;
addChild(newGameSel);
//newGameSel.addEventListener(Mouse.MouseEvent.CLICK, newGameButton);
I'm inserting the button with the movieclip inside the mainMenu() function... Thanks again!