here is an example of a TypeSafe class for AS3 I just made that acts like an enum (typesafe means it's literally safe to declare a var as this type).
Code:
package com.layeronemedia.core {
public class DebugType {
public static const NONE:DebugType = new DebugType();
public static const TRACE:DebugType = new DebugType();
public static const TRACE_THROWERROR:DebugType = new DebugType();
public static const TRACE_THROWERROR_LOGREMOTELY:DebugType = new DebugType();
public static const THROWERROR:DebugType = new DebugType();
public static const THROWERROR_LOGREMOTELY:DebugType = new DebugType();
public static const LOGREMOTELY:DebugType = new DebugType();
public static function getDebugType(type:String):DebugType {
var retType:DebugType;
switch(type.toLowerCase()) {
case "logremotely":
retType = DebugType.LOGREMOTELY; break;
case "trace":
retType = DebugType.TRACE; break;
case "trace_throwerror":
retType = DebugType.TRACE_THROWERROR; break;
case "trace_throwerror_logremotely":
retType = DebugType.TRACE_THROWERROR_LOGREMOTELY; break;
case "throwerror":
retType = DebugType.THROWERROR; break;
case "throwerror_logremotely":
retType = DebugType.THROWERROR_LOGREMOTELY; break;
default:
retType = DebugType.NONE; break;
}
return retType;
}
public static function toString(a:DebugType):String {
var retType:String;
switch(a) {
case DebugType.LOGREMOTELY:
retType = "Log Error(s) Remotely Only"; break;
case DebugType.TRACE:
retType = "Trace Error(s) Only"; break;
case DebugType.TRACE_THROWERROR:
retType = "Trace and Throw Error(s)"; break;
case DebugType.TRACE_THROWERROR_LOGREMOTELY:
retType = "Trace, Throw, and Remotely Log Error(s)"; break;
case DebugType.THROWERROR:
retType = "Throw Error(s) Only"; break;
case DebugType.THROWERROR_LOGREMOTELY:
retType = "Throw, and Remotely Log Error(s)"; break;
default:
retType = "No Debug Type Selected"; break;
}
return retType;
}
}
}