AS3 State Machine allows you to create simple and hierarchical StateMachines. State Machines are composed of states, and each state has (optional) callbacks for entering and exiting state. It’s also possible to restrict the transition from states and to create hierarchical state machines.

Sample

playerSM = new StateMachine();
playerSM.addState("playing",{ enter: onPlayingEnter, exit: onPlayingExit, from:["paused","stopped"] });
playerSM.addState("paused",{ enter: onPausedEnter, from:"playing"});
playerSM.addState("stopped",{ enter: onStoppedEnter, from:"*"});

playerSM.addEventListener(StateMachineEvent.TRANSITION_DENIED,transitionDeniedFunction);
playerSM.addEventListener(StateMachineEvent.TRANSITION_COMPLETE,transitionCompleteFunction);

playerSM.initialState = "stopped";
State machine . URL.