<?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</title>
	<atom:link href="http://blog.webdeely.com/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>
	<generator>http://wordpress.org/?v=2.9.1</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>Flash IDE code hints for TweenLite &#8211; built with CSDoc!</title>
		<link>http://blog.webdeely.com/2010/02/flash-ide-code-hints-for-tweenlite-built-with-csdoc/</link>
		<comments>http://blog.webdeely.com/2010/02/flash-ide-code-hints-for-tweenlite-built-with-csdoc/#comments</comments>
		<pubDate>Thu, 18 Feb 2010 14:55:39 +0000</pubDate>
		<dc:creator>Chris Deely</dc:creator>
				<category><![CDATA[AIR]]></category>
		<category><![CDATA[Flash]]></category>
		<category><![CDATA[ASDoc]]></category>
		<category><![CDATA[CSDoc]]></category>

		<guid isPermaLink="false">http://blog.webdeely.com/?p=65</guid>
		<description><![CDATA[Flash IDE code hints for TweenLite built using CSDoc]]></description>
			<content:encoded><![CDATA[<p>In my last post I released my new <a title="CSDoc" href="http://blog.webdeely.com/2010/01/csdoc-create-flash-cs3-cs4-code-hints-using-asdoc/" target="_self">AIR app CSDoc for generating Flash IDE code hints</a> from ASDoc comments.  The app is very useful for people that create AS3 libraries, but it can also be employed by the end user.  Any library that is released with source code can be processed by ASDoc, and subsequently converted into code hints using CSDoc.</p>
<p>As an example, I have run CSDoc against the popular TweenLite/TweenMax animation package developed by Jack Doyle at <a title="GreenSock TweenLite" href="http://www.greensock.com" target="_blank">http://www.greensock.com</a>.   You can download the resulting Flash extension here (<a title="TweenLite Code Hints MXP" href="http://blog.webdeely.com/CSDoc/packages/TweenLite_Code_Hints.mxp" target="_blank">MXP</a>).</p>
<p>To generate this package, I followed these steps:</p>
<ol>
<li>Downloaded the library source</li>
<li>Ran asdoc on the package with the &#8220;-keep-xml&#8221; flag (I highly recommend <a title="Grant Skinner's ASDocr" href="http://www.gskinner.com/blog/archives/2010/01/asdocr_simple_a.html" target="_blank">Grant Skinner&#8217;s ASDocr</a> for this task) <strong>***Use Flex SDK 3.4 or LOWER***</strong></li>
<li>Ran CSDoc on the resulting toplevel_classes.xml file</li>
<li>Packaged the resulting files into an MXP using the Adobe Extension Manager</li>
</ol>
<p>That&#8217;s it!  This should work on any open source AS3 library, provided you have the appropriate supporting libs available.</p>
<p>Please let me know if you find this extension useful or if you&#8217;d like to see packages made for any other popular libraries.</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.webdeely.com/2010/02/flash-ide-code-hints-for-tweenlite-built-with-csdoc/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>CSDoc &#8211; Create Flash CS3 &amp; CS4 code hints using ASDoc</title>
		<link>http://blog.webdeely.com/2010/01/csdoc-create-flash-cs3-cs4-code-hints-using-asdoc/</link>
		<comments>http://blog.webdeely.com/2010/01/csdoc-create-flash-cs3-cs4-code-hints-using-asdoc/#comments</comments>
		<pubDate>Wed, 13 Jan 2010 14:38:52 +0000</pubDate>
		<dc:creator>Chris Deely</dc:creator>
				<category><![CDATA[AIR]]></category>
		<category><![CDATA[Flash]]></category>

		<guid isPermaLink="false">http://blog.webdeely.com/?p=55</guid>
		<description><![CDATA[For the past few years I have been managing a sizable Flash API that is distributed to clients via an Adobe extension (MXP).  Managing the compilation of the MXP file is a headache on its own (and worthy of a separate post).  In addition, there is little to no documentation on building an [...]]]></description>
			<content:encoded><![CDATA[<p>For the past few years I have been managing a sizable Flash API that is distributed to clients via an Adobe extension (MXP).  Managing the compilation of the MXP file is a headache on its own (and worthy of a separate post).  In addition, there is little to no documentation on building an extension that integrates nicely with the Flash IDE.</p>
<p>Sure, you can get your class files to install into the IDE&#8217;s class path, but what about adding code hinting and highlighting?  I have not found many reliable resources on this topic, and everything I&#8217;ve learned has been by digging into the guts of the installed IDE files.</p>
<p>So, long story short, I&#8217;ve developed an AIR app that will use ASDoc to analyze your AS3 API and generate the files needed to add code hints within the Flash IDE.</p>
<p>The application, CSDoc, can be installed from the badge below.  It is extremely simple (read: ugly) but gets the job done.  Just follow the steps below to get the required XML docs for addition to your MXP:</p>
<p><strong>Note: </strong>You do not have to actually use ASDoc comments in your code, but it is recommended.</p>
<ol>
<li>Run ASDoc on your project with the added argument: -keep-xml</li>
<li>Use the &#8220;Browse&#8221; button to locate the toplevel_classes.xml file created by ASDoc</li>
<li>Review the XML generated (if you really care&#8230;)</li>
<li>Export the XML files to disk (I recommend keeping them in a directory with your project) and include them in your MXP</li>
</ol>
<p>Please let me know in the comments if you find this useful or have any problems.</p>

    <object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" id="swfobj_0" width="217" height="180">
      <param name="movie" value="http://blog.webdeely.com/CSDoc/badge.swf" />
      <param name="flashvars" value="appname=CSDoc&amp;appurl=http://blog.webdeely.com/CSDoc/CSDoc.air&amp;airversion=1.5.3&amp;imageurl=http://blog.webdeely.com/CSDoc/csdoc_badge.png" />
      <!--[if !IE]>-->
      <object type="application/x-shockwave-flash" data="http://blog.webdeely.com/CSDoc/badge.swf" width="217" height="180" flashvars="appname=CSDoc&amp;appurl=http://blog.webdeely.com/CSDoc/CSDoc.air&amp;airversion=1.5.3&amp;imageurl=http://blog.webdeely.com/CSDoc/csdoc_badge.png">
      <!--<![endif]-->
        <p>The Flash plugin is required to view this object.</p>
      <!--[if !IE]>-->
      </object>
      <!--<![endif]-->
    </object>

<p>For anyone interested, this all started with a post by Rob Dixon, which is pretty outdated now:  <a title="Use ASDoc to Drive new Processes" href="http://rantworld.blogs.com/flashlit/2007/02/use_asdoc_to_dr.html" target="_blank">Use ASDoc to drive new processes</a></p>
]]></content:encoded>
			<wfw:commentRss>http://blog.webdeely.com/2010/01/csdoc-create-flash-cs3-cs4-code-hints-using-asdoc/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Great Article on UDP in AIR 2.0</title>
		<link>http://blog.webdeely.com/2009/11/great-article-on-udp-in-air-2-0/</link>
		<comments>http://blog.webdeely.com/2009/11/great-article-on-udp-in-air-2-0/#comments</comments>
		<pubDate>Tue, 17 Nov 2009 17:16:50 +0000</pubDate>
		<dc:creator>Chris Deely</dc:creator>
				<category><![CDATA[AIR]]></category>

		<guid isPermaLink="false">http://blog.webdeely.com/?p=51</guid>
		<description><![CDATA[Ian McLean has written a multi-part article on using the UDP protocol in AIR 2.0.  Interesting read, be sure to check it out: http://www.insideria.com/2009/11/udp-socket-connections-for-los-1.html
]]></description>
			<content:encoded><![CDATA[<p>Ian McLean has written a multi-part article on using the UDP protocol in AIR 2.0.  Interesting read, be sure to check it out: <a href="http://www.insideria.com/2009/11/udp-socket-connections-for-los-1.html">http://www.insideria.com/2009/11/udp-socket-connections-for-los-1.html</a></p>
]]></content:encoded>
			<wfw:commentRss>http://blog.webdeely.com/2009/11/great-article-on-udp-in-air-2-0/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>&#8220;Fixing&#8221; the FileSystemTree</title>
		<link>http://blog.webdeely.com/2009/07/fixing-the-filesystemtree/</link>
		<comments>http://blog.webdeely.com/2009/07/fixing-the-filesystemtree/#comments</comments>
		<pubDate>Fri, 24 Jul 2009 03:10:46 +0000</pubDate>
		<dc:creator>Chris Deely</dc:creator>
				<category><![CDATA[AIR]]></category>
		<category><![CDATA[Flex]]></category>

		<guid isPermaLink="false">http://blog.webdeely.com/?p=44</guid>
		<description><![CDATA[I recently ran into some painfully slow performance issues using the FileSystemTree to display file system contents in an AIR app.  It seemed that when accessing directories containing a large number of files, the app would simply hang for ages, never populating the tree.
This occurred most readily when accessing network drives.  I chased [...]]]></description>
			<content:encoded><![CDATA[<p>I recently ran into some painfully slow performance issues using the FileSystemTree to display file system contents in an AIR app.  It seemed that when accessing directories containing a large number of files, the app would simply hang for ages, never populating the tree.</p>
<p>This occurred most readily when accessing network drives.  I chased the issue down a number of avenues, including looking at &#8220;funky&#8221; file types and network speed.  Nothing pointed me in the right direction.</p>
<p>Finally, I spent some time placing breakpoints directly into the FileSystemTree class and dug into the guts to find the answer.  As I stepped through the code, I found that the file records for the large directory in question were returned from the OS almost instantaneously.  This was not what I expected to find, but it was great news, as it meant the processing delay was somewhere inside the Flex SDK or my own code.</p>
<p>Sure enough, there is some code in the FileSystemTree class that significantly slows down the processing of large directories.  After loading the raw directory listing from the AIR framework, the child items are processed through the following function:</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">&nbsp;mx_internal <span style="color: #339966; font-weight: bold;">function</span> insertChildItems<span style="color: #000000;">&#40;</span>subdirectory<span style="color: #000066; font-weight: bold;">:</span>File<span style="color: #000066; font-weight: bold;">,</span> childItems<span style="color: #000066; font-weight: bold;">:</span><a href="http://www.google.com/search?q=array%20inurl:http://livedocs.adobe.com/flex/201/langref/%20inurl:array.html"><span style="color: #004993;">Array</span></a><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;<span style="color: #000000;">&#123;</span><br />
&nbsp; &nbsp; <span style="color: #6699cc; font-weight: bold;">var</span> childCollection<span style="color: #000066; font-weight: bold;">:</span>ArrayCollection = <span style="color: #0033ff; font-weight: bold;">new</span> ArrayCollection<span style="color: #000000;">&#40;</span>childItems<span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <br />
&nbsp; &nbsp; childCollection<span style="color: #000066; font-weight: bold;">.</span>filterFunction =<br />
&nbsp; &nbsp; &nbsp; &nbsp; helper<span style="color: #000066; font-weight: bold;">.</span>directoryEnumeration<span style="color: #000066; font-weight: bold;">.</span>fileFilterFunction<span style="color: #000066; font-weight: bold;">;</span><br />
&nbsp; &nbsp; childCollection<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">sort</span> = <span style="color: #0033ff; font-weight: bold;">new</span> Sort<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span><br />
&nbsp; &nbsp; childCollection<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">sort</span><span style="color: #000066; font-weight: bold;">.</span>compareFunction =<br />
&nbsp; &nbsp; &nbsp; &nbsp; helper<span style="color: #000066; font-weight: bold;">.</span>directoryEnumeration<span style="color: #000066; font-weight: bold;">.</span>fileCompareFunction<span style="color: #000066; font-weight: bold;">;</span><br />
&nbsp; &nbsp; childCollection<span style="color: #000066; font-weight: bold;">.</span>refresh<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span><br />
<br />
&nbsp; &nbsp; FileSystemTreeDataDescriptor<span style="color: #000000;">&#40;</span>dataDescriptor<span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">setChildren</span><span style="color: #000000;">&#40;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; subdirectory<span style="color: #000066; font-weight: bold;">,</span> childCollection<span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span><br />
<br />
&nbsp; &nbsp; expandItem<span style="color: #000000;">&#40;</span>subdirectory<span style="color: #000066; font-weight: bold;">,</span> <span style="color: #0033ff; font-weight: bold;">true</span><span style="color: #000066; font-weight: bold;">,</span> <span style="color: #0033ff; font-weight: bold;">true</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span><br />
<br />
&nbsp; &nbsp; helper<span style="color: #000066; font-weight: bold;">.</span>itemsChanged<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span><br />
<span style="color: #000000;">&#125;</span></div></div>
<p>The problem here is that the file records returned from the OS are now filtered and sorted before populating the Tree.  This is fine for relatively small sets of data, but when dealing with large directories (1600+ files in my case) it grinds to a halt.</p>
<p>The only way I have found to improve the performance of this component is to prevent the filtering and sorting from taking place for large directories.  I extended the FileSystemTree (source attached) and overrode the insertChildItems function.</p>
<p>The full class is below:</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> com<span style="color: #000066; font-weight: bold;">.</span>webdeely<span style="color: #000066; font-weight: bold;">.</span>file<br />
<span style="color: #000000;">&#123;</span><br />
&nbsp; &nbsp; <span style="color: #0033ff; font-weight: bold;">import</span> flash<span style="color: #000066; font-weight: bold;">.</span>filesystem<span style="color: #000066; font-weight: bold;">.</span>File<span style="color: #000066; font-weight: bold;">;</span><br />
&nbsp; &nbsp; <br />
&nbsp; &nbsp; <span style="color: #0033ff; font-weight: bold;">import</span> mx<span style="color: #000066; font-weight: bold;">.</span>collections<span style="color: #000066; font-weight: bold;">.</span>ArrayCollection<span style="color: #000066; font-weight: bold;">;</span><br />
&nbsp; &nbsp; <span style="color: #0033ff; font-weight: bold;">import</span> mx<span style="color: #000066; font-weight: bold;">.</span>collections<span style="color: #000066; font-weight: bold;">.</span>Sort<span style="color: #000066; font-weight: bold;">;</span><br />
&nbsp; &nbsp; <span style="color: #0033ff; font-weight: bold;">import</span> mx<span style="color: #000066; font-weight: bold;">.</span>controls<span style="color: #000066; font-weight: bold;">.</span>FileSystemTree<span style="color: #000066; font-weight: bold;">;</span><br />
&nbsp; &nbsp; <span style="color: #0033ff; font-weight: bold;">import</span> mx<span style="color: #000066; font-weight: bold;">.</span>controls<span style="color: #000066; font-weight: bold;">.</span>fileSystemClasses<span style="color: #000066; font-weight: bold;">.</span>FileSystemTreeDataDescriptor<span style="color: #000066; font-weight: bold;">;</span><br />
&nbsp; &nbsp; <span style="color: #0033ff; font-weight: bold;">import</span> mx<span style="color: #000066; font-weight: bold;">.</span>core<span style="color: #000066; font-weight: bold;">.</span>mx_internal<span style="color: #000066; font-weight: bold;">;</span><br />
&nbsp; &nbsp; <span style="color: #0033ff; font-weight: bold;">import</span> mx<span style="color: #000066; font-weight: bold;">.</span>utils<span style="color: #000066; font-weight: bold;">.</span>DirectoryEnumerationMode<span style="color: #000066; font-weight: bold;">;</span><br />
<br />
&nbsp; &nbsp; use <span style="color: #004993;">namespace</span> mx_internal<span style="color: #000066; font-weight: bold;">;</span><br />
&nbsp; &nbsp; <br />
&nbsp; &nbsp; <span style="color: #3f5fbf;">/**<br />
&nbsp; &nbsp; * This class overrides the AIR FileSystemTree class' insertChildItems to prevent sorting of directory contents when <br />
&nbsp; &nbsp; * there are a great number of children in the folder. This is far from perfect, as the children may be listed randomly,<br />
&nbsp; &nbsp; * however it is better than the default behavior where the app chokes.<br />
&nbsp; &nbsp; **/</span><br />
&nbsp; &nbsp; <br />
&nbsp; &nbsp; <span style="color: #0033ff; font-weight: bold;">public</span> <span style="color: #9900cc; font-weight: bold;">class</span> FastFileSystemTree <span style="color: #0033ff; font-weight: bold;">extends</span> FileSystemTree<br />
&nbsp; &nbsp; <span style="color: #000000;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #3f5fbf;">/** Adjust this number to set an acceptable threshold for sorted/unsorted children **/</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0033ff; font-weight: bold;">public</span> <span style="color: #6699cc; font-weight: bold;">var</span> largeDirectoryThreshold<span style="color: #000066; font-weight: bold;">:</span><a href="http://www.google.com/search?q=number%20inurl:http://livedocs.adobe.com/flex/201/langref/%20inurl:number.html"><span style="color: #004993;">Number</span></a> = <span style="color: #000000; font-weight:bold;">500</span><span style="color: #000066; font-weight: bold;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0033ff; font-weight: bold;">public</span> <span style="color: #339966; font-weight: bold;">function</span> FileSystemTreeAsync<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><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;">super</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000;">&#125;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <br />
&nbsp; &nbsp; &nbsp; &nbsp; override mx_internal <span style="color: #339966; font-weight: bold;">function</span> insertChildItems<span style="color: #000000;">&#40;</span>subdirectory<span style="color: #000066; font-weight: bold;">:</span>File<span style="color: #000066; font-weight: bold;">,</span> childItems<span style="color: #000066; font-weight: bold;">:</span><a href="http://www.google.com/search?q=array%20inurl:http://livedocs.adobe.com/flex/201/langref/%20inurl:array.html"><span style="color: #004993;">Array</span></a><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; &nbsp; &nbsp; <span style="color: #000000;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #6699cc; font-weight: bold;">var</span> childCollection<span style="color: #000066; font-weight: bold;">:</span>ArrayCollection = <span style="color: #0033ff; font-weight: bold;">new</span> ArrayCollection<span style="color: #000000;">&#40;</span>childItems<span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #3f5fbf;">/* This is the only change to the function. &nbsp;If this directory contains a large number of children, <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; just append them as they are listed from the OS, rather than filtering or sorting them. */</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0033ff; font-weight: bold;">if</span><span style="color: #000000;">&#40;</span> childCollection<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">length</span> <span style="color: #000066; font-weight: bold;">&lt;</span> largeDirectoryThreshold <span style="color: #000000;">&#41;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; childCollection<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">sort</span> = <span style="color: #0033ff; font-weight: bold;">new</span> Sort<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; childCollection<span style="color: #000066; font-weight: bold;">.</span>filterFunction = helper<span style="color: #000066; font-weight: bold;">.</span>directoryEnumeration<span style="color: #000066; font-weight: bold;">.</span>fileFilterFunction<span style="color: #000066; font-weight: bold;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; childCollection<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">sort</span><span style="color: #000066; font-weight: bold;">.</span>compareFunction = helper<span style="color: #000066; font-weight: bold;">.</span>directoryEnumeration<span style="color: #000066; font-weight: bold;">.</span>fileCompareFunction<span style="color: #000066; font-weight: bold;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; childCollection<span style="color: #000066; font-weight: bold;">.</span>refresh<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000;">&#125;</span><br />
&nbsp; &nbsp; <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; FileSystemTreeDataDescriptor<span style="color: #000000;">&#40;</span>dataDescriptor<span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">setChildren</span><span style="color: #000000;">&#40;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; subdirectory<span style="color: #000066; font-weight: bold;">,</span> childCollection<span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span><br />
&nbsp; &nbsp; <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; expandItem<span style="color: #000000;">&#40;</span>subdirectory<span style="color: #000066; font-weight: bold;">,</span> <span style="color: #0033ff; font-weight: bold;">true</span><span style="color: #000066; font-weight: bold;">,</span> <span style="color: #0033ff; font-weight: bold;">true</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span><br />
&nbsp; &nbsp; <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; helper<span style="color: #000066; font-weight: bold;">.</span>itemsChanged<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000;">&#125;</span><br />
&nbsp; &nbsp; <span style="color: #000000;">&#125;</span><br />
<span style="color: #000000;">&#125;</span></div></div>
<p>This is definitely not a great solution, as the contents of large directories may not appear in exactly the right order.  I&#8217;ve had mixed results.</p>
<p>The real issue is that this type of operation on large quantities of file references should really be executed within the AIR framework itself, and not by the AS3 components running on top of it.</p>
<p>I am very open to suggestions on how to approach a better solution, but for now this at least allows the user to access their files; albeit in possibly the wrong order.</p>
<p><a href='http://blog.webdeely.com/wp-content/uploads/2009/07/fastfilesystemtree.zip'>Get the class source</a></p>
]]></content:encoded>
			<wfw:commentRss>http://blog.webdeely.com/2009/07/fixing-the-filesystemtree/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Storing Custom AMF files for AIR Apps</title>
		<link>http://blog.webdeely.com/2009/03/storing-custom-strongly-typed-amf-files-for-air-apps/</link>
		<comments>http://blog.webdeely.com/2009/03/storing-custom-strongly-typed-amf-files-for-air-apps/#comments</comments>
		<pubDate>Tue, 31 Mar 2009 21:54:13 +0000</pubDate>
		<dc:creator>Chris Deely</dc:creator>
				<category><![CDATA[AIR]]></category>
		<category><![CDATA[Flash]]></category>
		<category><![CDATA[AMF]]></category>
		<category><![CDATA[SharedObject]]></category>

		<guid isPermaLink="false">http://blog.webdeely.com/?p=26</guid>
		<description><![CDATA[In my current AIR project I have a need to store persistent user data across sessions.  Because the amount of data is fairly small, but the objects are complex, a SQL Lite database wasn&#8217;t ideal.  I also couldn&#8217;t use standard SharedObjects because of the file size limitations and the fact that crashed our [...]]]></description>
			<content:encoded><![CDATA[<p>In my current AIR project I have a need to store persistent user data across sessions.  Because the amount of data is fairly small, but the objects are complex, a SQL Lite database wasn&#8217;t ideal.  I also couldn&#8217;t use standard SharedObjects because of the file size limitations and the fact that crashed our IDE (more on that in a later post).</p>
<p>The solution I came to was to make my own SharedObjects, or rather custom files using the AMF data format.  It was actually much easier than I had initially feared.  I got my start by reading this <a title="The ABCs of AMF Format" href="http://ajax.sys-con.com/node/468744" target="_blank">article by Ted Patrick</a>.  (Unfortunately, the article is hosted on a Sys-Con property, and I&#8217;m not a fan of <a title="Sys-Con goes from bad to worse, launches Ulitzer, attacks community and content creators" href="http://aralbalkan.com/2022" target="_blank">their tatics</a>.)</p>
<p>Ted&#8217;s article is short and sweet and shows simply how to read and write AMF-encoded objects from/to a ByteArray.  Since we can easily save ByteArrays to disk and read them out again later, this is a perfect solution to the storage needs.</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: #6699cc; font-weight: bold;">var</span> byteArray = <span style="color: #0033ff; font-weight: bold;">new</span> <a href="http://www.google.com/search?q=bytearray%20inurl:http://livedocs.adobe.com/flex/201/langref/%20inurl:bytearray.html"><span style="color: #004993;">ByteArray</span></a><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span><br />
<span style="color: #009900; font-style: italic;">// the writeObject() method encodes any object into AMF</span><br />
byteArray<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">writeObject</span><span style="color: #000000;">&#40;</span> <span style="color: #000000;">&#123;</span> myBool<span style="color: #000066; font-weight: bold;">:</span> <span style="color: #0033ff; font-weight: bold;">true</span><span style="color: #000066; font-weight: bold;">,</span> myString<span style="color: #000066; font-weight: bold;">:</span><span style="color: #990000;">&quot;Hello World&quot;</span> <span style="color: #000000;">&#125;</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span><br />
<br />
<span style="color: #009900; font-style: italic;">//the readObject() method decodes the AMF into a standard AS3 Object</span><br />
<span style="color: #6699cc; font-weight: bold;">var</span> myObject<span style="color: #000066; font-weight: bold;">:</span><a href="http://www.google.com/search?q=object%20inurl:http://livedocs.adobe.com/flex/201/langref/%20inurl:object.html"><span style="color: #004993;">Object</span></a> = byteArray<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">readObject</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span></div></div>
<p>So, this approach works great if you are only using simple Objects made up of Flash Player core types.  Things get a little more complicated when you need to save complex custom objects.  AMF doesn&#8217;t automatically recognize your custom objects.  This effects all AMF transport methods, including SharedObject, LocalConnection and Remoting.</p>
<p>In order to inform AMF which classes it should recognize, you need to use the <a title="registerClassAlias" href="http://livedocs.adobe.com/flex/3/langref/flash/net/package.html#registerClassAlias()" target="_blank">registerClassAlias()</a> method:</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: #0033ff; font-weight: bold;">import</span> <span style="color: #004993;">flash.net</span><span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">registerClassAlias</span><span style="color: #000066; font-weight: bold;">;</span><br />
<span style="color: #0033ff; font-weight: bold;">import</span> com<span style="color: #000066; font-weight: bold;">.</span>webdeely<span style="color: #000066; font-weight: bold;">.</span>MyCustomClass<span style="color: #000066; font-weight: bold;">;</span><br />
<br />
<span style="color: #009900; font-style: italic;">// pass in the path to the class definition and a </span><br />
<span style="color: #009900; font-style: italic;">// reference to the actual Class</span><br />
<span style="color: #004993;">registerClassAlias</span><span style="color: #000000;">&#40;</span><span style="color: #990000;">&quot;com.webdeely.MyCustomClass&quot;</span><span style="color: #000066; font-weight: bold;">,</span> MyCustomClass<span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span><br />
<br />
<span style="color: #6699cc; font-weight: bold;">var</span> mcc<span style="color: #000066; font-weight: bold;">:</span>MyCustomClass = <span style="color: #0033ff; font-weight: bold;">new</span> MyCustomClass<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span><br />
mcc<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">message</span> = <span style="color: #990000;">&quot;Hello World!&quot;</span><span style="color: #000066; font-weight: bold;">;</span><br />
mcc<span style="color: #000066; font-weight: bold;">.</span>favoriteNumber = <span style="color: #000000; font-weight:bold;">12</span><span style="color: #000066; font-weight: bold;">;</span><br />
mcc<span style="color: #000066; font-weight: bold;">.</span>userName = <span style="color: #990000;">&quot;MiltonB&quot;</span><span style="color: #000066; font-weight: bold;">;</span><br />
<br />
<span style="color: #009900; font-style: italic;">// ByteArray will now recognize all of your custom class' properties, </span><br />
<span style="color: #009900; font-style: italic;">// and encode them to AMF</span><br />
<span style="color: #6699cc; font-weight: bold;">var</span> byteArray<span style="color: #000066; font-weight: bold;">:</span><a href="http://www.google.com/search?q=bytearray%20inurl:http://livedocs.adobe.com/flex/201/langref/%20inurl:bytearray.html"><span style="color: #004993;">ByteArray</span></a> = <span style="color: #0033ff; font-weight: bold;">new</span> <a href="http://www.google.com/search?q=bytearray%20inurl:http://livedocs.adobe.com/flex/201/langref/%20inurl:bytearray.html"><span style="color: #004993;">ByteArray</span></a><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span><br />
byteArray<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">writeObject</span><span style="color: #000000;">&#40;</span> mcc <span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span><br />
<br />
<span style="color: #009900; font-style: italic;">// ...and they can be decoded directly back to your class!</span><br />
<span style="color: #6699cc; font-weight: bold;">var</span> mcc2<span style="color: #000066; font-weight: bold;">:</span>MyCustomClass = byteArray<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">readObject</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span> <span style="color: #0033ff; font-weight: bold;">as</span> MyCustomClass<span style="color: #000066; font-weight: bold;">;</span></div></div>
<p>Ok, so now we have the encoding and decoding working properly, but we still need to save the file to disk in order for any of this to be useful.  For this we&#8217;ll use AIR&#8217;s File and FileStream classes:</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: #0033ff; font-weight: bold;">import</span> flash<span style="color: #000066; font-weight: bold;">.</span>filesystem<span style="color: #000066; font-weight: bold;">.</span>File<span style="color: #000066; font-weight: bold;">;</span><br />
<span style="color: #0033ff; font-weight: bold;">import</span> flash<span style="color: #000066; font-weight: bold;">.</span>filesystem<span style="color: #000066; font-weight: bold;">.</span>FileStream<span style="color: #000066; font-weight: bold;">;</span><br />
<br />
<span style="color: #0033ff; font-weight: bold;">private</span> <span style="color: #339966; font-weight: bold;">function</span> writeFile<span style="color: #000000;">&#40;</span> bytes<span style="color: #000066; font-weight: bold;">:</span><a href="http://www.google.com/search?q=bytearray%20inurl:http://livedocs.adobe.com/flex/201/langref/%20inurl:bytearray.html"><span style="color: #004993;">ByteArray</span></a> <span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">:</span><span style="color: #0033ff; font-weight: bold;">void</span><br />
<span style="color: #000000;">&#123;</span><br />
&nbsp; <span style="color: #009900; font-style: italic;">// save our data to the user's desktop, in a file called &quot;test.sol&quot;</span><br />
&nbsp; <span style="color: #009900; font-style: italic;">// &nbsp;btw, 'sol' is not a required extension, in fact you don't need an extension</span><br />
&nbsp; <span style="color: #6699cc; font-weight: bold;">var</span> file<span style="color: #000066; font-weight: bold;">:</span>File = File<span style="color: #000066; font-weight: bold;">.</span>desktopDirectory<span style="color: #000066; font-weight: bold;">.</span>resolvePath<span style="color: #000000;">&#40;</span><span style="color: #990000;">&quot;test.sol&quot;</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span><br />
<br />
&nbsp; <span style="color: #009900; font-style: italic;">// Create a file stream to write stuff to the file.</span><br />
&nbsp; <span style="color: #6699cc; font-weight: bold;">var</span> stream<span style="color: #000066; font-weight: bold;">:</span>FileStream = <span style="color: #0033ff; font-weight: bold;">new</span> FileStream<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span><br />
<br />
&nbsp; <span style="color: #009900; font-style: italic;">// Open the file stream and write the data</span><br />
&nbsp; stream<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">open</span><span style="color: #000000;">&#40;</span> file<span style="color: #000066; font-weight: bold;">,</span> FileMode<span style="color: #000066; font-weight: bold;">.</span>WRITE <span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span><br />
&nbsp; stream<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">writeBytes</span><span style="color: #000000;">&#40;</span>bytes<span style="color: #000066; font-weight: bold;">,</span>0<span style="color: #000066; font-weight: bold;">,</span>bytes<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">bytesAvailable</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span><br />
&nbsp; stream<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">close</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span><br />
<span style="color: #000000;">&#125;</span><br />
<br />
<span style="color: #0033ff; font-weight: bold;">private</span> <span style="color: #339966; font-weight: bold;">function</span> loadFile<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">:</span><a href="http://www.google.com/search?q=bytearray%20inurl:http://livedocs.adobe.com/flex/201/langref/%20inurl:bytearray.html"><span style="color: #004993;">ByteArray</span></a><br />
<span style="color: #000000;">&#123;</span><br />
&nbsp; <span style="color: #6699cc; font-weight: bold;">var</span> bytes<span style="color: #000066; font-weight: bold;">:</span><a href="http://www.google.com/search?q=bytearray%20inurl:http://livedocs.adobe.com/flex/201/langref/%20inurl:bytearray.html"><span style="color: #004993;">ByteArray</span></a> = <span style="color: #0033ff; font-weight: bold;">new</span> <a href="http://www.google.com/search?q=bytearray%20inurl:http://livedocs.adobe.com/flex/201/langref/%20inurl:bytearray.html"><span style="color: #004993;">ByteArray</span></a><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span><br />
&nbsp; <span style="color: #6699cc; font-weight: bold;">var</span> file<span style="color: #000066; font-weight: bold;">:</span>File = File<span style="color: #000066; font-weight: bold;">.</span>desktopDirectory<span style="color: #000066; font-weight: bold;">.</span>resolvePath<span style="color: #000000;">&#40;</span><span style="color: #990000;">&quot;test.sol&quot;</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span><br />
&nbsp; <span style="color: #6699cc; font-weight: bold;">var</span> stream<span style="color: #000066; font-weight: bold;">:</span>FileStream = <span style="color: #0033ff; font-weight: bold;">new</span> FileStream<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span><br />
<br />
&nbsp; <span style="color: #009900; font-style: italic;">// Open the file stream in read mode</span><br />
&nbsp; stream<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">open</span><span style="color: #000000;">&#40;</span> file<span style="color: #000066; font-weight: bold;">,</span> FileMode<span style="color: #000066; font-weight: bold;">.</span>READ <span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span><br />
<br />
&nbsp; <span style="color: #009900; font-style: italic;">// read the bytes directly into the ByteArray</span><br />
&nbsp; stream<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">readBytes</span><span style="color: #000000;">&#40;</span>bytes<span style="color: #000066; font-weight: bold;">,</span> 0<span style="color: #000066; font-weight: bold;">,</span> stream<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">bytesAvailable</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span><br />
&nbsp; stream<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">close</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span><br />
&nbsp; <span style="color: #0033ff; font-weight: bold;">return</span> bytes<span style="color: #000066; font-weight: bold;">;</span><br />
<span style="color: #000000;">&#125;</span></div></div>
<p>Hopefully this will be helpful to anyone faced with similar challenges.  I have found the de/serialization of the AMF objects to be extremely fast, reliable and convenient.  It works wonders and was a very quick switch over from the standard SharedObject process.</p>
<p>I have put together a simple Flex project file for an AIR app that allows you to experiment with the code here.  <a href='http://blog.webdeely.com/wp-content/uploads/2009/03/customamffiles.zip'>You can download the package here.</a></p>
]]></content:encoded>
			<wfw:commentRss>http://blog.webdeely.com/2009/03/storing-custom-strongly-typed-amf-files-for-air-apps/feed/</wfw:commentRss>
		<slash:comments>7</slash:comments>
		</item>
		<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:
1044: [...]]]></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&#8217;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>
