Over 10 years of community discussion and knowledge are maintained here as a read-only archive.
Is there any possibility in runtime to get the list of all possible transitions from current state and the list of actions initiating these transitions as well?
override public function execute ( note:INotification ) : void{ // Create the FSM definition var fsm:XML = <fsm initial={FSMConstants.INTERNET_CHECKING}> <state name={FSMConstants.INTERNET_CHECKING}> <transition action={FSMConstants.INTERNET_ONLINE} target={FSMConstants.UPDATE_CHECKING}/> <transition action={FSMConstants.INTERNET_OFFLINE} target={FSMConstants.INACTIVE}/> </state> <state name={FSMConstants.INACTIVE}> <transition action={FSMConstants.INTERNET_ONLINE} target={FSMConstants.UPDATE_CHECKING}/> </state> <state name={FSMConstants.UPDATE_CHECKING} changed={FSMConstants.CHECK_FOR_UPDATE}> <transition action={FSMConstants.UPDATE_PENDING} target={FSMConstants.UPDATE_AVAILABLE}/> <transition action={FSMConstants.NO_UPDATE_PENDING} target={FSMConstants.LICENSE_CHECKING}/> </state> . . . </fsm>; // Create and inject the StateMachine var injector:FSMInjector = new FSMInjector( fsm ); injector.initializeNotifier(this.multitonKey); // if using MultiCore injector.inject(); // Stash the FSM for later reference facade.registerProxy( new Proxy( FSMConstants.ProxyName, fsm ) );}
override public function handleNotification( note:INotification ):void { switch ( note.getName() ) { case StateMachine.CHANGED: var state:State = note.getBody() as State; var fsm:XML = facade.retrieveProxy(FSMConstants.ProxyName).getData() as XML; var transitions:XMLList = fsm.state.(@name==state.name)..transition; var actions:Array; for each (var transition:XML in transitions); { actions.push (transition.@action.toString); } myViewComponent.addButtons(actions); break; . . . }}
public class FSMProxy extends Proxy{ public static const NAME:String = 'FSMProxy'; public function FSMProxy( fsm:XML ) { super ( NAME, fsm ); } // Return a list of valid actions for the given state as an array of strings public function getActionsForState( state:State ):Array { var transitions:XMLList = fsm.state.(@name==state.name)..transition; var actions:Array; for each (var transition:XML in transitions); { actions.push (transition.@action.toString); } return actions; } private function get fsm():XML { return data as XML; }}
override public function execute ( note:INotification ) : void{ . . . // Stash the FSM for later reference facade.registerProxy( new FSMProxy( fsm ) );}
private var fsmProxy:FSMProxy;override public function onRegister():void{ facade.retrieveProxy(FSMProxy.NAME);}override public function handleNotification( note:INotification ):void { switch ( note.getName() ) { case StateMachine.CHANGED: var state:State = note.getBody() as State; var actions:Array = fsmProxy.getActionsForState(state); myViewComponent.addButtons( actions ); break; . . . }}