Tuesday, May 13, 2008

Enumerations in ActionScript 2.0

Here is an alternate for Enumerations in ActionScript 2.0. Just add an item with needed name as a member to the class (as _NORMAL or _ENUM_ITEM) and then use them through the "get" functions from another code.

/**
* @author Artak Mkrtchyan
*/
class EnumTypeName extends Number
{
private static var _NORMAL:EnumTypeName = EnumTypeName(0);
private static var _ENUM_ITEM:EnumTypeName = EnumTypeName(1);

private function EnumTypeName(value:Number){

}

public static function get NORMAL() : EnumTypeName {
return _NORMAL;
}

public static function get _ENUM_ITEM() : EnumTypeName {
return _ENUM_ITEM;
}
}


////////////////////////////////
//And here is the usage of this

//.... another class
public function test():Void{
var testVar:EnumTypeName;

testVar = EnumTypeName.NORMAL;
}
//.... other code
Post a Comment