<?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>JonnyReeves.co.uk &#187; ActionScript 3</title>
	<atom:link href="http://www.jonnyreeves.co.uk/category/actionscript-3/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.jonnyreeves.co.uk</link>
	<description>Actionscript, Flash, PHP and stuff</description>
	<lastBuildDate>Mon, 19 Jul 2010 15:36:14 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.8.4</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>Hudson, MXMLC and Embedding Assets</title>
		<link>http://www.jonnyreeves.co.uk/2010/07/hudson-mxmlc-and-embedding-assets/</link>
		<comments>http://www.jonnyreeves.co.uk/2010/07/hudson-mxmlc-and-embedding-assets/#comments</comments>
		<pubDate>Mon, 19 Jul 2010 15:28:37 +0000</pubDate>
		<dc:creator>Jonny</dc:creator>
				<category><![CDATA[ActionScript 3]]></category>
		<category><![CDATA[asset]]></category>
		<category><![CDATA[embed]]></category>
		<category><![CDATA[hudson]]></category>
		<category><![CDATA[mxmlc]]></category>

		<guid isPermaLink="false">http://www.jonnyreeves.co.uk/?p=196</guid>
		<description><![CDATA[Quick post to help out anyone in the same headscratching situation that I just found myself in.  I was in the process of getting our Flash build up and running on Hudson when I fell foul of the following error:

[java] /foo/diablo-flash/workspace/adoption_ingame/src/com/mindcandy/diablo/adoption_ingame/controller/DropDownConfigManager.as(17): col: 4: Error: unable to resolve &#8216;dropDownConfig.xml&#8217; for transcoding
[java] 
[java] &#160;&#160; &#160; &#160; [...]]]></description>
			<content:encoded><![CDATA[<p>Quick post to help out anyone in the same headscratching situation that I just found myself in.  I was in the process of getting our Flash build up and running on Hudson when I fell foul of the following error:</p>
<div class="dean_ch" style="white-space: nowrap; overflow: scroll;">
[java] /foo/diablo-flash/workspace/adoption_ingame/src/com/mindcandy/diablo/adoption_ingame/controller/DropDownConfigManager.as(17): col: 4: Error: unable to resolve &#8216;dropDownConfig.xml&#8217; for transcoding<br />
[java] <br />
[java] &nbsp;&nbsp; &nbsp; &nbsp; &nbsp; [Embed(source=&quot;dropDownConfig.xml&quot;, mimeType=&quot;application/octet-stream&quot;)]<br />
&nbsp;</div>
<p>Strange, I thought to myself, the file is definitnely there:</p>
<div class="dean_ch" style="white-space: nowrap; overflow: scroll;">
host:/foo/diablo-flash/workspace/adoption_ingame/src# ls -l<br />
total 100<br />
drwxr-xr-x 4 tomcat6 tomcat6 &nbsp;4096 2010-07-19 15:47 com<br />
-rw-r&#8211;r&#8211; 1 tomcat6 tomcat6 12205 2010-07-19 15:47 dropdownConfig.xml<br />
&nbsp;</div>
<p>And then the answer struck me &#8211; the casing is different &#8211; dropDownConfig.xml in the Embed vs. dropdownConfig.xml on disc, sure enough bringing these two back into sync fixed the issue and my build proceeded as planned with Hudson.</p>
<p>I wondered why I had never come across this problem during day-to-day builds and then I remember that Mac OS ships with Case Insensitive filesystem by default&#8230;</p>
]]></content:encoded>
			<wfw:commentRss>http://www.jonnyreeves.co.uk/2010/07/hudson-mxmlc-and-embedding-assets/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>FDT and FlexUnit 4.1 Beta</title>
		<link>http://www.jonnyreeves.co.uk/2010/06/fdt-and-flexunit-4-1-beta/</link>
		<comments>http://www.jonnyreeves.co.uk/2010/06/fdt-and-flexunit-4-1-beta/#comments</comments>
		<pubDate>Sat, 19 Jun 2010 16:26:22 +0000</pubDate>
		<dc:creator>Jonny</dc:creator>
				<category><![CDATA[ActionScript 3]]></category>
		<category><![CDATA[actionscript]]></category>
		<category><![CDATA[eclipse]]></category>
		<category><![CDATA[fdt]]></category>
		<category><![CDATA[flexunit]]></category>

		<guid isPermaLink="false">http://www.jonnyreeves.co.uk/?p=185</guid>
		<description><![CDATA[FlexUnit 4 was a massive leap forward for Test Driven ActionScript 3 Development allowing us to make use of metadata annotations, hamcrest and easier asynchronous testing and I was delighted to discover that the flexunit.org team are still busy working away preparing for the next milestone release of FlexUnit 4.1 which boasts some great new [...]]]></description>
			<content:encoded><![CDATA[<p>FlexUnit 4 was a massive leap forward for Test Driven ActionScript 3 Development allowing us to make use of metadata annotations, hamcrest and easier asynchronous testing and I was delighted to discover that the <a href="http://flexunit.org/">flexunit.org</a> team are still busy working away preparing for the next milestone release of <a href="http://github.com/flexunit/flexunit/downloads">FlexUnit 4.1</a> which boasts some <a href="http://www.flexunit.org/?p=62">great new features</a>, my favourite being an ANT Task to generate TestSuite&#8217;s automatically (something that only Antennae appeared to offer before).</p>
<p>This wiki post will show you how to get the FlexUnit 4.1 beta up and running in <a href="http://www.fdt.powerflasher.com/developer-tools/fdt-3/home/">FDT 3.5</a> by making use of the FlexUnit ANT tasks.</p>
<p>First up we will download the FlexUnit 4.1 beta; I will be downloading the <a href="http://www.flexunit.org/releases/flexunit-4.1.0-beta1-flex3.5-AS3.zip">build for FlexSDK 3.5, AS3 Pure</a>.</p>
<p>Once unzipped, you will want to add the FlexUnit 4.1 libraries to your project&#8217;s libs folder; once copied across your project should look something like the screenshot below:</p>
<div id="attachment_186" class="wp-caption aligncenter" style="width: 486px"><img src="http://www.jonnyreeves.co.uk/wp-content/uploads/2010/06/flexunit4.1-libs.PNG" alt="Copying the FlexUnit 4.1 libs into your FDT project" title="flexunit4.1-libs" width="476" height="374" class="size-full wp-image-186" /><p class="wp-caption-text">Copying the FlexUnit 4.1 libs into your FDT project</p></div>
<p>Once you have copied the FlexUnit 4.1 libs into your project you will want to add the FlexUnit core library SWC to your FDT Class Path so you get code completion on FlexUnit methods; this is done by right-clicking on the <b>flexunit-core-4.1.0-beta1.swc</b> file; again see the screnshow below:<br />
<div id="attachment_187" class="wp-caption aligncenter" style="width: 510px"><img src="http://www.jonnyreeves.co.uk/wp-content/uploads/2010/06/flexunit4.1-add-to-classpath.PNG" alt="Adding the FlexUnit 4.1 Core SWC to your project&#039;s Class Path" title="flexunit4.1-add-to-classpath" width="500" class="size-full wp-image-187" /><p class="wp-caption-text">Adding the FlexUnit 4.1 Core SWC to your project's Class Path</p></div></p>
<p>Next up we will add a very simple, sample test to the project, start by adding a new &#8220;Source Folder&#8221; to your project by selecting File -> New -> Source Folder; name the folder <b>test-src</b>.  Now create a new ActionScript Class in the test-src folder and name it TestExample.as.</p>
<p>Because FlexUnit 4 is driven by metadata, there is no need to extend a base class; instead you just need to annotate the methods which represent test with the <b>[Test]</b> metadata tag.  Our example test will do nothing, but will at least allow FlexUnit 4.1 to fire up and show some output:</p>
<div class="dean_ch" style="white-space: nowrap; overflow: scroll;">
package &nbsp;<br />
<span class="br0">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span class="kw3">import</span> org.<span class="me1">flexunit</span>.<span class="me1">asserts</span>.<span class="me1">assertTrue</span>;</p>
<p>&nbsp; &nbsp; &nbsp; &nbsp; <span class="coMULTI">/**<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;* An example Test Case to get FlexUnit 4.1 Beta up and running.<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;* @author Jonny Reeves<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;*/</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span class="kw3">public</span> <span class="kw2">class</span> TestExample <br />
&nbsp; &nbsp; &nbsp; &nbsp; <span class="br0">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="br0">&#91;</span>Test<span class="br0">&#93;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="kw3">public</span> <span class="kw2">function</span> exampleTest<span class="br0">&#40;</span><span class="br0">&#41;</span> : <span class="kw3">void</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="br0">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="co1">// Not much of a test! :)</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; assertTrue<span class="br0">&#40;</span><span class="st0">&quot;FlexUnit 4.1 Beta is running under FDT&quot;</span>, <span class="kw2">true</span><span class="br0">&#41;</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="br0">&#125;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span class="br0">&#125;</span><br />
<span class="br0">&#125;</span><br />
&nbsp;</div>
<p>The final step is to setup the ANT Build File which will automatically create our TestSuite and launch the FlexUnit 4 Visual Test Runner to display the outcome of our test.  If you have not used ANT before in FDT then you may need to open the ANT View by selecting Window -> Show View -> Ant.</p>
<p>Create a new file named <b>build.xml</b> in your project; when you open this file for editing FDT should automatically fire up the ANT editor which provides syntax highlighting for you.  Start off by creating a barebones ANT file:</p>
<div class="dean_ch" style="white-space: nowrap; overflow: scroll;">
<span class="sc3"><span class="re1">&lt;project</span> <span class="re0">name</span>=<span class="st0">&quot;FlexUnit4.1-Example&quot;</span><span class="re2">&gt;</span></span><br />
<span class="sc3"><span class="re1">&lt;/project<span class="re2">&gt;</span></span></span><br />
&nbsp;</div>
<p>Now drag the build.xml into the ANT View; once added it should appear like the screenshot below:</p>
<div id="attachment_189" class="wp-caption aligncenter" style="width: 510px"><img src="http://www.jonnyreeves.co.uk/wp-content/uploads/2010/06/flexunit4.1-buildfile.PNG" alt="Creating an ANT BuildFile and adding it to the ANT View" title="flexunit4.1-buildfile" width="500" class="size-full wp-image-189" /><p class="wp-caption-text">Creating an ANT BuildFile and adding it to the ANT View</p></div>
<p>Now we want to create a new Build Task which will generate a Test Suite from our test-src folder and then compile a FlexUnit 4.1 SWF which runs those tests.</p>
<div class="dean_ch" style="white-space: nowrap; overflow: scroll;">
<span class="sc3"><span class="re1">&lt;project</span> <span class="re0">name</span>=<span class="st0">&quot;FlexUnit4.1-Example&quot;</span><span class="re2">&gt;</span></span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span class="sc3"><span class="coMULTI">&lt;!&#8211; Update this property to point to your FLEX SDK; note there is<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; a bug in FlexUnit 4.1 Beta 1 where the FLEX SDK path must<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; NOT include any spaces, otherwise you will get an error during<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; the MXMLC compilation stage; this has already been fixed in the<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; latest Builds of FlexUnit 4.1, see: http://bit.ly/dpHcHT &#8211;&gt;</span></span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span class="sc3"><span class="re1">&lt;property</span> <span class="re0">name</span>=<span class="st0">&quot;FLEX_HOME&quot;</span> <span class="re0">location</span>=<span class="st0">&quot;${eclipse.fdt.flexsdk}&quot;</span> <span class="re2">/&gt;</span></span></p>
<p>&nbsp; &nbsp; &nbsp; &nbsp; <span class="sc3"><span class="re1">&lt;property</span> <span class="re0">name</span>=<span class="st0">&quot;bin.dir&quot;</span> <span class="re0">value</span>=<span class="st0">&quot;${basedir}/bin&quot;</span> <span class="re2">/&gt;</span></span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span class="sc3"><span class="re1">&lt;property</span> <span class="re0">name</span>=<span class="st0">&quot;report.dir&quot;</span> <span class="re0">value</span>=<span class="st0">&quot;${basedir}/reports&quot;</span> <span class="re2">/&gt;</span></span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span class="sc3"><span class="re1">&lt;property</span> <span class="re0">name</span>=<span class="st0">&quot;lib.dir&quot;</span> <span class="re0">value</span>=<span class="st0">&quot;${basedir}/libs&quot;</span> <span class="re2">/&gt;</span></span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span class="sc3"><span class="re1">&lt;property</span> <span class="re0">name</span>=<span class="st0">&quot;test-src.dir&quot;</span> <span class="re0">value</span>=<span class="st0">&quot;${basedir}/test-src&quot;</span> <span class="re2">/&gt;</span></span></p>
<p>&nbsp; &nbsp; &nbsp; &nbsp; <span class="sc3"><span class="re1">&lt;taskdef</span> <span class="re0">resource</span>=<span class="st0">&quot;flexTasks.tasks&quot;</span> <span class="re0">classpath</span>=<span class="st0">&quot;${FLEX_HOME}/ant/lib/flexTasks.jar&quot;</span> <span class="re2">/&gt;</span></span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span class="sc3"><span class="re1">&lt;taskdef</span> <span class="re0">resource</span>=<span class="st0">&quot;flexUnitTasks.tasks&quot;</span> <span class="re0">classpath</span>=<span class="st0">&quot;${lib.dir}/flexUnitTasks-4.1.0-beta1.14.jar&quot;</span> <span class="re2">/&gt;</span></span></p>
<p>&nbsp; &nbsp; &nbsp; &nbsp; <span class="sc3"><span class="coMULTI">&lt;!&#8211; Run FlexUnit 4.1 and generate JUnit Output &#8211;&gt;</span></span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span class="sc3"><span class="re1">&lt;target</span> <span class="re0">name</span>=<span class="st0">&quot;test&quot;</span> <span class="re0">depends</span>=<span class="st0">&quot;init&quot;</span> <span class="re0">description</span>=<span class="st0">&quot;Run Unit Tests&quot;</span><span class="re2">&gt;</span></span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="sc3"><span class="re1">&lt;flexunit</span> <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="re0">workingDir</span>=<span class="st0">&quot;${bin.dir}&quot;</span> <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="re0">toDir</span>=<span class="st0">&quot;${report.dir}&quot;</span> <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="re0">verbose</span>=<span class="st0">&quot;true&quot;</span> <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="re0">haltonfailure</span>=<span class="st0">&quot;true&quot;</span><span class="re2">&gt;</span></span> <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="sc3"><span class="re1">&lt;testSource</span> <span class="re0">dir</span>=<span class="st0">&quot;${test-src.dir}&quot;</span><span class="re2">&gt;</span></span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="sc3"><span class="re1">&lt;include</span> <span class="re0">name</span>=<span class="st0">&quot;**/*Test*.as&quot;</span> <span class="re2">/&gt;</span></span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="sc3"><span class="re1">&lt;/testSource<span class="re2">&gt;</span></span></span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="sc3"><span class="re1">&lt;library</span> <span class="re0">dir</span>=<span class="st0">&quot;${lib.dir}&quot;</span> <span class="re2">/&gt;</span></span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="sc3"><span class="re1">&lt;/flexunit<span class="re2">&gt;</span></span></span></p>
<p>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="sc3"><span class="re1">&lt;junitreport</span> <span class="re0">todir</span>=<span class="st0">&quot;${report.dir}&quot;</span><span class="re2">&gt;</span></span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="sc3"><span class="re1">&lt;fileset</span> <span class="re0">dir</span>=<span class="st0">&quot;${report.dir}&quot;</span><span class="re2">&gt;</span></span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="sc3"><span class="re1">&lt;include</span> <span class="re0">name</span>=<span class="st0">&quot;TEST-*.xml&quot;</span> <span class="re2">/&gt;</span></span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="sc3"><span class="re1">&lt;/fileset<span class="re2">&gt;</span></span></span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="sc3"><span class="re1">&lt;report</span> <span class="re0">format</span>=<span class="st0">&quot;frames&quot;</span> <span class="re0">todir</span>=<span class="st0">&quot;${report.dir}/html&quot;</span> <span class="re2">/&gt;</span></span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="sc3"><span class="re1">&lt;/junitreport<span class="re2">&gt;</span></span></span></p>
<p>&nbsp; &nbsp; &nbsp; &nbsp; <span class="sc3"><span class="re1">&lt;/target<span class="re2">&gt;</span></span></span></p>
<p>&nbsp; &nbsp; &nbsp; &nbsp; <span class="sc3"><span class="coMULTI">&lt;!&#8211; Create the required directories and clean out the reports folder &#8211;&gt;</span></span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span class="sc3"><span class="re1">&lt;target</span> <span class="re0">name</span>=<span class="st0">&quot;init&quot;</span><span class="re2">&gt;</span></span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="sc3"><span class="re1">&lt;delete</span> <span class="re0">dir</span>=<span class="st0">&quot;${report.dir}&quot;</span> <span class="re2">/&gt;</span></span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="sc3"><span class="re1">&lt;mkdir</span> <span class="re0">dir</span>=<span class="st0">&quot;${bin.dir}&quot;</span> <span class="re2">/&gt;</span></span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="sc3"><span class="re1">&lt;mkdir</span> <span class="re0">dir</span>=<span class="st0">&quot;${report.dir}&quot;</span> <span class="re2">/&gt;</span></span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span class="sc3"><span class="re1">&lt;/target<span class="re2">&gt;</span></span></span><br />
<span class="sc3"><span class="re1">&lt;/project<span class="re2">&gt;</span></span></span><br />
&nbsp;</div>
<p>Once you&#8217;re build file is setup you can execute the <b>test</b> ANT task.  If the task completes succesfully, FlexUnit will have populated the reports folder with both JUnit style reports and an HTML version which can be opened in a web browser.</p>
<div id="attachment_190" class="wp-caption aligncenter" style="width: 310px"><a href="http://www.jonnyreeves.co.uk/wp-content/uploads/2010/06/flexunit4.1-testresults.PNG"><img src="http://www.jonnyreeves.co.uk/wp-content/uploads/2010/06/flexunit4.1-testresults-300x175.PNG" alt="SUCCESS! My Test Passed :)" title="flexunit4.1-testresults" width="300" height="175" class="size-medium wp-image-190" /></a><p class="wp-caption-text">SUCCESS! My Test Passed :)</p></div>
<p>If the build fails then the Output Console view should provide you with some debugging hints; if you are using FlexUnit 4.1 Beta 1 then make sure your Flex SDK path does not include any spaces (this particular bug will be fixed in beta 2 of FlexUnit 4.1).</p>
<p>Further reading:</p>
<ul>
<li><a href="http://docs.flexunit.org/index.php?title=Ant_Task">FlexUnit ANT Task documentation</a></li>
<li><a href="http://forums.adobe.com/community/opensource/flexunit">FlexUnit Support Forum</a></li>
</ul>
]]></content:encoded>
			<wfw:commentRss>http://www.jonnyreeves.co.uk/2010/06/fdt-and-flexunit-4-1-beta/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>Reducing the size of SWF Files</title>
		<link>http://www.jonnyreeves.co.uk/2010/06/reducing-the-size-of-swf-files/</link>
		<comments>http://www.jonnyreeves.co.uk/2010/06/reducing-the-size-of-swf-files/#comments</comments>
		<pubDate>Tue, 15 Jun 2010 20:20:11 +0000</pubDate>
		<dc:creator>Jonny</dc:creator>
				<category><![CDATA[ActionScript 3]]></category>
		<category><![CDATA[actionscript]]></category>
		<category><![CDATA[filesize]]></category>
		<category><![CDATA[flash]]></category>
		<category><![CDATA[mxmlc]]></category>
		<category><![CDATA[optimisation]]></category>

		<guid isPermaLink="false">http://www.jonnyreeves.co.uk/?p=180</guid>
		<description><![CDATA[Over at Moshi HQ, we&#8217;ve spent a fair bit of time looking at how to reduce the size of the SWFs we publish; here&#8217;s a quick checklist to rattle through to get the most bang for your buck (or in this case, Kb)
1. Joa Ebert&#8217;s Apparat.
Joa is an ActionScript hero (infact he won an award [...]]]></description>
			<content:encoded><![CDATA[<p>Over at Moshi HQ, we&#8217;ve spent a fair bit of time looking at how to reduce the size of the SWFs we publish; here&#8217;s a quick checklist to rattle through to get the most bang for your buck (or in this case, Kb)</p>
<p>1. Joa Ebert&#8217;s Apparat.<br />
Joa is an ActionScript hero (infact <a href="http://blog.joa-ebert.com/2010/06/10/fatc-awards/">he won an award</a> to prove it); one of his tools is <a href="http://blog.joa-ebert.com/2010/05/07/apparat-crunching-swf-files-since-2009/">Apparat</a>; a Scala application which optimises SWFs by tinkering with the compression they use.  Apparat is a real quick win as once you&#8217;ve integrated it into your build process you will immediately being reaping the rewards.</p>
<p>2. Sothink SWF Decompiler<br />
Yes, number two on my list is a decompiler; this is not a mistake.  <a href="http://www.sothink.com/product/flashdecompiler/index.htm">Sothink SWF Decompiler</a> is an essential part of the optimisation process as it allows you to explore all the assets, ActionScript classes, fonts, bitmaps, etc which are lurking around in your SWF &#8211; think of it like a visual Size Report for a SWF.</p>
<p>3. Make use of Run Time Shared Libraries<br />
Flex developers seem very comfortable with <a href="http://livedocs.adobe.com/flex/3/html/help.html?content=rsl_02.html#220675">Runtime Shared Libraries</a>, but it&#8217;s something that most ActionScript dev&#8217;s aren&#8217;t so hot on.  The MXMLC compiler provides a couple of ways to reduce the size of your published SWF by allowing you to automatically exclude duplicated class definitions across SWFs loaded at run time.   The problem is a very simple one; you have a Main application which loads in a bunch of child &#8220;sub apps&#8221; into the same Application Domain; both of the SWFs end up with the same classes compiled into them (for example, you may be using famework elements in both) &#8211; because the Main application SWF has already loaded these classes there is no need to include them into the child swf as well.  </p>
<p>The simplest MXMLC compiler flag you can use is, <b>runtime-shared-libraries</b>, simply point it at the location of your Main SWF when compiling the subapps and it will do the rest for you. Alternatively, Those of you who worked in AS2 back in the day may recall the old <a href="http://www.adobe.com/livedocs/flash/9.0/main/wwhelp/wwhimpl/common/html/wwhelp.htm?context=LiveDocs_Parts&#038;file=00000817.html">exclude.xml</a>; well it&#8217;s still alive and kicking with MXMLC, it just goes under the name of <b>link-report</b>.</p>
<p>The process is pretty straight forward, compile your main application supplying the link-report flag, this will dump out an XML file.  Next, compile all your subapps supplying the load-externs flag.  <a href="http://www.bit-101.com/blog/?p=941">Keith Peters goes into more detail on his blog</a>.</p>
<p>4. Check your Compiler Flags<br />
This may seem pretty obvious, but it&#8217;s important to check; The MXMLC compiler which ships with the Flex SDK supports a <a href="http://livedocs.adobe.com/flex/3/html/help.html?content=compilers_14.html">crazy number of switches and options</a>, the following options can impact on the size of the compiled SWF:</p>
<ul>
<li><b>debug</b> &#8211; Pretty obvious, if you set the debug flag to true when compiling, MXMLC will embed a whole bunch of debugging information to your SWF, bloating out the filesize.  The main thing to watch out for is that you don&#8217;t end up deploying SWFs compiled with the debug flag set to true on your live server.  Sames goes for the <b>optimise</b> and <b>verbose-stacktraces</b> flags</li>
<li><b>include-libraries</b> &#8211; Make sure that you didn&#8217;t mean to use <i>library-path</i> instead!  include-libraries will compile the entire contents of a SWC into your final SWF file even if you never actually use any of it! Using library-path, on the other hand, results in only the classes which you import being compiled into the SWF</li>
</ul>
]]></content:encoded>
			<wfw:commentRss>http://www.jonnyreeves.co.uk/2010/06/reducing-the-size-of-swf-files/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Logging in ActionScript 3</title>
		<link>http://www.jonnyreeves.co.uk/2010/02/logging-in-actionscript-3/</link>
		<comments>http://www.jonnyreeves.co.uk/2010/02/logging-in-actionscript-3/#comments</comments>
		<pubDate>Mon, 22 Feb 2010 20:27:36 +0000</pubDate>
		<dc:creator>Jonny</dc:creator>
				<category><![CDATA[ActionScript 2]]></category>
		<category><![CDATA[ActionScript 3]]></category>
		<category><![CDATA[best practices]]></category>
		<category><![CDATA[logging]]></category>

		<guid isPermaLink="false">http://www.jonnyreeves.co.uk/?p=169</guid>
		<description><![CDATA[Logging is a fundamental part of any mid to large scale application, your application needs to be able to talk to other developers and Q&#038;A engineers to help diagnose problems and gain insight into what&#8217;s going on under the hood.  Jesse Warden recently wrote an excellent article on logging, however, my own implementation of [...]]]></description>
			<content:encoded><![CDATA[<p>Logging is a fundamental part of any mid to large scale application, your application needs to be able to talk to other developers and Q&#038;A engineers to help diagnose problems and gain insight into what&#8217;s going on under the hood.  Jesse Warden recently wrote <a href="http://jessewarden.com/2010/02/consulting-chronicles-3-preventing-fire-drills-crises-by-removing-land-mines-and-using-diagnostic-tools.html">an excellent article on logging</a>, however, my own implementation of logging AS3 apps differs so much that I thought it warranted a blog post.</p>
<h3>The Problems</h3>
<p>One of the most important things in OOP is to ensure that you avoid tight coupling; Jesse&#8217;s approach of using a static logger leaves your code scattered with a dependency on it.  </p>
<p>Another point that Jesse makes is how important it is to include the name of the enclosing class when writing a log message,</p>
<blockquote><p>&#8230; all log messages start with &#8220;ClassName::methodName&#8221; where ClassName is the name of the class you are in, and methodName is the current method the log message is in.  It seems a major pain at first, but I guarantee you when you start removing them 2 months later, you know EXACTLY where to find it vs. that one trace that stays there for weeks because no one found where the bastard is.
</p></blockquote>
<p>I couldn&#8217;t agree more with this, having come from working on a massive application with thousands of log messages, not knowing where a message was originating from would have been a nightmare.  However, Jesse&#8217;s approach is very manual and relies on your entire team being disciplined; not to mention the fact that as soon as you start refactoring that &#8220;ClassName::methodName&#8221; identifier is quickly going to get out of sync.</p>
<h3>A Commons Solution</h3>
<p>I feel that there is a simple solution to both the above problems in the form of the <a href="http://code.google.com/p/as3-commons/">AS3 Commons Logging Framework</a>.  The framework provides an abstraction of logging which means your code is not dependant on any one implementation, plus it has the added benefit of automatically adding the name of the Class when writing a log message; winner!</p>
<p>Usage is pretty straight forward, but requires a little more setup than Jesse&#8217;s static helper approach; first of all your request a static ILogger instance from the LoggerFactory at the top of your class and then you are free to use it throughout the Class to write log messages, for example:</p>
<div class="dean_ch" style="white-space: nowrap; overflow: scroll;">
package uk.<span class="me1">co</span>.<span class="me1">jonnyreeves</span><br />
<span class="br0">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span class="kw3">public</span> <span class="kw2">class</span> MyClass<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span class="br0">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="co1">// Request an ILogger instance for this Class.</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="kw3">public</span> <span class="kw3">static</span> const LOGGER : ILogger = LogFactory.<span class="me1">getClassLogger</span><span class="br0">&#40;</span>MyClass<span class="br0">&#41;</span>;</p>
<p>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="kw3">public</span> <span class="kw2">function</span> MyClass<span class="br0">&#40;</span><span class="br0">&#41;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="br0">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="co1">// Write a log message using the Logger instance.</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; LOGGER.<span class="me1">info</span><span class="br0">&#40;</span><span class="st0">&quot;Created instance of MyClass&quot;</span><span class="br0">&#41;</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="br0">&#125;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span class="br0">&#125;</span><br />
<span class="br0">&#125;</span><br />
&nbsp;</div>
<p>Using the TraceLogger implementation which the AS3 Commons Logger will default to, you would receive the following in your <a href="http://yourpalmark.com/2005/07/01/trace-from-the-browser-using-standard-trace/">Flash TraceLog</a>:</p>
<pre>
Sun Feb 21 10:33:29 GMT+0000 2010 [INFO]  uk.co.jonnyreeves.MyClass - Created instance of MyClass
</pre>
<p>The beauty of this approach is that the actual implementation of the ILogger interface is left to the LoggerFactory which means it can be switched at runtime.  Another neat benfit is that the name of the Logger is taken from the encolosing Class which created it (via <a href="http://code.google.com/p/as3-commons/source/browse/tags/as3-commons-logging/1.1/src/main/actionscript/org/as3commons/logging/LoggerFactory.as">LoggerFactory.getClassLogger()</a>).  This mean that is you rename the Class as part of a refactoring effort, all the log messages contained in said class will automatically update.</p>
<h3>Getting More Specific</h3>
<p>So I&#8217;ve mentioned that your can decide the ILogger implementation at runtime, let&#8217;s see an example of that in action.  My current Logging implementation of choice is the excellent DeMonsters Monster Debugger which reminds me a lot of the AS2 classic, LumnicBox in that it allows you to fully inspect the Object Graph at run time.</p>
<p>The first thing we need is to create an implementation of LogFactory which will return our ILogger instances upon request:</p>
<div class="dean_ch" style="white-space: nowrap; overflow: scroll;">
package uk.<span class="me1">co</span>.<span class="me1">jonnyreeves</span>.<span class="me1">logging</span>.<span class="me1">util</span>.<span class="me1">monsterdebugger</span> <br />
<span class="br0">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span class="kw3">import</span> nl.<span class="me1">demonsters</span>.<span class="me1">debugger</span>.<span class="me1">MonsterDebugger</span>;</p>
<p>&nbsp; &nbsp; &nbsp; &nbsp; <span class="kw3">import</span> org.<span class="me1">as3commons</span>.<span class="me1">logging</span>.<span class="me1">ILogger</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span class="kw3">import</span> org.<span class="me1">as3commons</span>.<span class="me1">logging</span>.<span class="me1">ILoggerFactory</span>;</p>
<p>&nbsp; &nbsp; &nbsp; &nbsp; <span class="coMULTI">/**<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;* Provides a bridge between the AS3Commons Logging Framework and MonsterDebugger.<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;* <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;* @author John Reeves<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;*/</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span class="kw3">public</span> <span class="kw2">class</span> MonsterDebuggerLoggerFactory <span class="kw3">implements</span> ILoggerFactory <br />
&nbsp; &nbsp; &nbsp; &nbsp; <span class="br0">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="coMULTI">/**<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;* Initialises MonsterDebugger<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;* <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;* @param target&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; The Base Object you wisht to start graphing from (usually you will supply the<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;* &nbsp; &nbsp; &nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Display Root DisplayObject).<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;* &nbsp; &nbsp; &nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;* @param clearConsole&nbsp; Clears MonsterDebugger&#8217;s Trace Console when the initial connection is made.<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;*/</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="kw3">public</span> <span class="kw2">function</span> MonsterDebuggerLoggerFactory<span class="br0">&#40;</span><span class="kw3">target</span> : <span class="kw3">Object</span>, clearConsole : <span class="kw3">Boolean</span> = <span class="kw2">true</span><span class="br0">&#41;</span> <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="br0">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="kw2">new</span> MonsterDebugger<span class="br0">&#40;</span><span class="kw3">target</span><span class="br0">&#41;</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="kw1">if</span> <span class="br0">&#40;</span>clearConsole<span class="br0">&#41;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="br0">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; MonsterDebugger.<span class="me1">clearTraces</span><span class="br0">&#40;</span><span class="br0">&#41;</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="br0">&#125;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="br0">&#125;</span></p>
<p>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="coMULTI">/**<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;* Factory Method, used to return an instance of ILogger to the AS3Commons Logging Framework.<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;*/</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="kw3">public</span> <span class="kw2">function</span> getLogger<span class="br0">&#40;</span><span class="kw3">name</span> : <span class="kw3">String</span><span class="br0">&#41;</span> : ILogger<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="br0">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="kw1">return</span> <span class="kw2">new</span> MonsterDebuggerLogger<span class="br0">&#40;</span><span class="kw3">name</span><span class="br0">&#41;</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="br0">&#125;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span class="br0">&#125;</span><br />
<span class="br0">&#125;</span><br />
&nbsp;</div>
<p>Now all that&#8217;s left to do is to create the MonsterDebuggerLogger implementation of the ILogger interface; this will re-write all the LOGGER.info(), etc calls through to MonsterDebugger.</p>
<div class="dean_ch" style="white-space: nowrap; overflow: scroll;">
package uk.co.jonnyreeves.logging.util.monsterdebugger <br />
{<br />
&nbsp; &nbsp; &nbsp; &nbsp; import org.as3commons.logging.util.MessageUtil;<br />
&nbsp; &nbsp; &nbsp; &nbsp; import nl.demonsters.debugger.MonsterDebugger;</p>
<p>&nbsp; &nbsp; &nbsp; &nbsp; import org.as3commons.logging.LogLevel;<br />
&nbsp; &nbsp; &nbsp; &nbsp; import org.as3commons.logging.impl.AbstractLogger;</p>
<p>&nbsp; &nbsp; &nbsp; &nbsp; /**<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;* Provides a bridge between the AS3 Commons Logging implementation and Monster Debugger; it&#8217;s not perfect but it <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;* works for the most part.<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;* <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;* The Target of the log message will always be the name of the logger.<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;* <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;* The Object of the log message will vary depending on the parameters passed. &nbsp;If the message string is empty<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;* then the params Array will be logged. &nbsp;If the message string is not empty, the params Array will be used to<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;* tokenise the message string.<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;* <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;* Usage:<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;* &nbsp; &nbsp; &nbsp;&nbsp; &nbsp; &nbsp; &nbsp; LOGGER.debug(&quot;Hello World&quot;);&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; // Outputs message: &quot;(String) Hello World&quot;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;* &nbsp; &nbsp; &nbsp;&nbsp; &nbsp; &nbsp; &nbsp; LOGGER.debug(&quot;Hello {0} {1}, &quot;Jonny&quot;, &quot;Reeves&quot;);&nbsp; &nbsp; &nbsp; &nbsp; // Outputs message: &quot;(String) Hello Jonny Reeves&quot;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;* &nbsp; &nbsp; &nbsp;&nbsp; &nbsp; &nbsp; &nbsp; LOGGER.debug(&quot;&quot;, [ 1, 2, 3 ]);&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; // Outputs message: &quot;(Array)&#8230;&quot; (which can then be inspected)<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;* &nbsp; &nbsp; &nbsp;&nbsp; &nbsp; &nbsp; &nbsp; <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;* Incorrect usage:<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;* &nbsp; &nbsp; &nbsp;&nbsp; &nbsp; &nbsp; &nbsp; LOGGER.debug(&quot;Some Array&quot;, [1, 2, 3]);&nbsp; // Outputs message: &quot;(String) Some Array&quot; (which can&#8217;t be inspected)<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;* <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;* @author John Reeves<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;*/<br />
&nbsp; &nbsp; &nbsp; &nbsp; public class MonsterDebuggerLogger extends AbstractLogger <br />
&nbsp; &nbsp; &nbsp; &nbsp; {<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; public var level : int = LogLevel.DEBUG;</p>
<p>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; public function MonsterDebuggerLogger(name : String) <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; {<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; super(name);<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; }</p>
<p>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; override protected function log(level : uint, message : String, params : Array) : void<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; {<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; if (level &gt;= this.level)<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; {<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; var target : Object = name;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; var object : Object = getLogObject(message, params);<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; var colour : uint = getLogMessageColour(level);<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; MonsterDebugger.trace(target, object, colour);<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; }<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; }</p>
<p>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; private function getLogObject(message : String, params : Array) : Object <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; {<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; if (message == &quot;&quot;)<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; {<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; // If the user only supplied a single param to log, we remove the params array which is enclosing it.<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; return (params.length == 1) ? params.pop() : params;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; }<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; else<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; {<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; return MessageUtil.toString(message, params);<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; }<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; }</p>
<p>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; private function getLogMessageColour(level : int) : uint <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; {<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; var colour : int;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; switch (level)<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; {<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; case LogLevel.FATAL:<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; case LogLevel.ERROR:<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; colour = MonsterDebugger.COLOR_ERROR;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; break;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; case LogLevel.WARN:<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; colour = MonsterDebugger.COLOR_WARNING;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; break;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; default:<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; colour = MonsterDebugger.COLOR_NORMAL;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; break;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; }<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; return colour;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; }</p>
<p>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; override public function get debugEnabled() : Boolean<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; {<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; return LogLevel.DEBUG &gt;= level;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; }</p>
<p>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; override public function get errorEnabled() : Boolean<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; {<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; return LogLevel.ERROR &gt;= level;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; }</p>
<p>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; override public function get infoEnabled() : Boolean<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; {<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; return LogLevel.INFO &gt;= level;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; }</p>
<p>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; override public function get warnEnabled() : Boolean<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; {<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; return LogLevel.WARN &gt;= level;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; }</p>
<p>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; override public function get fatalEnabled() : Boolean<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; {<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; return LogLevel.FATAL &gt;= level;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; }<br />
&nbsp; &nbsp; &nbsp; &nbsp; }<br />
}<br />
&nbsp;</div>
<p>The code here is fairly self documenting with the protected log() method proxying all the logging requests through to MonsterDebugger.  Because the creators of the AS3Commons Logging Project specified the message param to have a datatype of String, we are forced to do a little bit of a workaround when we want to dump Objects out to the MonsterDebugger console.  There is an <a href="http://code.google.com/p/as3-commons/issues/detail?id=3">open ticket</a> on the AS3Commons project page should you wish to request a change.</p>
<p>The last piece of the puzzle is to swap the AS3Commons LoggingFactory implementation, this is very straight forward and requires a single line of code during your application&#8217;s startup routine (preferably before any logging takes place).</p>
<div class="dean_ch" style="white-space: nowrap; overflow: scroll;">
package &nbsp;<br />
<span class="br0">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span class="kw3">import</span> uk.<span class="me1">co</span>.<span class="me1">jonnyreeves</span>.<span class="me1">logging</span>.<span class="me1">util</span>.<span class="me1">MonsterDebuggerLoggerFactory</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span class="kw3">import</span> flash.<span class="me1">display</span>.<span class="me1">Sprite</span>;</p>
<p>&nbsp; &nbsp; &nbsp; &nbsp; <span class="coMULTI">/**<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;* Application Entry Point.<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;* @author John Reeves<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;*/</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span class="kw3">public</span> <span class="kw2">class</span> MyApp <span class="kw3">extends</span> Sprite <br />
&nbsp; &nbsp; &nbsp; &nbsp; <span class="br0">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="kw3">public</span> <span class="kw2">function</span> MyApp<span class="br0">&#40;</span><span class="br0">&#41;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="br0">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; LoggerFactory.<span class="me1">loggerFactory</span> = <span class="kw2">new</span> MonsterDebuggerLoggerFactory<span class="br0">&#40;</span><span class="kw3">this</span><span class="br0">&#41;</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="br0">&#125;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span class="br0">&#125;</span><br />
<span class="br0">&#125;</span><br />
&nbsp;</div>
<p>Once this is done you are free to start using the LoggingFactory as per the example further up the page.  Your log messages should now show up in the MonsterDebugger logging console.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.jonnyreeves.co.uk/2010/02/logging-in-actionscript-3/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Error 2048 and Flash Policy File Logging</title>
		<link>http://www.jonnyreeves.co.uk/2010/02/error-2048-and-flash-policy-file-logging/</link>
		<comments>http://www.jonnyreeves.co.uk/2010/02/error-2048-and-flash-policy-file-logging/#comments</comments>
		<pubDate>Wed, 17 Feb 2010 14:54:31 +0000</pubDate>
		<dc:creator>Jonny</dc:creator>
				<category><![CDATA[ActionScript 3]]></category>

		<guid isPermaLink="false">http://www.jonnyreeves.co.uk/?p=167</guid>
		<description><![CDATA[Whenever you are working with Flash or Flex applications which make use of 3rd party feeds or data sources (such as XML or JSON), you need to be aware of how the Flash Player deals with Cross Domain security issues.
The easiest way to debug a 2048 Security Error is to enable Policy File logging in [...]]]></description>
			<content:encoded><![CDATA[<p>Whenever you are working with Flash or Flex applications which make use of 3rd party feeds or data sources (such as XML or JSON), you need to be aware of how the Flash Player deals with Cross Domain security issues.</p>
<p>The easiest way to debug a 2048 Security Error is to enable Policy File logging in your mm.cfg; Adobe have <a href="http://www.adobe.com/devnet/flashplayer/articles/fplayer9_security_05.html">a guide posted over on their site</a> which explains how to get setup.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.jonnyreeves.co.uk/2010/02/error-2048-and-flash-policy-file-logging/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>FlexPMD and ANT &#8211; RuleSetFactory Error</title>
		<link>http://www.jonnyreeves.co.uk/2010/02/flexpmd-and-ant-rulesetfactory-error/</link>
		<comments>http://www.jonnyreeves.co.uk/2010/02/flexpmd-and-ant-rulesetfactory-error/#comments</comments>
		<pubDate>Tue, 09 Feb 2010 20:58:19 +0000</pubDate>
		<dc:creator>Jonny</dc:creator>
				<category><![CDATA[ActionScript 3]]></category>
		<category><![CDATA[ant]]></category>
		<category><![CDATA[flexpmd]]></category>

		<guid isPermaLink="false">http://www.jonnyreeves.co.uk/?p=163</guid>
		<description><![CDATA[Just a quick post to save someone a few minutes of headscratching!  I&#8217;ve just finished integrating FlexPMD, Adobe&#8217;s latest opensource offering into my ant build scripts following their documentation when I hit this error:

java.lang.NoClassDefFoundError: net/sourceforge/pmd/RuleSetFactory

Looking at my taskdef, everything appeared to be in order, it wasn&#8217;t until I searched the Adobe JIRA and managed [...]]]></description>
			<content:encoded><![CDATA[<p>Just a quick post to save someone a few minutes of headscratching!  I&#8217;ve just finished integrating FlexPMD, Adobe&#8217;s latest opensource offering into my ant build scripts following <a href="http://opensource.adobe.com/wiki/display/flexpmd/How+to+invoke+FlexPMD">their documentation</a> when I hit this error:</p>
<pre>
java.lang.NoClassDefFoundError: net/sourceforge/pmd/RuleSetFactory
</pre>
<p>Looking at my taskdef, everything appeared to be in order, it wasn&#8217;t until I searched the Adobe JIRA and managed to find <a href="https://bugs.adobe.com/jira/browse/FLEXPMD-106">this ticket</a>.  What&#8217;s even more annoying is that the ticket is marked as Closed!</p>
<p>I would update the wiki entry on the adobe site, but when I try and log in the site stacktraces&#8230;</p>
]]></content:encoded>
			<wfw:commentRss>http://www.jonnyreeves.co.uk/2010/02/flexpmd-and-ant-rulesetfactory-error/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Sorting Values Stored in a Dictionary</title>
		<link>http://www.jonnyreeves.co.uk/2009/06/sorting-values-stored-in-a-dictionary/</link>
		<comments>http://www.jonnyreeves.co.uk/2009/06/sorting-values-stored-in-a-dictionary/#comments</comments>
		<pubDate>Mon, 15 Jun 2009 06:59:11 +0000</pubDate>
		<dc:creator>Jonny</dc:creator>
				<category><![CDATA[ActionScript 3]]></category>
		<category><![CDATA[dictionary]]></category>
		<category><![CDATA[sort]]></category>

		<guid isPermaLink="false">http://www.jonnyreeves.co.uk/?p=93</guid>
		<description><![CDATA[Looking through my incoming seaches from Google I&#8217;ve noticed that a lot of visitors to my site are trying to figure out how to sort values stored in a Dictionary.  The short and simple answer is that you can&#8217;t as Dictionary&#8217;s in AS3 are meant to represent un-ordered HashMaps, however, there&#8217;s nothing to stop [...]]]></description>
			<content:encoded><![CDATA[<p>Looking through my incoming seaches from Google I&#8217;ve noticed that a lot of visitors to my site are trying to figure out how to sort values stored in a Dictionary.  The short and simple answer is that you can&#8217;t as Dictionary&#8217;s in AS3 are meant to represent un-ordered HashMaps, however, there&#8217;s nothing to stop you moving the un-ordered data out of the Dictionary and into an Array:</p>
<div class="dean_ch" style="white-space: nowrap; overflow: scroll;">
package <span class="br0">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span class="kw3">import</span> flash.<span class="me1">display</span>.<span class="me1">Sprite</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span class="kw3">import</span> flash.<span class="me1">utils</span>.<span class="me1">Dictionary</span>;</p>
<p>&nbsp; &nbsp; &nbsp; &nbsp; <span class="coMULTI">/**<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;* @author Jonny Reeves<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;*/</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span class="kw3">public</span> <span class="kw2">class</span> DictionarySort <span class="kw3">extends</span> Sprite <br />
&nbsp; &nbsp; &nbsp; &nbsp; <span class="br0">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="kw2">function</span> DictionarySort<span class="br0">&#40;</span><span class="br0">&#41;</span> : <span class="kw3">void</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="br0">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="kw2">var</span> myDictionary : Dictionary = <span class="kw2">new</span> Dictionary<span class="br0">&#40;</span><span class="br0">&#41;</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="co1">// Provide some values to sort.</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; myDictionary<span class="br0">&#91;</span><span class="nu0">500</span><span class="br0">&#93;</span> = <span class="st0">&quot;Five Hundred&quot;</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; myDictionary<span class="br0">&#91;</span><span class="nu0">55</span><span class="br0">&#93;</span> = <span class="st0">&quot;Fifty Five&quot;</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; myDictionary<span class="br0">&#91;</span><span class="nu0">1</span><span class="br0">&#93;</span> = <span class="st0">&quot;One&quot;</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; myDictionary<span class="br0">&#91;</span><span class="nu0">231</span><span class="br0">&#93;</span> = <span class="st0">&quot;Two Hundred and Thirty One&quot;</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="kw2">var</span> myKeys : <span class="kw3">Array</span> = <span class="kw3">this</span>.<span class="me1">extractKeysFrom</span><span class="br0">&#40;</span>myDictionary<span class="br0">&#41;</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="kw3">trace</span><span class="br0">&#40;</span><span class="st0">&quot;myKeys Array before sort: &quot;</span> + myKeys<span class="br0">&#41;</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="co1">// Apply a Numeric sort to the Array.</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; myKeys.<span class="kw3">sort</span><span class="br0">&#40;</span><span class="kw3">Array</span>.<span class="me1">NUMERIC</span><span class="br0">&#41;</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="kw3">trace</span><span class="br0">&#40;</span><span class="st0">&quot;myKeys Array after sort: &quot;</span> + myKeys<span class="br0">&#41;</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="co1">// You can now use the extracted Keys to read from the Dictionary in</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="co1">// the required order.</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="kw1">for</span> each <span class="br0">&#40;</span><span class="kw2">var</span> thisKey : * <span class="kw1">in</span> myKeys<span class="br0">&#41;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="br0">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="co1">// Will trace out the number followed by the english words.</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="kw3">trace</span><span class="br0">&#40;</span>thisKey + <span class="st0">&quot; = &quot;</span> + myDictionary<span class="br0">&#91;</span>thisKey<span class="br0">&#93;</span><span class="br0">&#41;</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="br0">&#125;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="br0">&#125;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="coMULTI">/**<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;* Helper method to extract the Keys from a Dictionary Object and return<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;* them in an Array.<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;*/</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="kw3">private</span> <span class="kw2">function</span> extractKeysFrom<span class="br0">&#40;</span>source : Dictionary<span class="br0">&#41;</span> : <span class="kw3">Array</span> <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="br0">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="kw2">var</span> output : <span class="kw3">Array</span> = <span class="br0">&#91;</span><span class="br0">&#93;</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="co1">// Note that Dictionary&#8217;s Keys are untyped as they can contain</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="co1">// any value.</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="kw1">for</span> <span class="br0">&#40;</span><span class="kw2">var</span> prop : * <span class="kw1">in</span> source<span class="br0">&#41;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="br0">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; output.<span class="kw3">push</span><span class="br0">&#40;</span>prop<span class="br0">&#41;</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="br0">&#125;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="kw1">return</span> output;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="br0">&#125;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span class="br0">&#125;</span><br />
<span class="br0">&#125;</span><br />
&nbsp;</div>
]]></content:encoded>
			<wfw:commentRss>http://www.jonnyreeves.co.uk/2009/06/sorting-values-stored-in-a-dictionary/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Sorting values in ActionScript 3</title>
		<link>http://www.jonnyreeves.co.uk/2009/05/sorting-values-in-actionscript-3/</link>
		<comments>http://www.jonnyreeves.co.uk/2009/05/sorting-values-in-actionscript-3/#comments</comments>
		<pubDate>Sat, 23 May 2009 15:05:51 +0000</pubDate>
		<dc:creator>Jonny</dc:creator>
				<category><![CDATA[ActionScript 3]]></category>

		<guid isPermaLink="false">http://www.jonnyreeves.co.uk/?p=91</guid>
		<description><![CDATA[One of the next big projects at work will involve displaying a list of data to the user, this list will be generated server side and sent down as un-ordered XML, it is up to the client to sort the data and display it to the user.  The system will need to be able [...]]]></description>
			<content:encoded><![CDATA[<p>One of the next big projects at work will involve displaying a list of data to the user, this list will be generated server side and sent down as un-ordered XML, it is up to the client to sort the data and display it to the user.  The system will need to be able to sort a large amount of data (at present, the server could be sending down up to 10,000 records) and we needed to find out if this sorting would be fiesable &#8211; to find out, I set up a quick little test script which provides a couple of interesting findings:</p>
<div class="dean_ch" style="white-space: nowrap; overflow: scroll;">
package <br />
<span class="br0">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span class="kw3">import</span> flash.<span class="me1">display</span>.<span class="me1">Sprite</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span class="kw3">import</span> flash.<span class="me1">utils</span>.<span class="me1">Dictionary</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span class="kw3">import</span> flash.<span class="me1">utils</span>.<span class="kw3">getTimer</span>;</p>
<p>&nbsp; &nbsp; &nbsp; &nbsp; <span class="coMULTI">/**<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;* @author Jonny<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;*/</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span class="kw3">public</span> <span class="kw2">class</span> Sorting <span class="kw3">extends</span> Sprite<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span class="br0">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="kw3">public</span> <span class="kw2">function</span> Sorting<span class="br0">&#40;</span><span class="br0">&#41;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="br0">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="kw2">var</span> source1 : <span class="kw3">Array</span> = <span class="kw3">this</span>.<span class="me1">generateViaIndexOf</span><span class="br0">&#40;</span><span class="nu0">10000</span><span class="br0">&#41;</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="kw2">var</span> source2 : <span class="kw3">Array</span> = <span class="kw3">this</span>.<span class="me1">generateViaDictionary</span><span class="br0">&#40;</span><span class="nu0">10000</span>, <span class="kw2">false</span><span class="br0">&#41;</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="kw2">var</span> source3 : <span class="kw3">Array</span> = <span class="kw3">this</span>.<span class="me1">generateViaDictionary</span><span class="br0">&#40;</span><span class="nu0">10000</span>, <span class="kw2">true</span><span class="br0">&#41;</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="kw3">this</span>.<span class="kw3">sort</span><span class="br0">&#40;</span>source1, <span class="kw3">Array</span>.<span class="me1">NUMERIC</span><span class="br0">&#41;</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="kw3">this</span>.<span class="kw3">sort</span><span class="br0">&#40;</span>source2, <span class="kw3">Array</span>.<span class="me1">NUMERIC</span><span class="br0">&#41;</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="kw3">this</span>.<span class="kw3">sort</span><span class="br0">&#40;</span>source3, <span class="kw3">Array</span>.<span class="me1">NUMERIC</span><span class="br0">&#41;</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; debugOutput<span class="br0">&#40;</span><span class="st0">&quot;indexOf&quot;</span>, source1<span class="br0">&#41;</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; debugOutput<span class="br0">&#40;</span><span class="st0">&quot;nonCast&quot;</span>, source2<span class="br0">&#41;</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; debugOutput<span class="br0">&#40;</span><span class="st0">&quot;cast&quot;</span>, source3<span class="br0">&#41;</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="br0">&#125;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="kw3">private</span> <span class="kw2">function</span> debugOutput<span class="br0">&#40;</span><span class="kw3">name</span> : <span class="kw3">String</span>, values : <span class="kw3">Array</span><span class="br0">&#41;</span> : <span class="kw3">void</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="br0">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="kw3">trace</span><span class="br0">&#40;</span><span class="kw3">name</span> + <span class="st0">&quot;[0] = &quot;</span> + values<span class="br0">&#91;</span><span class="nu0">0</span><span class="br0">&#93;</span> + <span class="st0">&quot;, &quot;</span> + <span class="kw3">name</span> + <span class="st0">&quot;[1] = &quot;</span> + values<span class="br0">&#91;</span><span class="nu0">1</span><span class="br0">&#93;</span><span class="br0">&#41;</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="br0">&#125;</span></p>
<p>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="kw3">private</span> <span class="kw2">function</span> <span class="kw3">sort</span><span class="br0">&#40;</span>source : <span class="kw3">Array</span>, sortMethod : uint<span class="br0">&#41;</span> : <span class="kw3">void</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="br0">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="kw2">var</span> startTime : uint = <span class="kw3">getTimer</span><span class="br0">&#40;</span><span class="br0">&#41;</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; source.<span class="kw3">sort</span><span class="br0">&#40;</span>sortMethod<span class="br0">&#41;</span>;&nbsp; &nbsp; &nbsp; &nbsp; <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="kw3">trace</span><span class="br0">&#40;</span><span class="st0">&quot;Array sorted in &quot;</span> + <span class="br0">&#40;</span><span class="kw3">getTimer</span><span class="br0">&#40;</span><span class="br0">&#41;</span> &#8211; startTime<span class="br0">&#41;</span> + <span class="st0">&quot;ms.&quot;</span><span class="br0">&#41;</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="br0">&#125;</span></p>
<p>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="kw3">private</span> <span class="kw2">function</span> generateViaDictionary<span class="br0">&#40;</span><span class="kw3">length</span> : <span class="kw3">int</span>, castOutput : <span class="kw3">Boolean</span><span class="br0">&#41;</span> : <span class="kw3">Array</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="br0">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="kw2">var</span> startTime : <span class="kw3">int</span> = <span class="kw3">getTimer</span><span class="br0">&#40;</span><span class="br0">&#41;</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="kw2">var</span> pushed : <span class="kw3">Boolean</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="kw2">var</span> dictionary : Dictionary = <span class="kw2">new</span> Dictionary<span class="br0">&#40;</span><span class="br0">&#41;</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="kw1">while</span> <span class="br0">&#40;</span>length&#8211;<span class="br0">&#41;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="br0">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; pushed = <span class="kw2">false</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="kw1">while</span> <span class="br0">&#40;</span>!pushed<span class="br0">&#41;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="br0">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="kw2">var</span> thisRand : uint = <span class="kw3">Math</span>.<span class="kw3">ceil</span><span class="br0">&#40;</span><span class="kw3">Math</span>.<span class="kw3">random</span><span class="br0">&#40;</span><span class="br0">&#41;</span> * <span class="nu0">100000000</span><span class="br0">&#41;</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="kw1">if</span> <span class="br0">&#40;</span>dictionary<span class="br0">&#91;</span>thisRand<span class="br0">&#93;</span> == <span class="kw3">undefined</span><span class="br0">&#41;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="br0">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; dictionary<span class="br0">&#91;</span>thisRand<span class="br0">&#93;</span> = <span class="kw2">true</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; pushed = <span class="kw2">true</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="br0">&#125;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="br0">&#125;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="br0">&#125;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="kw2">var</span> output : <span class="kw3">Array</span> = <span class="br0">&#91;</span><span class="br0">&#93;</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="kw1">for</span> <span class="br0">&#40;</span><span class="kw2">var</span> prop : <span class="kw3">String</span> <span class="kw1">in</span> dictionary<span class="br0">&#41;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="br0">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="kw1">if</span> <span class="br0">&#40;</span>castOutput<span class="br0">&#41;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="br0">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; output.<span class="kw3">push</span><span class="br0">&#40;</span><span class="kw3">parseInt</span><span class="br0">&#40;</span>prop<span class="br0">&#41;</span><span class="br0">&#41;</span>;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="br0">&#125;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="kw1">else</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="br0">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; output.<span class="kw3">push</span><span class="br0">&#40;</span>prop<span class="br0">&#41;</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="br0">&#125;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="br0">&#125;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="kw3">trace</span><span class="br0">&#40;</span><span class="st0">&quot;Source Array containing &quot;</span> + output.<span class="kw3">length</span> + <span class="st0">&quot; items created in &quot;</span> + <span class="br0">&#40;</span><span class="kw3">getTimer</span><span class="br0">&#40;</span><span class="br0">&#41;</span> &#8211; startTime<span class="br0">&#41;</span> + <span class="st0">&quot;ms.&quot;</span><span class="br0">&#41;</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="kw1">return</span> output;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="br0">&#125;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="kw3">private</span> <span class="kw2">function</span> generateViaIndexOf<span class="br0">&#40;</span><span class="kw3">length</span> : <span class="kw3">int</span><span class="br0">&#41;</span> : <span class="kw3">Array</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="br0">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="kw2">var</span> startTime : uint = <span class="kw3">getTimer</span><span class="br0">&#40;</span><span class="br0">&#41;</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="kw2">var</span> pushed : <span class="kw3">Boolean</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="kw2">var</span> output : <span class="kw3">Array</span> = <span class="br0">&#91;</span><span class="br0">&#93;</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="kw1">while</span> <span class="br0">&#40;</span>length&#8211;<span class="br0">&#41;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="br0">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; pushed = <span class="kw2">false</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="kw1">while</span> <span class="br0">&#40;</span>!pushed<span class="br0">&#41;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="br0">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="kw2">var</span> thisRand : uint = <span class="kw3">Math</span>.<span class="kw3">ceil</span><span class="br0">&#40;</span><span class="kw3">Math</span>.<span class="kw3">random</span><span class="br0">&#40;</span><span class="br0">&#41;</span> * <span class="nu0">100000000</span><span class="br0">&#41;</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="kw1">if</span> <span class="br0">&#40;</span>output.<span class="kw3">indexOf</span><span class="br0">&#40;</span>thisRand<span class="br0">&#41;</span> == <span class="nu0">-1</span><span class="br0">&#41;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="br0">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; output.<span class="kw3">push</span><span class="br0">&#40;</span>thisRand<span class="br0">&#41;</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; pushed = <span class="kw2">true</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="br0">&#125;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="br0">&#125;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="br0">&#125;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="kw3">trace</span><span class="br0">&#40;</span><span class="st0">&quot;Source Array containing &quot;</span> + output.<span class="kw3">length</span> + <span class="st0">&quot; items created in &quot;</span> + <span class="br0">&#40;</span><span class="kw3">getTimer</span><span class="br0">&#40;</span><span class="br0">&#41;</span> &#8211; startTime<span class="br0">&#41;</span> + <span class="st0">&quot;ms.&quot;</span><span class="br0">&#41;</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="kw1">return</span> output;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="br0">&#125;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span class="br0">&#125;</span><br />
<span class="br0">&#125;</span><br />
&nbsp;</div>
<p>When run, this code produces the following output:</p>
<pre>
Source Array containing 10000 items created in 3082ms.
Source Array containing 10000 items created in 71ms.
Source Array containing 10000 items created in 102ms.
Array sorted in 19ms.
Array sorted in 312ms.
Array sorted in 17ms.
indexOf[0] = 4532, indexOf[1] = 14806
nonCast[0] = 3553, nonCast[1] = 6646
cast[0] = 10432, cast[1] = 22513
</pre>
<p>We can immediatley draw the conclusion that performing Array.indexOf to determine if a value is unique in a given array is woefully inefficient, the use of a Dictionary (serving as a lookup table) is much better.  The other interesting point is that Array.sort(Array.NUMERIC) works quicker if the source values are cast to integers (instead of the Strings a for&#8230;var&#8230;in loop produces).</p>
<p>For those interested, my final stratergy will be to parse the data returned from the Service layer into strongly typed Objects and then store these in a Dictionary mapping User.id => User Object, then when I need to perform a sort I can simply dump the keys from the Dictionary into an Array.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.jonnyreeves.co.uk/2009/05/sorting-values-in-actionscript-3/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Using Dictionary Objects to Map Classes and Instances</title>
		<link>http://www.jonnyreeves.co.uk/2009/03/using-dictionary-objects-to-map-classes-and-instances/</link>
		<comments>http://www.jonnyreeves.co.uk/2009/03/using-dictionary-objects-to-map-classes-and-instances/#comments</comments>
		<pubDate>Thu, 19 Mar 2009 23:05:09 +0000</pubDate>
		<dc:creator>Jonny</dc:creator>
				<category><![CDATA[ActionScript 3]]></category>

		<guid isPermaLink="false">http://www.jonnyreeves.co.uk/?p=75</guid>
		<description><![CDATA[This is a neat little ActionScript 3 trick which I&#8217;ve been using more and more of recently that I thought I would share.  The basic premise is that it allows you to use a dictionary which maps Classes to other data, the twist is that you can supply either the Class definition or an instance [...]]]></description>
			<content:encoded><![CDATA[<p>This is a neat little ActionScript 3 trick which I&#8217;ve been using more and more of recently that I thought I would share.  The basic premise is that it allows you to use a dictionary which maps Classes to other data, the twist is that you can supply either the Class definition or an instance of the Class as the key.</p>
<p>The most obvious example I have come across for this is when creating Asset Mappings.  Let&#8217;s say I have a generic Model-esq class, ie: a Car and I know that each instance of Car (Ferrari, Porsche, etc) has an assosiated asset (ie: a SWF file).  These assets are stored on the server and use the <em>name</em> property as part of that assets filename, for example:</p>
<ul>
<li>Ferrari maps to /flash/assets/cars/ferrari.swf</li>
<li>Porsche maps to /flash/assets/cars/porsche.swf</li>
</ul>
<p>Now, it&#8217;s clear that the &#8220;/flash/assets/cars/&#8221; part of the URL is common to all instances of the Car class and we can leverage this fact when building URLs with the help of a URLManager Class and a common interface that all Model objects which contain Asset Paths share:</p>
<p><strong>Car Class</strong></p>
<div class="dean_ch" style="white-space: nowrap; overflow: scroll;">
package uk.<span class="me1">co</span>.<span class="me1">jonnyreeves</span>.<span class="me1">classmapping</span> <span class="br0">&#123;</span></p>
<p>&nbsp; &nbsp; &nbsp; &nbsp; <span class="coMULTI">/**<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;* Example Model Class for a Car<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;*/</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span class="kw3">public</span> <span class="kw2">class</span> Car <span class="kw3">implements</span> IContainsAssetPath<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span class="br0">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="coMULTI">/**<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;* The name of this Car.<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;*/</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="kw3">private</span> <span class="kw2">var</span> <span class="kw3">name</span> : <span class="kw3">String</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="coMULTI">/**<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;* Constructor.<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;* @param name&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; The name of this car.<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;*/</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="kw3">public</span> <span class="kw2">function</span> Car<span class="br0">&#40;</span><span class="kw3">name</span> : <span class="kw3">String</span><span class="br0">&#41;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="br0">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="kw3">this</span>.<span class="kw3">name</span> = <span class="kw3">name</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="br0">&#125;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="coMULTI">/**<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;* Returns the name of this car.<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;*/</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="kw3">public</span> <span class="kw2">function</span> getName<span class="br0">&#40;</span><span class="br0">&#41;</span> : <span class="kw3">String</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="br0">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="kw1">return</span> <span class="kw3">this</span>.<span class="kw3">name</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="br0">&#125;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="coMULTI">/**<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;* Return the filename for this Car&#8217;s Asset SWF.<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;*/</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="kw3">public</span> <span class="kw2">function</span> getAssetPath<span class="br0">&#40;</span><span class="br0">&#41;</span> : <span class="kw3">String</span> <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="br0">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="kw1">return</span> <span class="kw3">this</span>.<span class="kw3">name</span> + <span class="st0">&quot;.swf&quot;</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="br0">&#125;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span class="br0">&#125;</span><br />
<span class="br0">&#125;</span><br />
&nbsp;</div>
<p><b>IContainsAssetPath interface</b></p>
<div class="dean_ch" style="white-space: nowrap; overflow: scroll;">
package uk.<span class="me1">co</span>.<span class="me1">jonnyreeves</span>.<span class="me1">classmapping</span> <span class="br0">&#123;</span></p>
<p>&nbsp; &nbsp; &nbsp; &nbsp; <span class="coMULTI">/**<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;* Common Interface for all Models with Assets<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;*/</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span class="kw3">public</span> <span class="kw3">interface</span> IContainsAssetPath <br />
&nbsp; &nbsp; &nbsp; &nbsp; <span class="br0">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="coMULTI">/**<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;* Returns the final stub path to this asset.<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;*/</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="kw2">function</span> getAssetPath<span class="br0">&#40;</span><span class="br0">&#41;</span> : <span class="kw3">String</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span class="br0">&#125;</span><br />
<span class="br0">&#125;</span><br />
&nbsp;</div>
<p>Finally, the URLManager which will help build the URLs for all Models which implement IContainAssetPath</p>
<p><b>URLManager Class</b></p>
<div class="dean_ch" style="white-space: nowrap; overflow: scroll;">
package uk.<span class="me1">co</span>.<span class="me1">jonnyreeves</span>.<span class="me1">classmapping</span> <br />
<span class="br0">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span class="kw3">import</span> flash.<span class="me1">utils</span>.<span class="me1">Dictionary</span>;&nbsp; </p>
<p>&nbsp; &nbsp; &nbsp; &nbsp; <span class="coMULTI">/**<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;* Helper for building URLs from Car Objects.<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;*/</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span class="kw3">public</span> <span class="kw2">class</span> URLManager <span class="br0">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="coMULTI">/**<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;* Dictionary which will contain mappings between Class Definitions<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;* and URL Stubs used to build asset paths.<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;*/</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="kw3">private</span> <span class="kw3">static</span> <span class="kw2">var</span> objectMappings : Dictionary = <span class="kw2">new</span> Dictionary<span class="br0">&#40;</span><span class="br0">&#41;</span>;</p>
<p>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="coMULTI">/**<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;* Singleton Instance.<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;*/</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="kw3">private</span> <span class="kw3">static</span> <span class="kw2">var</span> instance : URLManager;</p>
<p>
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="coMULTI">/**<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;* Singleton Accessor Method.<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;*/</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="kw3">public</span> <span class="kw3">static</span> <span class="kw2">function</span> getInstance<span class="br0">&#40;</span><span class="br0">&#41;</span> : URLManager<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="br0">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="kw1">if</span> <span class="br0">&#40;</span>instance == <span class="kw2">null</span><span class="br0">&#41;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="br0">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; instance = <span class="kw2">new</span> URLManager<span class="br0">&#40;</span><span class="br0">&#41;</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="br0">&#125;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="kw1">return</span> instance;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="br0">&#125;</span></p>
<p>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="coMULTI">/**<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;* Private Constructor for Singleton Pattern.<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;*/</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="kw3">public</span> <span class="kw2">function</span> URLManager<span class="br0">&#40;</span><span class="br0">&#41;</span> <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="br0">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; createObjectMappings<span class="br0">&#40;</span><span class="br0">&#41;</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="br0">&#125;</span></p>
<p>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="coMULTI">/**<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;* Populate the ObjectMappings Dictionary.<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;*/</span>&nbsp; &nbsp; &nbsp;&nbsp; &nbsp; &nbsp; &nbsp; <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="kw3">private</span> <span class="kw2">function</span> createObjectMappings<span class="br0">&#40;</span><span class="br0">&#41;</span> : <span class="kw3">void</span> <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="br0">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="co1">// Here we create relationships between the Class definitions and their</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="co1">// URL Stubs. &nbsp;We use the constructor object to create a common relation</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="co1">// between ClassDefinitions and instances of those Class Definitions.</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; objectMappings<span class="br0">&#91;</span>Car.<span class="kw3">prototype</span>.<span class="kw3">constructor</span><span class="br0">&#93;</span> = <span class="st0">&quot;/flash/assets/cars/&quot;</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="br0">&#125;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="coMULTI">/**<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;* Retrieve the AssetURL for the supplied instance of the IContainsAssetPath interface<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;*/</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="kw3">public</span> <span class="kw2">function</span> getAssetURL<span class="br0">&#40;</span>source : IContainsAssetPath<span class="br0">&#41;</span> : <span class="kw3">String</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="br0">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="co1">// Here we can extract the constructor object from the incoming IContainsAssetPath</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="co1">// implementation. &nbsp;This will be the same object as the one we stored in </span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="co1">// this.createObjectMappings();</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="kw2">var</span> sourceConstructor : <span class="kw3">Object</span> = <span class="br0">&#40;</span>source as <span class="kw3">Object</span><span class="br0">&#41;</span>.<span class="kw3">constructor</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="co1">// Check to see if a mapping exists for this Class Definition.</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="kw1">if</span> <span class="br0">&#40;</span>objectMappings<span class="br0">&#91;</span>sourceConstructor<span class="br0">&#93;</span> == <span class="kw3">undefined</span><span class="br0">&#41;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="br0">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="kw3">throw</span> <span class="kw2">new</span> <span class="kw3">Error</span><span class="br0">&#40;</span><span class="st0">&quot;Asset Mapping does not exist for object: &quot;</span> + source<span class="br0">&#41;</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="br0">&#125;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="co1">// We can now build the complete URL.</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="kw1">return</span> objectMappings<span class="br0">&#91;</span>sourceConstructor<span class="br0">&#93;</span> + source.<span class="me1">getAssetPath</span><span class="br0">&#40;</span><span class="br0">&#41;</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="br0">&#125;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span class="br0">&#125;</span><br />
<span class="br0">&#125;</span><br />
&nbsp;</div>
<p>The technique relies on the fact that the Class Definition&#8217;s prototype will yield the same constructor object as the instance of that Class Definition.  This has come in incredibly handy when I only have the Class Definitions avaliable to me whilst writing code but need to create mappings to them at run-time.  For those that want a complete the example, <a href="http://www.jonnyreeves.co.uk/wp-content/uploads/2009/03/classmapping-source.zip">here is the source</a>.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.jonnyreeves.co.uk/2009/03/using-dictionary-objects-to-map-classes-and-instances/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>MoshiMonsters.com Homepage Redesign</title>
		<link>http://www.jonnyreeves.co.uk/2009/03/moshimonsterscom-homepage-redesign/</link>
		<comments>http://www.jonnyreeves.co.uk/2009/03/moshimonsterscom-homepage-redesign/#comments</comments>
		<pubDate>Tue, 10 Mar 2009 21:07:06 +0000</pubDate>
		<dc:creator>Jonny</dc:creator>
				<category><![CDATA[ActionScript 3]]></category>
		<category><![CDATA[Personal]]></category>

		<guid isPermaLink="false">http://www.jonnyreeves.co.uk/?p=69</guid>
		<description><![CDATA[As some of you may know, I am currently working for MindCandy as an ActionScript 3 developer hacking away on Moshi Monsters &#8211; a safe, online world for kids to learn and play.  This week is a very proud one for myself as the homepage redesign which I worked on went live &#8211; I thought [...]]]></description>
			<content:encoded><![CDATA[<p>As some of you may know, I am currently working for <a href="http://mindcandy.com/">MindCandy</a> as an ActionScript 3 developer hacking away on <a href="http://moshimonsters.com/">Moshi Monsters</a> &#8211; a safe, online world for kids to learn and play.  This week is a very proud one for myself as the homepage redesign which I worked on went live &#8211; I thought I would take the opportunity to explain some of the problems faced and the solutions used.</p>
<p style="text-align: left;">
<p style="text-align: center;"><a href="http://moshimonsters.com/"><img class="size-full wp-image-70 aligncenter" title="MoshiMonsters.com Homepage, March 2009" src="http://www.jonnyreeves.co.uk/wp-content/uploads/2009/03/moshi-homepage.jpg" alt="MoshiMonsters.com Homepage, March 2009" width="500" height="280" /></a></p>
<p style="text-align: left;">First off I need to give full credit where it&#8217;s due; to our amazing designers.  I got to work with three such talented chaps on this project, <a href="http://mindcandy.com/people/#trev">Trevor</a>, <a href="http://mindcandy.com/people/#benp">Ben P</a>. and our latest hire, Axel.  These guys spent a good week illustrating the concept for the new homepage and creating the animations and elements which I wired up to make the finished product.</p>
<p style="text-align: left;">The page splits into two parts, the main body and the navigation is delivered in normal HTML with CSS styling and the central content including the monsters and ocean background are delivered using Flash.  One of the challenges to over-come was the fact the page had to scale horizontally to allow the user to resize their browser, this was achieved by using the ActionScript <a href="http://livedocs.adobe.com/flash/9.0/ActionScriptLangRefV3/flash/display/Stage.html#scaleMode">StageScale.NO_SCALE</a> setting and using <a href="http://code.google.com/p/swfobject/">SWFObject</a> to set the embed width to 100%.  By <a href="http://livedocs.adobe.com/flash/9.0/ActionScriptLangRefV3/flash/display/Stage.html#event:resize">registering an Event.RESIZE  listener to the Stage</a>, I am able to adjust the width property of the background gradients&#8217; (which make up the ocean) DisplayObject.  It&#8217;s awesome to see the site still look great even when stretched across two 24&#8243; monitors!</p>
<p style="text-align: left;">One of the key points of the new homepage&#8217;s <a href="http://en.wikipedia.org/wiki/Acceptance_testing">Acceptance Test</a> was that it weighed around the same as the static HTML version it was replacing.  Using <a href="http://getfirebug.com/">firebug</a>, I was able to tell that the original homepage weighed ~360kb; it wasn&#8217;t going to be easy providing all this interactivity.  We managed to come in at ~430kb which wasn&#8217;t too far off!  We made savings filesize savings on both the HTML and Flash by a combination of <a href="http://www.alistapart.com/articles/sprites/">CSS Spriting</a> and optimisation of all animations and MovieClips (the majority of the Flash optimisations were done by our Animator Ben P. so you will have to ask him for his tips and tricks!).  We didn&#8217;t go down the route of trying to optimise the ActionScript to reduce filesize as legibility is more important to us than a couple of kilobytes at the CDN.</p>
<p style="text-align: left;">Finally, the last goal of the new site was that it displayed on the user screen as quickly as possible &#8211; the last thing we wan the user to see is a massive white hole in the middle of our page whilst it loads!  Pre-Loaders in ActionScript 3 are not quite as intuitive as they used to be in AS2, but thanks to <a href="http://www.bit-101.com/blog/?p=946">Keith over at Bit-101, they are reliviley straight forward once you know what you&#8217;re doing</a>!  During the Preloader we render the background gradients in actionscript which helps the Flash element fit seamlessly with the HTML and CSS while the remaining 200kb loads.  Once the app has finished loading, the user can start interacting with the buttons, watch the tour video, etc.  At this point, we send off a background call to load in the monster animations and sound effects.  The monster anims are all contained in a single swf which weighs in around 130kb &#8211; we chose to use a single swf to reduce the number of requests on the web server (infact the entire page now renders in under 15 requests to our own server, down from well over 30!).  The monster animations SWF contains linkages for all the various animations &#8211; these are loaded into the <a href="http://help.adobe.com/en_US/AS3LCR/Flash_10.0/flash/system/ApplicationDomain.html">Current ApplicationDomain</a> and then initialised via<a href="http://thillerson.wordpress.com/2007/03/01/runtime-class-instantiation-in-actionscript-30/"> getDefinitionByName</a>.</p>
<p style="text-align: left;">If you are already a Moshi user then I hope you enjoy the new MoshiMonsters homepage and all the new features that our team keeps working on &#8211; and if you&#8217;re not yet a member, well get on over there and adopt one today!</p>
]]></content:encoded>
			<wfw:commentRss>http://www.jonnyreeves.co.uk/2009/03/moshimonsterscom-homepage-redesign/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
