<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
		>
<channel>
	<title>Comments on: Ultimate AS3 Fake Enums</title>
	<atom:link href="http://scottbilas.com/blog/ultimate-as3-fake-enums/feed/" rel="self" type="application/rss+xml" />
	<link>http://scottbilas.com/blog/ultimate-as3-fake-enums/</link>
	<description>Take what you want, and leave the rest (just like your salad bar).</description>
	<lastBuildDate>Mon, 06 Feb 2012 03:15:56 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.9.2</generator>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
		<item>
		<title>By: Ryan</title>
		<link>http://scottbilas.com/blog/ultimate-as3-fake-enums/#comment-1689</link>
		<dc:creator>Ryan</dc:creator>
		<pubDate>Mon, 23 Jan 2012 18:55:38 +0000</pubDate>
		<guid isPermaLink="false">http://scottbilas.com/?p=351#comment-1689</guid>
		<description>Hey Scott -- pretty nice thorough implementation. I like the fact that you included the ability to use the ParseConstant command for setting values, including the ability to allow a different case passed to get the enum value. My only beef there is that often times one would like have a value like this:

public static const UPSIDE_DOWN:Orientation = new Orientation();

However, if this is a client app getting data from the server, the server value might be the camelcase version of the value, i.e. &quot;upsideDown&quot;, instead of a lowercase underscore delimited version. I don&#039;t know if that is a pretty rare case for folks, but I thought I&#039;d note it and say that it could be worked around by changing the &quot;toLowerCase() in the EnumConstants constructor and in the ParseConstants function to something like &quot;toLowerCase().replace(/_/gi, &quot;&quot;)&quot;. 

