Fake Enums in AS3


package
{
	final public class TargetPlatform
	{
		public static const APPLE_IPA:TargetPlatform = new TargetPlatform("ipa");
		public static const ANDROID_APK:TargetPlatform = new TargetPlatform("apk");
		public static const WINDOWS_AIR:TargetPlatform = new TargetPlatform("air");
		
		private var _value:String;
		
		public function TargetPlatform(value:String)
		{
			_value = value;
		}
		
		public function toString():String
		{
			return _value;
		}	
	}
}
Advertisements

One thought on “Fake Enums in AS3

  1. You need some sort of lock on the constructor to stop anybody created instances of the enum outside of the class. Easiest way is to have a package base class defined inside this file, and have that as a required param in the constructor.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s