Skip to content

Instantly share code, notes, and snippets.

@DavidArno
Created January 31, 2012 11:00
Show Gist options
  • Save DavidArno/1709906 to your computer and use it in GitHub Desktop.
Save DavidArno/1709906 to your computer and use it in GitHub Desktop.
AS3 enum example
Enum base class:
package language.extensions.enums
{
public class EnumBase
{
function EnumBase(token:*)
{
if (token !== runtimeInstantiationPreventionKey)
{
throw new Error("Cannot create new enums at runtime.");
}
}
static protected function key():*
{
return runtimeInstantiationPreventionKey;
}
}
}
const runtimeInstantiationPreventionKey:* = {};
And a typical enum would be:
package ...
{
public final class TrafficLights extends EnumBase
{
public static const Red:TrafficLights = new TrafficLights(key);
public static const Amber:TrafficLights = new TrafficLights(key);
public static const Green:TrafficLights = new TrafficLights(key);
function TrafficLights(key:*)
{
super(key);
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment