<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	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/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>WebDeely &#187; cs4</title>
	<atom:link href="http://blog.webdeely.com/tag/cs4/feed/" rel="self" type="application/rss+xml" />
	<link>http://blog.webdeely.com</link>
	<description></description>
	<lastBuildDate>Thu, 18 Feb 2010 14:55:39 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0</generator>
		<item>
		<title>CS4 doesn&#8217;t like the combo of internal classes and interfaces in AS3</title>
		<link>http://blog.webdeely.com/2009/02/cs4-doesnt-like-the-combo-of-internal-classes-and-interfaces-in-as3/</link>
		<comments>http://blog.webdeely.com/2009/02/cs4-doesnt-like-the-combo-of-internal-classes-and-interfaces-in-as3/#comments</comments>
		<pubDate>Mon, 23 Feb 2009 01:51:54 +0000</pubDate>
		<dc:creator>Chris Deely</dc:creator>
				<category><![CDATA[Flash]]></category>
		<category><![CDATA[as3]]></category>
		<category><![CDATA[cs4]]></category>

		<guid isPermaLink="false">http://blog.webdeely.com/?p=5</guid>
		<description><![CDATA[Just prior to the public release of CS4, I had to spend some time at work testing how our API would install into the new Flash IDE.  Aside from some MXP file funkiness (which I may cover later) I encountered some very strange compiler errors.  Specifically, the compiler complained about many classes that implemented interfaces: [...]]]></description>
			<content:encoded><![CDATA[<p>Just prior to the public release of CS4, I had to spend some time at work testing how our API would install into the new Flash IDE.  Aside from some MXP file funkiness (which I may cover later) I encountered some very strange compiler errors.  Specifically, the compiler complained about many classes that implemented interfaces:</p>
<pre>1044: Interface method foo in namespace IFoo not implemented by class MyClass.</pre>
<p>Now, I knew for a fact that all of the interfaces were implemented properly and all of the classes compiled properly in Flash CS3 (and Flex 2 &amp; 3).  Nevertheless, we rechecked all the code over and over.</p>
<p>The startling realization was that all of the classes effected were Singletons!  The Singleton pattern I generally use is the one from the excellent &#8220;<a href="http://www.amazon.com/Advanced-ActionScript-3-Design-Patterns/dp/0321426568/ref=sr_1_1?ie=UTF8&amp;s=books&amp;qid=1235349753&amp;sr=8-1" target="_blank">Advanced ActionScript 3 with Design Patterns</a>&#8221; b<span class="addmd">y Joey Lott, Danny Patterson.  The gist of the pattern is that it makes use of a second class declared inside the main class&#8217; AS file.  Non-public classes are accessible only to the main class of the file, and not anywhere else in your package.  (<a href="http://books.google.com/books?id=DT7INNE3ui8C&amp;pg=PA69&amp;dq=joey+lott+singleton#PPA70,M1" target="_blank">You can see the relevant pages here</a>.)</span></p>
<p>Here is some code to illustrate the setup in use:</p>
<p>First, the main class, which implements IFoo and uses the Singleton Pattern</p>
<div class="codecolorer-container actionscript3 default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;height:300px;"><div class="actionscript3 codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #9900cc; font-weight: bold;">package</span><br />
<span style="color: #000000;">&#123;</span><br />
&nbsp; &nbsp; <span style="color: #0033ff; font-weight: bold;">public</span> <span style="color: #9900cc; font-weight: bold;">class</span> MyClass implements IFoo <span style="color: #000000;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009966; font-style: italic;">/** Singleton object */</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; static <span style="color: #0033ff; font-weight: bold;">private</span> <span style="color: #6699cc; font-weight: bold;">var</span> _instance<span style="color: #000066; font-weight: bold;">:</span>MyClass<span style="color: #000066; font-weight: bold;">;</span><br />
<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #3f5fbf;">/** The constructor will throw an error if you do not <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; pass a SingletonEnforcer instance */</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0033ff; font-weight: bold;">public</span> <span style="color: #339966; font-weight: bold;">function</span> MyClass<span style="color: #000000;">&#40;</span>s<span style="color: #000066; font-weight: bold;">:</span>SingletonEnforcer<span style="color: #000000;">&#41;</span><span style="color: #000000;">&#123;</span> &nbsp; <span style="color: #000000;">&#125;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009966; font-style: italic;">/** Method to retrieve an instance. */</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0033ff; font-weight: bold;">public</span> static <span style="color: #339966; font-weight: bold;">function</span> getInstance<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">:</span>MyClass<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0033ff; font-weight: bold;">if</span> <span style="color: #000000;">&#40;</span><span style="color: #000066; font-weight: bold;">!</span>_instance<span style="color: #000000;">&#41;</span> _instance = <span style="color: #0033ff; font-weight: bold;">new</span> MyClass<span style="color: #000000;">&#40;</span> <span style="color: #0033ff; font-weight: bold;">new</span> SingletonEnforcer<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span> <span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0033ff; font-weight: bold;">return</span> _instance<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000;">&#125;</span><br />
&nbsp; <br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009966; font-style: italic;">/** Function required by IFoo interface */</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0033ff; font-weight: bold;">public</span> <span style="color: #339966; font-weight: bold;">function</span> foo<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">:</span><span style="color: #0033ff; font-weight: bold;">void</span> <span style="color: #000000;">&#123;</span><span style="color: #000000;">&#125;</span><br />
&nbsp; &nbsp; <span style="color: #000000;">&#125;</span><br />
<span style="color: #000000;">&#125;</span><br />
<br />
<span style="color: #009966; font-style: italic;">/** The enforcer class cannot be accessed outside this .as file */</span><br />
<span style="color: #9900cc; font-weight: bold;">class</span> SingletonEnforcer <span style="color: #000000;">&#123;</span><span style="color: #000000;">&#125;</span></div></div>
<p> <br />
And, here is the definition of IFoo:</p>
<div class="codecolorer-container actionscript3 default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="actionscript3 codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #9900cc; font-weight: bold;">package</span><br />
<span style="color: #000000;">&#123;</span><br />
&nbsp; &nbsp; <span style="color: #009966; font-style: italic;">/** A simple interface */</span><br />
&nbsp; &nbsp; <span style="color: #0033ff; font-weight: bold;">public</span> interface IFoo <span style="color: #000000;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #339966; font-weight: bold;">function</span> foo<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">:</span><span style="color: #0033ff; font-weight: bold;">void</span><br />
&nbsp; &nbsp; <span style="color: #000000;">&#125;</span><br />
<span style="color: #000000;">&#125;</span></div></div>
<p>Easy enough, right?  The method <strong>foo()</strong> is obviously implemented in the class.  But as it turns out, CS4&#8242;s compiler doesn&#8217;t agree.</p>
<p>Once we discovered that the combination of the interface and the Singleton pattern was to blame, we started looking at all of the Singletons in the API.  By a stroke of luck, we found one that did NOT generate the compiler error.  The difference in that class was that it implemented TWO interfaces!</p>
<p>Bizarre as it seems, adding a second interface to the scheme above fixes the issue, and CS4 compiles the code without further issue.  We decided to add an empty ISingleton interface which was then used to correct the issue wherever it cropped up.</p>
<div class="codecolorer-container actionscript3 default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="actionscript3 codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #9900cc; font-weight: bold;">package</span><br />
<span style="color: #000000;">&#123;</span><br />
&nbsp; &nbsp; <span style="color: #0033ff; font-weight: bold;">public</span> <span style="color: #9900cc; font-weight: bold;">class</span> MyClass implements IFoo<span style="color: #000066; font-weight: bold;">,</span> ISingleton <span style="color: #000000;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009966; font-style: italic;">/** yadda yadda */</span><br />
&nbsp; &nbsp; <span style="color: #000000;">&#125;</span><br />
<span style="color: #000000;">&#125;</span></div></div>
<div class="codecolorer-container actionscript3 default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="actionscript3 codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #9900cc; font-weight: bold;">package</span><span style="color: #000000;">&#123;</span><br />
&nbsp; &nbsp; &nbsp;<span style="color: #009966; font-style: italic;">/** Add an empty interface to fix the issue */</span><br />
&nbsp; &nbsp; <span style="color: #0033ff; font-weight: bold;">public</span> interface ISingleton <span style="color: #000000;">&#123;</span><span style="color: #000000;">&#125;</span><br />
<span style="color: #000000;">&#125;</span></div></div>
<p>Many thanks to Tim O&#8217;Hare for his help in diagnosing and fixing the issue.</p>
<p>Feel free to <a href="http://blog.webdeely.com/wp-content/uploads/2009/02/cs4-singletons-with-interface.zip">download the source files</a> referenced here.</p>
<p>UPDATE: There is an <a href="https://bugs.adobe.com/jira/browse/ASC-3588">ActionScript compiler bug logged for this issue</a>.  It is marked as Closed and transferred to the main bugbase, so hopefully it will be addressed.</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.webdeely.com/2009/02/cs4-doesnt-like-the-combo-of-internal-classes-and-interfaces-in-as3/feed/</wfw:commentRss>
		<slash:comments>7</slash:comments>
		</item>
	</channel>
</rss>
