Packagecitrus.core
Classpublic final class MediatorState
InheritanceMediatorState Inheritance Object

The MediatorState class is very important. It usually contains the logic for a particular state the game is in. You should never instanciate/extend this class by your own. It's used via a wrapper: State or StarlingState or Away3DState. There can only ever be one state running at a time. You should extend the State class to create logic and scripts for your levels. You can build one state for each level, or create a state that represents all your levels. You can get and set the reference to your active state via the CitrusEngine class.



Public Properties
 PropertyDefined By
  objects : Vector.<CitrusObject>
[read-only] Contains all the objects added to the State and not killed.
MediatorState
  view : ACitrusView
Gets a reference to this state's view manager.
MediatorState
Public Methods
 MethodDefined By
  
MediatorState
  
Call this method to add a CitrusObject to this state.
MediatorState
  
Call this method to add an Entity to this state.
MediatorState
  
Call this method to add a PoolObject to this state.
MediatorState
  
destroy():void
Called by the Citrus Engine.
MediatorState
  
Returns the first instance of a CitrusObject that is of the class that you pass in.
MediatorState
  
Gets a reference to a CitrusObject by passing that object's name in.
MediatorState
  
getObjectsByName(name:String):Vector.<CitrusObject>
This returns a vector of all objects of a particular name.
MediatorState
  
getObjectsByType(type:Class):Vector.<CitrusObject>
This returns a vector of all objects of a particular type.
MediatorState
  
killAllObjects(except:Array):void
Destroy all the objects added to the State and not already killed.
MediatorState
  
remove(object:CitrusObject):void
removeImmediately instaneously destroys and remove the object from the state.
MediatorState
  
MediatorState
  
update(timeDelta:Number):void
This method calls update on all the CitrusObjects that are attached to this state.
MediatorState
Property Detail
objectsproperty
objects:Vector.<CitrusObject>  [read-only]

Contains all the objects added to the State and not killed.


Implementation
    public function get objects():Vector.<CitrusObject>
viewproperty 
view:ACitrusView

Gets a reference to this state's view manager. Take a look at the class definition for more information about this.


Implementation
    public function get view():ACitrusView
    public function set view(value:ACitrusView):void
Constructor Detail
MediatorState()Constructor
public function MediatorState(istate:IState)



Parameters
istate:IState
Method Detail
add()method
public function add(object:CitrusObject):CitrusObject

Call this method to add a CitrusObject to this state. All visible game objects and physics objects will need to be created and added via this method so that they can be properly created, managed, updated, and destroyed.

Parameters

object:CitrusObject

Returns
CitrusObject — The CitrusObject that you passed in. Useful for linking commands together.
addEntity()method 
public function addEntity(entity:Entity):Entity

Call this method to add an Entity to this state. All entities will need to be created and added via this method so that they can be properly created, managed, updated, and destroyed.

Parameters

entity:Entity

Returns
Entity — The Entity that you passed in. Useful for linking commands together.
addPoolObject()method 
public function addPoolObject(poolObject:PoolObject):PoolObject

Call this method to add a PoolObject to this state. All pool objects and will need to be created and added via this method so that they can be properly created, managed, updated, and destroyed.

Parameters

poolObject:PoolObject — The PoolObject isCitrusObjectPool's value must be true to be render through the State.

Returns
PoolObject — The PoolObject that you passed in. Useful for linking commands together.
destroy()method 
public function destroy():void

Called by the Citrus Engine.

getFirstObjectByType()method 
public function getFirstObjectByType(type:Class):CitrusObject

Returns the first instance of a CitrusObject that is of the class that you pass in. This is useful if you know that there is only one object of a certain time in your state (such as a "Hero").

Parameters

type:Class — The class of the object you want to get a reference to.

Returns
CitrusObject
getObjectByName()method 
public function getObjectByName(name:String):CitrusObject

Gets a reference to a CitrusObject by passing that object's name in. Often the name property will be set via a level editor such as the Flash IDE.

Parameters

name:String — The name property of the object you want to get a reference to.

Returns
CitrusObject
getObjectsByName()method 
public function getObjectsByName(name:String):Vector.<CitrusObject>

This returns a vector of all objects of a particular name. This is useful for adding an event handler to objects that aren't similar but have the same name. For instance, you can track the collection of coins plus enemies that you've named exactly the same. Then you'd loop through the returned vector to change properties or whatever you want.

Parameters

name:String — The name property of the object you want to get a reference to.

Returns
Vector.<CitrusObject>
getObjectsByType()method 
public function getObjectsByType(type:Class):Vector.<CitrusObject>

This returns a vector of all objects of a particular type. This is useful for adding an event handler to all similar objects. For instance, if you want to track the collection of coins, you can get all objects of type "Coin" via this method. Then you'd loop through the returned array to add your listener to the coins' event.

Parameters

type:Class — The class of the object you want to get a reference to.

Returns
Vector.<CitrusObject>
killAllObjects()method 
public function killAllObjects(except:Array):void

Destroy all the objects added to the State and not already killed.

Parameters

except:Array — CitrusObjects you want to save.

remove()method 
public function remove(object:CitrusObject):void

removeImmediately instaneously destroys and remove the object from the state. While using remove() is recommended, there are specific case where this is needed. please use with care.

Parameters

object:CitrusObject

removeImmediately()method 
public function removeImmediately(object:CitrusObject):void

Parameters

object:CitrusObject

update()method 
public function update(timeDelta:Number):void

This method calls update on all the CitrusObjects that are attached to this state. The update method also checks for CitrusObjects that are ready to be destroyed and kills them. Finally, this method updates the View manager.

Parameters

timeDelta:Number