diff --git a/src/as/com/threerings/util/Enum.as b/src/as/com/threerings/util/Enum.as index b416f7f6e..f27fe2bb8 100644 --- a/src/as/com/threerings/util/Enum.as +++ b/src/as/com/threerings/util/Enum.as @@ -143,6 +143,18 @@ public class Enum return Integer.compare(this.ordinal(), Enum(other).ordinal()); } + /** + * Return the Enum of the given class with the given ordinal value. + */ + public static function fromOrdinal (clazz :Class, ordinal :int) :Enum + { + var values :Array = (_enums[ClassUtil.getClass(clazz)] as Array); + if (values != null && ordinal >= 0 && ordinal < values.length) { + return values[ordinal]; + } + throw new ArgumentError("No such enum [class=" + clazz + ", ordinal=" + ordinal + "]."); + } + /** * Turn a String name into an Enum constant. */ @@ -181,7 +193,7 @@ public class Enum protected var _name :String; /** An array of enums for each enum class. */ - private static const _enums :Dictionary = new Dictionary(true); + private static const _enums :Dictionary = new Dictionary(true); /** Is further instantiation of enum constants for a class allowed? */ private static const _blocked :Dictionary = new Dictionary(true);