Created
January 30, 2010 22:52
-
-
Save mimshwright/290770 to your computer and use it in GitHub Desktop.
using a whacky hack to create single instances of several classes at once.
This file contains hidden or 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
| /** | |
| * creates a single instance of each state and stores them in a dictionary of states. | |
| */ | |
| // OH, HACKY! .... OR BRILLIANT? | |
| protected function initializeStates():void { | |
| allStates = new Dictionary( false ); | |
| //This vector contains several state classes i want to instantiate. | |
| var stateClasses:Vector.<Class> = new Vector.<Class> ([MainMenuState, CreditsState, GameplayState]); | |
| for each ( var stateClass:Class in stateClasses) { | |
| allStates[stateClass] = new stateClass(); | |
| } | |
| } | |
| /** | |
| * Gets the instance of the state based on the class. | |
| */ | |
| public function getState(stateClass:Class):IGameState { | |
| return allStates[stateClass] as IGameState; | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment