Packagecom.whirled.contrib
Classpublic class GameModeStack

GameModeStack implements a stack of user-specific game modes. Modes can be pushed on to or popped off of the stack. Whenever a new mode is pushed on the stack, the old top is cleaned up, and the new one is initialized; vice versa for popping a mode off the stack. Usage example:
   var mgr :GameModeStack = new GameModeStack(switchDisplayFn);
   mgr.push(new MainMenu());
   ...
   // in the main menu, we decide to pick a level
   mgr.push(new LevelSelectorScreen());
   ...
   // inside the level selector, we start the game:
   mgr.push(new GameScreen());
   ...
   // inside the game screen, once it was won or lost:
   mgr.pop();
 



Protected Properties
 PropertyDefined by
  _callback : Function
Function that will be called every time the stack changes.
GameModeStack
  _stack : Array
Internal storage for the stack.
GameModeStack
Public Methods
 MethodDefined by
  
GameModeStack(callback:Function)
Constructor, receives a function to be called whenever the top of the stack changes.
GameModeStack
  
clear():void
Pops all items off the stack.
GameModeStack
  
Pops and returns the current top game mode from the stack.
GameModeStack
  
push(newMode:GameMode):void
Pushes a new game mode on top of the stack.
GameModeStack
  
Returns the top of the mode stack.
GameModeStack
Property detail
_callbackproperty
protected var _callback:Function

Function that will be called every time the stack changes.

_stackproperty 
protected var _stack:Array

Internal storage for the stack.

Constructor detail
GameModeStack()constructor
public function GameModeStack(callback:Function)

Constructor, receives a function to be called whenever the top of the stack changes.

Parameters
callback:Function — Called whenever the top of the stack changes. Should be a function like: function (previousTop :GameMode, newTop :GameMode) :void { } - where previousTop is the mode previously selected, and newTop is the mode currently selected (either can be null).
Method detail
clear()method
public function clear():void

Pops all items off the stack.

pop()method 
public function pop():GameMode

Pops and returns the current top game mode from the stack. Popping an empty stack is safe, it simply returns null.

Returns
GameMode
push()method 
public function push(newMode:GameMode):void

Pushes a new game mode on top of the stack.

Parameters
newMode:GameMode
top()method 
public function top():GameMode

Returns the top of the mode stack. If the stack is empty, returns null.

Returns
GameMode