Thanks again!</description>
		<content:encoded><![CDATA[<p>Hey Scott &#8212; pretty nice thorough implementation. I like the fact that you included the ability to use the ParseConstant command for setting values, including the ability to allow a different case passed to get the enum value. My only beef there is that often times one would like have a value like this:</p>
<p>public static const UPSIDE_DOWN:Orientation = new Orientation();</p>
<p>However, if this is a client app getting data from the server, the server value might be the camelcase version of the value, i.e. &#8220;upsideDown&#8221;, instead of a lowercase underscore delimited version. I don&#8217;t know if that is a pretty rare case for folks, but I thought I&#8217;d note it and say that it could be worked around by changing the &#8220;toLowerCase() in the EnumConstants constructor and in the ParseConstants function to something like &#8220;toLowerCase().replace(/_/gi, &#8220;&#8221;)&#8221;. </p>
<p>Thanks again!</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Damian</title>
		<link>http://scottbilas.com/blog/ultimate-as3-fake-enums/#comment-745</link>
		<dc:creator>Damian</dc:creator>
		<pubDate>Wed, 05 Jan 2011 12:04:59 +0000</pubDate>
		<guid isPermaLink="false">http://scottbilas.com/?p=351#comment-745</guid>
		<description>Ha, ignore that last message, I&#039;m being an idiot - the problem comes from the &quot;var s:State = new State&quot; code in the test file.</description>
		<content:encoded><![CDATA[<p>Ha, ignore that last message, I&#8217;m being an idiot &#8211; the problem comes from the &#8220;var s:State = new State&#8221; code in the test file.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Damian</title>
		<link>http://scottbilas.com/blog/ultimate-as3-fake-enums/#comment-744</link>
		<dc:creator>Damian</dc:creator>
		<pubDate>Wed, 05 Jan 2011 11:54:30 +0000</pubDate>
		<guid isPermaLink="false">http://scottbilas.com/?p=351#comment-744</guid>
		<description>Has the initialisation order in Flash changed? When I create a new enum based of the Enum class (say State), it calls the Enum constructor before calling the State static constructor, and hence fails.

E.g.:
[code]
package  
{
	import flash.display.Sprite;
	
	public class TestOrder extends Sprite
	{
		
		public function TestOrder() 
		{
			trace( &quot;--- creating State&quot; );
			var s:State = new State;
			trace( &quot;--- finished creating State&quot; );
		}
		
	}

}

// shortened enum class
class Enum
{
	protected static function init():void
	{
		trace( &quot;Init function on enum&quot; );
	}
	
	public function Enum()
	{
		trace( &quot;Constructor for Enum&quot; );
	}
}

// the enum that we&#039;re creating
class State extends Enum
{
	{
		trace( &quot;Static constructor for State&quot; );
		init();
	}
	
	public static const BLAH:State = new State;
}
[/code]

Here, my trace is:

Constructor for Enum
Static constructor for State
Init function on enum
--- creating State
Constructor for Enum
--- finished creating State

Where the &quot;Static constructor for State&quot; should be before &quot;Constructor for Enum&quot; for your code to work or it fails on the error &quot;Enum constants can only be constructed as static consts...&quot;.

Is this how it works your end as well, or am I missing something basic?

I think I&#039;m going to have to split out the Enum constructor code to an init function.

In any case, thanks for the excellent class!</description>
		<content:encoded><![CDATA[<p>Has the initialisation order in Flash changed? When I create a new enum based of the Enum class (say State), it calls the Enum constructor before calling the State static constructor, and hence fails.</p>
<p>E.g.:</p>
<pre class="brush: plain;">
package
{
	import flash.display.Sprite;

	public class TestOrder extends Sprite
	{

		public function TestOrder()
		{
			trace( &quot;--- creating State&quot; );
			var s:State = new State;
			trace( &quot;--- finished creating State&quot; );
		}

	}

}

// shortened enum class
class Enum
{
	protected static function init():void
	{
		trace( &quot;Init function on enum&quot; );
	}

	public function Enum()
	{
		trace( &quot;Constructor for Enum&quot; );
	}
}

// the enum that we're creating
class State extends Enum
{
	{
		trace( &quot;Static constructor for State&quot; );
		init();
	}

	public static const BLAH:State = new State;
}
</pre>
<p>Here, my trace is:</p>
<p>Constructor for Enum<br />
Static constructor for State<br />
Init function on enum<br />
&#8212; creating State<br />
Constructor for Enum<br />
&#8212; finished creating State</p>
<p>Where the &#8220;Static constructor for State&#8221; should be before &#8220;Constructor for Enum&#8221; for your code to work or it fails on the error &#8220;Enum constants can only be constructed as static consts&#8230;&#8221;.</p>
<p>Is this how it works your end as well, or am I missing something basic?</p>
<p>I think I&#8217;m going to have to split out the Enum constructor code to an init function.</p>
<p>In any case, thanks for the excellent class!</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: The paperCrane&#8217;s view from the reverseFold &#187; Java-style Typesafe Enumerations in AS3</title>
		<link>http://scottbilas.com/blog/ultimate-as3-fake-enums/#comment-735</link>
		<dc:creator>The paperCrane&#8217;s view from the reverseFold &#187; Java-style Typesafe Enumerations in AS3</dc:creator>
		<pubDate>Thu, 23 Dec 2010 04:33:42 +0000</pubDate>
		<guid isPermaLink="false">http://scottbilas.com/?p=351#comment-735</guid>
		<description>[...] of Java code which use Java&#8217;s robust enumerations. This has been discussed elsewhere quite a bit so I&#8217;ll just do a quick recap and then give my new updated [...]</description>
		<content:encoded><![CDATA[<p>[...] of Java code which use Java&#8217;s robust enumerations. This has been discussed elsewhere quite a bit so I&#8217;ll just do a quick recap and then give my new updated [...]</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: John Willemse</title>
		<link>http://scottbilas.com/blog/ultimate-as3-fake-enums/#comment-666</link>
		<dc:creator>John Willemse</dc:creator>
		<pubDate>Tue, 14 Sep 2010 15:54:18 +0000</pubDate>
		<guid isPermaLink="false">http://scottbilas.com/?p=351#comment-666</guid>
		<description>Thanks a lot for this superb code! I&#039;ve been looking for a type-safe implementation for a while ;-) I love it!</description>
		<content:encoded><![CDATA[<p>Thanks a lot for this superb code! I&#8217;ve been looking for a type-safe implementation for a while <img src='http://scottbilas.com/wp-includes/images/smilies/icon_wink.gif' alt=';-)' class='wp-smiley' />  I love it!</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Joost</title>
		<link>http://scottbilas.com/blog/ultimate-as3-fake-enums/#comment-553</link>
		<dc:creator>Joost</dc:creator>
		<pubDate>Thu, 01 Jul 2010 13:47:07 +0000</pubDate>
		<guid isPermaLink="false">http://scottbilas.com/?p=351#comment-553</guid>
		<description>Thanks for your reply. I&#039;ve added an import statement to the private support class and now it works.

[code]
package my.package.enum
{
  public class Enum
  {
    ...
  }
}

class EnumConstants
{
  import my.package.enum.Enum; /* this fixed my problem */

  ...
}
[/code]

BTW: I&#039;m using Flash Builder 4.0 with the Flex SDK 4 (and AS3 but that should not be a surprise).
I wonder why I had to add this import statement.

Thanks for this Enum class and examples. I really like it!</description>
		<content:encoded><![CDATA[<p>Thanks for your reply. I&#8217;ve added an import statement to the private support class and now it works.</p>
<pre class="brush: plain;">
package my.package.enum
{
  public class Enum
  {
    ...
  }
}

class EnumConstants
{
  import my.package.enum.Enum; /* this fixed my problem */

  ...
}
</pre>
<p>BTW: I&#8217;m using Flash Builder 4.0 with the Flex SDK 4 (and AS3 but that should not be a surprise).<br />
I wonder why I had to add this import statement.</p>
<p>Thanks for this Enum class and examples. I really like it!</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Scott</title>
		<link>http://scottbilas.com/blog/ultimate-as3-fake-enums/#comment-547</link>
		<dc:creator>Scott</dc:creator>
		<pubDate>Mon, 28 Jun 2010 03:58:55 +0000</pubDate>
		<guid isPermaLink="false">http://scottbilas.com/?p=351#comment-547</guid>
		<description>Couple possibilities I can think of - either your package needs importing, or you&#039;re using an old Actionscript that does not support static typing.</description>
		<content:encoded><![CDATA[<p>Couple possibilities I can think of &#8211; either your package needs importing, or you&#8217;re using an old Actionscript that does not support static typing.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Joost</title>
		<link>http://scottbilas.com/blog/ultimate-as3-fake-enums/#comment-540</link>
		<dc:creator>Joost</dc:creator>
		<pubDate>Fri, 25 Jun 2010 08:47:48 +0000</pubDate>
		<guid isPermaLink="false">http://scottbilas.com/?p=351#comment-540</guid>
		<description>If I place the Enum class in a package, I get a compile error on the line &quot;var enumConstant :Enum = ByIndex[i];&quot; in the EnumConstants class, saying:

Type was not found or was not a compile-time constant: Enum.

Any idea?</description>
		<content:encoded><![CDATA[<p>If I place the Enum class in a package, I get a compile error on the line &#8220;var enumConstant :Enum = ByIndex[i];&#8221; in the EnumConstants class, saying:</p>
<p>Type was not found or was not a compile-time constant: Enum.</p>
<p>Any idea?</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: AS3 Lecks - Flashforum</title>
		<link>http://scottbilas.com/blog/ultimate-as3-fake-enums/#comment-494</link>
		<dc:creator>AS3 Lecks - Flashforum</dc:creator>
		<pubDate>Thu, 06 May 2010 10:28:09 +0000</pubDate>
		<guid isPermaLink="false">http://scottbilas.com/?p=351#comment-494</guid>
		<description>[...]  [...]</description>
		<content:encoded><![CDATA[<p>[...]  [...]</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Scott</title>
		<link>http://scottbilas.com/blog/ultimate-as3-fake-enums/#comment-337</link>
		<dc:creator>Scott</dc:creator>
		<pubDate>Sat, 26 Dec 2009 22:40:06 +0000</pubDate>
		<guid isPermaLink="false">http://scottbilas.com/?p=351#comment-337</guid>
		<description>Thanks for the feedback.

I think that minimizing class name usage within the enum class is a good idea, in order to reduce copy-paste error. Perhaps it would be better to have a

[as3]
private static const _enumType :Class = ThisEnumClassName; 
[/as3]

...and then reference that from functions like GetConstants as well as the original initEnum() call. Note that I haven&#039;t tried this out, but if it compiles, it&#039;s probably a good way to reduce copy-paste errors.

The problem I have with a helper class is that it&#039;s still necessarily generic, and so you lose the type safety you get with NetError.ParseConstant. You could inherit from the helper class to provide type-specific behavior but then it&#039;s back to having the classname in multiple places.</description>
		<content:encoded><![CDATA[<p>Thanks for the feedback.</p>
<p>I think that minimizing class name usage within the enum class is a good idea, in order to reduce copy-paste error. Perhaps it would be better to have a</p>
<pre class="brush: as3;">
private static const _enumType :Class = ThisEnumClassName;
</pre>
<p>&#8230;and then reference that from functions like GetConstants as well as the original initEnum() call. Note that I haven&#8217;t tried this out, but if it compiles, it&#8217;s probably a good way to reduce copy-paste errors.</p>
<p>The problem I have with a helper class is that it&#8217;s still necessarily generic, and so you lose the type safety you get with NetError.ParseConstant. You could inherit from the helper class to provide type-specific behavior but then it&#8217;s back to having the classname in multiple places.</p>
]]></content:encoded>
	</item>
</channel>
</rss>

