Over 10 years of community discussion and knowledge are maintained here as a read-only archive.
// shorter, friendlier constants :)public static const CHANGE_STATE:String = "changeState" internal static const EXIT:String = "exit" // only visible to the packageinternal static const ENTER:String = "enter" // only visible to the package
private function getNoteName(state:State, phase:String):String{ return state.name + phase;}
public function registerStateChangeCommands(enterCommand:Class, exitCommand:Class, state:State):void{ facade.registerCommand(getNoteName(state, StateConstants.ENTER), enterCommand); facade.registerCommand(getNoteName(state, StateConstants.EXIT), exitCommand); } public function removeStateChangeCommands(state:State):void{ facade.removeCommand(getNoteName(state, StateConstants.ENTER)); facade.removeCommand(getNoteName(state, StateConstants.EXIT)); }private function exitState(state:State):void{ if(currentState == null) return sendNotification(getNoteName(state,EXIT), state);} private function enterState(state:State):void{ viewComponent = state; sendNotification(getNoteName(state,ENTER), state)}
public function changeState(state:State):void{ if(currentState && state.name == currentState.name) throw new Error ("The Application is already in this state"); exitState(currentState); enterState(state); }
public function changeState(state:State):void{ if(currentState && state.name == currentState.name) return; exitState(currentState); enterState(state); }
public function changeStateStrict(state:State):void{ if(currentState && state.name == currentState.name) throw new Error ("The Application is already in this state"); changeState(state); }
also, perhaps I should subclass and add some state history?