Created
August 25, 2011 20:18
-
-
Save neilmanuell/1171775 to your computer and use it in GitHub Desktop.
example of how to retain classes for StateMachine util
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public function FSMInjector( fsm:XML, commandMap:ICommandMap ){ | |
this.fsm = fsm; | |
this.commandMap = commandMap; | |
} | |
public function addClass( value:Class ):void{ | |
if( !validateIsCommand( value ) ) | |
throw new Error ("not a command") | |
} | |
protected function createState( stateDef:XML ):State{ | |
// ... do all normal stuff | |
// map command any way you want | |
commandMap.mapEvent( stateDef.@entered, getDefinitionByName( stateDef.@cmdClass ) ); | |
return state; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var fsmInjector:FSMInjector = new FSMInjector( FSMData, commadMap ); | |
fsmInjector.addClass( MyFirstCommand); | |
fsmInjector.addClass( MySecondCommand ); | |
fsmInjector.inject( stateMachine ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
This is just a suggestion, written from the top of my head. This probably wont work straight ofrf, but it will give you an idea.
The addClass method does not need to have any code implemented, it is simply a conceit to get the classes to be compile in the place where some body looking at your code in a years time would go looking for it.
In this example I suggest that you could do a bit of reflection to check that it has an execute() method, though the CommandMap will do this for you, so the idea is a bit redundant.