To extend off of Dan R's answer, you could create a strict event (like the way you'd do enums) class like so:
import flash.utils.Dictionary;
import flash.utils.describeType;
import flash.utils.getQualifiedClassName;
public class StrictEvent
{
private static var VALID_EVENTS:Dictionary = new Dictionary();
public static function initEvents(inType:*):void {
var events:Object = {};
var description:XML = describeType(inType);
var constants:XMLList = description.constant;
for each(var constant:XML in constants) {
events[inType[constant.@name]] = true;
}
VALID_EVENTS[getQualifiedClassName(inType)] = events;
}
public function StrictEvent(type:String)
{
var className:String = getQualifiedClassName(this);
if(VALID_EVENTS[className][type]) {
// init
} else {
throw new Error("Error! " + type);
}
}
}
Then, you could define your custom event class by extending the strict event class and calling initEvents in the static initializer. Here is your example with this method:
public class CustomEvent extends StrictEvent
{
public static const DISAPPEAR_COMPLETELY:String = "disappearCompletely";
public static const SIT_DOWN:String = "sitDown";
public static const STAND_UP:String = "standUp";
public static const SAIL_TO_THE_MOON:String = "sailToTheMoon";
public static const GO_TO_SLEEP:String = "goToSleep";
public static const GO_SLOWLY:String = "goSlowly";
public function CustomEvent(type:String) {
super(type);
}
{
initEvents(CustomEvent);
}
}
Now, each time it creates an event it only has to look up the event object and see if the type is in that object. It also means you don't have to manually add all the constants in the initializer.