Not only is this enum typesafe, it can be gotten, compared, and parsed.
// Creates and sets a state
var _state:InteractiveObjectState = InteractiveObjecState.parse("active");
// Returns that state
trace(InteractiveObjectState.toString(_state));
// Compares state
if(_state == InteractiveObjectState.DEFAULT) { // Do Something }
if you have a core interactive object, which all views inherit, then everything has inherited state management
Code:
package views.core {
/**
* Enum for Interactive Object State
*/
public class InteractiveObjectState {
public static const NONE:InteractiveObjectState = new InteractiveObjectState();
public static const DEFAULT:InteractiveObjectState = new InteractiveObjectState();
public static const ACTIVE:InteractiveObjectState = new InteractiveObjectState();
public static const INACTIVE:InteractiveObjectState = new InteractiveObjectState();
public static const HIDDEN:InteractiveObjectState = new InteractiveObjectState();
/**
* Parses an InteractiveObjectState Object from a String
* @param a as String
* @return an InteractiveObjectState Object
*/
public static function parse(s:String):InteractiveObjectState {
var retState:InteractiveObjectState;
switch(s.toLowerCase()) {
case "default":
retState = DEFAULT; break;
case "active":
retState = ACTIVE; break;
case "inactive":
retState = INACTIVE; break;
case "hidden":
retState = HIDDEN; break;
default:
retState = NONE; break;
}
return retState;
}
/**
* Displays the InteractiveObjectState as a String
* @param s as InteractiveObjectState
* @return String
*/
public static function toString(s:InteractiveObjectState):String {
var retStr:String;
switch(s) {
case DEFAULT:
retStr = "default"; break;
case ACTIVE:
retStr = "active"; break;
case INACTIVE:
retStr = "inactive"; break;
case HIDDEN:
retStr = "hidden"; break;
default:
retStr = "none"; break;
}
return retStr;
}
}
}