Skip to content

Instantly share code, notes, and snippets.

@neilmanuell
Created August 25, 2011 20:18
Show Gist options
  • Save neilmanuell/1171775 to your computer and use it in GitHub Desktop.
Save neilmanuell/1171775 to your computer and use it in GitHub Desktop.
example of how to retain classes for StateMachine util
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;
}
var fsmInjector:FSMInjector = new FSMInjector( FSMData, commadMap );
fsmInjector.addClass( MyFirstCommand);
fsmInjector.addClass( MySecondCommand );
fsmInjector.inject( stateMachine );
@neilmanuell
Copy link
Author

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment