Saturday 16 April 2011

StateManager

The state manager works like a traffic light system or it can be used light switch system. The traffic light system has a number of states and when one is turned on the rest turn off. The light switch system has a list of states which can have more than one state turned on.

1. first you have to create a string of state names as shown below:


public static const UNIT_WEIGHT_METRIC : String = "UNIT_WEIGHT_METRIC";
public static const UNIT_WEIGHT_IMPERIAL : String = "UNIT_WEIGHT_IMPERIAL";
public static const UNIT_HEIGHT_METRIC : String = "UNIT_HEIGHT_METRIC";
public static const UNIT_HEIGHT_IMPERIAL : String = "UNIT_HEIGHT_IMPERIAL";

2. Create a StateManager and add each state to it, by default the reserved value is set to false which means the states acts in the traffic light system so if you want to use the light switch system you must set the reserved value to true as shown below.

configState = new StateManager();
configState.addState( UNIT_WEIGHT_METRIC, true );
configState.addState( UNIT_WEIGHT_IMPERIAL, true );
configState.addState( UNIT_HEIGHT_METRIC, true );
configState.addState( UNIT_HEIGHT_IMPERIAL, true );

3.All the states by default are turned off, in order to turn on a state you must do the following.
configState.stateKey = Survey.UNIT_HEIGHT_IMPERIAL;

4.To turn off a state you need to do the same as above as the state manager will check the state and switch it.

5. To check if the state is turned on or off you do the following.

if ( configState.compare( Survey.UNIT_HEIGHT_IMPERIAL))


No comments:

Post a Comment