<?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>dispatchEvent() Blog™ &#187; AS3</title>
	<atom:link href="http://dispatchevent.org/category/as3/feed/" rel="self" type="application/rss+xml" />
	<link>http://dispatchevent.org</link>
	<description>Collective thoughts on the Flash Platform, iOS, Unity, and any other technology we use.</description>
	<lastBuildDate>Wed, 18 Jan 2012 19:16:58 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.2.1</generator>
		<item>
		<title>Snippet Saturday: quick random choice</title>
		<link>http://dispatchevent.org/mims/snippet-saturday-quick-random-choice/</link>
		<comments>http://dispatchevent.org/mims/snippet-saturday-quick-random-choice/#comments</comments>
		<pubDate>Sun, 20 Mar 2011 20:05:22 +0000</pubDate>
		<dc:creator>Mims H Wright</dc:creator>
				<category><![CDATA[AS3]]></category>
		<category><![CDATA[Snippets]]></category>
		<category><![CDATA[Tips, Tricks, and Hacks]]></category>
		<category><![CDATA[snippet]]></category>

		<guid isPermaLink="false">http://dispatchevent.org/?p=877</guid>
		<description><![CDATA[Today&#8217;s Snippet Saturday (actually, Sunday) is a quick shortcut for choosing one of several strings, objects, etc. randomly. Now, I wouldn&#8217;t really recommend using this code in a project. There are ways to do the same thing that are much &#8230; <a href="http://dispatchevent.org/mims/snippet-saturday-quick-random-choice/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>Today&#8217;s Snippet Saturday (actually, Sunday) is a quick shortcut for choosing one of several strings, objects, etc. randomly. </p>
<p><script src="https://gist.github.com/878605.js?file=randomChoice.as"></script></p>
<p>Now, I wouldn&#8217;t really recommend using this code in a project. There are ways to do the same thing that are much more readable and less error prone. Instead, I thought it was an interesting experiment to show off some of how AS3&#8242;s syntax works for those of you who may not have seen something like this. </p>
<p>What&#8217;s happening here? Let&#8217;s break it down.</p>
<ul>
<li><code>["Alpha", "Bravo", "Charlie"]</code> &#8211; Here we are instantiating a new array and populating it with three strings. This is essentially the same as:
<pre>
var a:Array = new Array();
a[0] = "Alpha";
a[1] = "Bravo";
a[2] = "Charlie";
</pre>
</li>
<li><code>[...]</code> &#8211; next is another pair of square brackets. This is an <a href="http://www.adobe.com/livedocs/flash/9.0/ActionScriptLangRefV3/operators.html#array_access">array access operator</a>. In other words, everything between the two brackets will be evaluated as the index of the array to retrieve.</li>
<li><code>int(..</code>.) &#8211; This is an <a href="http://www.adobe.com/livedocs/flash/9.0/main/wwhelp/wwhimpl/common/html/wwhelp.htm?context=LiveDocs_Parts&#038;file=00000048.html">explicit type-cast to an int</a>. That means that everything inside those parentheses is evaluated and flash attempts to convert from whatever data type it is to an integer. In the case of decimal numbers, they are rounded down so this is similar to using <code>Math.floor()</code>.</li>
<li><code>Math.random() * 3</code> &#8211; random() of course produces a random floating point (decimal) number between 0.0 and (almost but not quite) 1.0. Multiplying that number by 3 (the length of the array) produces a number between 0.0 and 3.0 (technically, between 0 and 2.99999999etc).</li>
</ul>
<p>The result, an array is created with three strings, a random number between 0.0 and (almost) 3.0 is generated, it is rounded down to an int between 0 and 2, that number is used as the index of the array to look up. The result will be randomly one of the three strings. </p>
<p>I hope you found this interesting!</p>
]]></content:encoded>
			<wfw:commentRss>http://dispatchevent.org/mims/snippet-saturday-quick-random-choice/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Snippet Saturday: isRoughlyEqual()  PLUS: as3-utils</title>
		<link>http://dispatchevent.org/mims/snippet-saturday-isroughlyequal-plus-as3-utils/</link>
		<comments>http://dispatchevent.org/mims/snippet-saturday-isroughlyequal-plus-as3-utils/#comments</comments>
		<pubDate>Sat, 12 Mar 2011 14:11:19 +0000</pubDate>
		<dc:creator>Mims H Wright</dc:creator>
				<category><![CDATA[AS3]]></category>
		<category><![CDATA[Snippets]]></category>
		<category><![CDATA[fuzzy]]></category>
		<category><![CDATA[isRoughlyEqual]]></category>
		<category><![CDATA[math]]></category>

		<guid isPermaLink="false">http://dispatchevent.org/?p=879</guid>
		<description><![CDATA[Last week, I started a (hopefully) weekly post where I throw out a (hopefully) useful piece of code for people to (hopefully) use in their projects. I&#8217;m calling this #SnippetSaturday. John Lindquist commented almost immediately that there is a project &#8230; <a href="http://dispatchevent.org/mims/snippet-saturday-isroughlyequal-plus-as3-utils/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>Last week, I started a (hopefully) weekly post where I throw out a (hopefully) useful piece of code for people to (hopefully) use in their projects. I&#8217;m calling this #SnippetSaturday. </p>
<p><a href="http://johnlindquist.com/">John Lindquist</a> commented almost immediately that there is a project on github designed to collect these sorts of useful little snippets of code. It&#8217;s called <a href="https://github.com/as3/as3-utils">as3-utils</a>. Check it out!</p>
<p>This week&#8217;s snippet, isRoughlyEqual(), provides a simple way to find out if two numbers are in the ballpark of each other.</p>
<p><script src="https://gist.github.com/857563.js?file=isRoughlyEqual.as"></script></p>
<p>I&#8217;ve added it to the as3-utils project too.<br />
<a href="http://github.com/mimshwright/as3-utils/blob/master/src/utils/number/isRoughlyEqual.as">http://github.com/mimshwright/as3-utils/blob/master/src/utils/number/isRoughlyEqual.as</a></p>
]]></content:encoded>
			<wfw:commentRss>http://dispatchevent.org/mims/snippet-saturday-isroughlyequal-plus-as3-utils/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Snippet Saturday: limit() function</title>
		<link>http://dispatchevent.org/mims/snippet-saturday-limit-function/</link>
		<comments>http://dispatchevent.org/mims/snippet-saturday-limit-function/#comments</comments>
		<pubDate>Sun, 06 Mar 2011 02:14:59 +0000</pubDate>
		<dc:creator>Mims H Wright</dc:creator>
				<category><![CDATA[AS3]]></category>
		<category><![CDATA[Snippets]]></category>
		<category><![CDATA[code]]></category>
		<category><![CDATA[gist]]></category>
		<category><![CDATA[math]]></category>
		<category><![CDATA[snippet-saturday]]></category>

		<guid isPermaLink="false">http://dispatchevent.org/?p=878</guid>
		<description><![CDATA[So I&#8217;m sitting on a bunch of pretty useful code and I&#8217;m not sure how to share it with people. I could create a massive library that combines all the miscellaneous bits into a single, poorly documented library, but after &#8230; <a href="http://dispatchevent.org/mims/snippet-saturday-limit-function/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>So I&#8217;m sitting on a bunch of pretty useful code and I&#8217;m not sure how to share it with people. I could create a massive library that combines all the miscellaneous bits into a <a href="http://code.google.com/p/as3lib/">single, poorly documented library</a>, but after looking at the <a href="http://flashgamedojo.com/wiki/index.php?title=Category:Snippets">Flash Game Dojo&#8217;s wiki</a>, I&#8217;m starting to believe more strongly in the idea of releasing code in smaller pieces that achieve a particular function. So, I&#8217;m going to try to kick off this idea of <a href="http://twitter.com/#!/search/%23SnippetSaturday">#SnippetSaturday</a>. I&#8217;m sure I won&#8217;t manage to post something every week but I&#8217;ll do my best. If you&#8217;ve got a blog or just twitter, I&#8217;d encourage you to join in too!</p>
<p>Anyway, here&#8217;s my first contribution. It&#8217;s a simple little function that limits a number between an upper and lower limit.</p>
<p><script src="https://gist.github.com/856948.js?file=limit.as"></script></p>
<p>BTW, I used <a href="https://gist.github.com/">gist.github.com</a> for this but <a href="http://snipplr.com">snipplr</a> is good too. If you know of others, leave a comment!</p>
]]></content:encoded>
			<wfw:commentRss>http://dispatchevent.org/mims/snippet-saturday-limit-function/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>Matryoshka Functions</title>
		<link>http://dispatchevent.org/mims/matryoshka-functions/</link>
		<comments>http://dispatchevent.org/mims/matryoshka-functions/#comments</comments>
		<pubDate>Fri, 07 Jan 2011 19:22:40 +0000</pubDate>
		<dc:creator>Mims H Wright</dc:creator>
				<category><![CDATA[AS3]]></category>
		<category><![CDATA[Objective-C]]></category>
		<category><![CDATA[Programming]]></category>
		<category><![CDATA[Tips, Tricks, and Hacks]]></category>

		<guid isPermaLink="false">http://dispatchevent.org/?p=869</guid>
		<description><![CDATA[The other day, I was working with the Flex function BindingUtil.bindProperty(). I always have a hard time remembering which pair of arguments comes first, the &#8216;site&#8217; or the &#8216;host&#8217; and to be honest, the names don&#8217;t really make much sense &#8230; <a href="http://dispatchevent.org/mims/matryoshka-functions/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p><a href="http://dispatchevent.org/wp-content/uploads/2011/01/First-matryoshka-museum-doll-open.jpeg"><img src="http://dispatchevent.org/wp-content/uploads/2011/01/First-matryoshka-museum-doll-open-300x211.jpg" alt="" width="300" height="211" class="alignnone size-medium wp-image-870" /></a><br />
The other day, I was working with the Flex function BindingUtil.bindProperty(). I always have a hard time remembering which pair of arguments comes first, the &#8216;site&#8217; or the &#8216;host&#8217; and to be honest, the names don&#8217;t really make much sense to me. &#8220;Oh, if only this were an Objective-C project I would have to laboriously type out each name of each parameter.&#8221; I thought, &#8220;It would be so much more obvious if it were writen like <code>Bind.property("foo").fromObject(bar).toTheValueOfProperty("foo").ofObject(baz);</code>.&#8221; </p>
<p>What followed was the discovery/invention of just such a thing, a nested, super-verbose function. The function achieves this by returning an instance of an internal class with nothing in it except for the next step in the chain.</p>

<div class="wp_codebox_msgheader wp_codebox_hide"><span class="right"><sup><a href="http://www.ericbess.com/ericblog/2008/03/03/wp-codebox/#examples" target="_blank" title="WP-CodeBox HowTo?"><span style="color: #99cc00">?</span></a></sup></span><span class="left"><a href="javascript:;" onclick="javascript:showCodeTxt('p869code5'); return false;">View Code</a> ACTIONSCRIPT3</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table><tr id="p8695"><td class="code" id="p869code5"><pre class="actionscript3" style="font-family:monospace;"><span style="color: #9900cc; font-weight: bold;">package</span>
<span style="color: #000000;">&#123;</span>
	<span style="color: #0033ff; font-weight: bold;">public</span> <span style="color: #9900cc; font-weight: bold;">class</span> Bind
	<span style="color: #000000;">&#123;</span>
		<span style="color: #0033ff; font-weight: bold;">public</span> static <span style="color: #339966; font-weight: bold;">function</span> updateProperty<span style="color: #000000;">&#40;</span>object<span style="color: #000066; font-weight: bold;">:</span><a href="http://www.google.com/search?q=object%20inurl:http://livedocs.adobe.com/flex/201/langref/%20inurl:object.html"><span style="color: #004993;">Object</span></a><span style="color: #000066; font-weight: bold;">,</span> property<span style="color: #000066; font-weight: bold;">:</span><a href="http://www.google.com/search?q=string%20inurl:http://livedocs.adobe.com/flex/201/langref/%20inurl:string.html"><span style="color: #004993;">String</span></a><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">:</span>BindSource <span style="color: #000000;">&#123;</span>
			<span style="color: #0033ff; font-weight: bold;">return</span> <span style="color: #0033ff; font-weight: bold;">new</span> BindSource<span style="color: #000000;">&#40;</span>object<span style="color: #000066; font-weight: bold;">,</span> property<span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>
		<span style="color: #000000;">&#125;</span>
	<span style="color: #000000;">&#125;</span>
<span style="color: #000000;">&#125;</span>
<span style="color: #0033ff; font-weight: bold;">import</span> mx<span style="color: #000066; font-weight: bold;">.</span>binding<span style="color: #000066; font-weight: bold;">.</span>utils<span style="color: #000066; font-weight: bold;">.</span>BindingUtils<span style="color: #000066; font-weight: bold;">;</span>
<span style="color: #9900cc; font-weight: bold;">class</span> BindSource <span style="color: #000000;">&#123;</span>
&nbsp;
	<span style="color: #0033ff; font-weight: bold;">private</span> <span style="color: #6699cc; font-weight: bold;">var</span> targetObject<span style="color: #000066; font-weight: bold;">:</span><a href="http://www.google.com/search?q=object%20inurl:http://livedocs.adobe.com/flex/201/langref/%20inurl:object.html"><span style="color: #004993;">Object</span></a><span style="color: #000066; font-weight: bold;">;</span>
	<span style="color: #0033ff; font-weight: bold;">private</span> <span style="color: #6699cc; font-weight: bold;">var</span> targetProperty<span style="color: #000066; font-weight: bold;">:</span><a href="http://www.google.com/search?q=string%20inurl:http://livedocs.adobe.com/flex/201/langref/%20inurl:string.html"><span style="color: #004993;">String</span></a><span style="color: #000066; font-weight: bold;">;</span>
&nbsp;
	<span style="color: #0033ff; font-weight: bold;">public</span> <span style="color: #339966; font-weight: bold;">function</span> BindSource<span style="color: #000000;">&#40;</span>targetObject<span style="color: #000066; font-weight: bold;">:</span><a href="http://www.google.com/search?q=object%20inurl:http://livedocs.adobe.com/flex/201/langref/%20inurl:object.html"><span style="color: #004993;">Object</span></a><span style="color: #000066; font-weight: bold;">,</span> targetProperty<span style="color: #000066; font-weight: bold;">:</span><a href="http://www.google.com/search?q=string%20inurl:http://livedocs.adobe.com/flex/201/langref/%20inurl:string.html"><span style="color: #004993;">String</span></a><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">:</span><span style="color: #0033ff; font-weight: bold;">void</span> <span style="color: #000000;">&#123;</span>
		<span style="color: #0033ff; font-weight: bold;">this</span><span style="color: #000066; font-weight: bold;">.</span>targetObject = targetObject<span style="color: #000066; font-weight: bold;">;</span>
		<span style="color: #0033ff; font-weight: bold;">this</span><span style="color: #000066; font-weight: bold;">.</span>targetProperty = targetProperty<span style="color: #000066; font-weight: bold;">;</span>
	<span style="color: #000000;">&#125;</span> 
&nbsp;
	<span style="color: #0033ff; font-weight: bold;">public</span> <span style="color: #339966; font-weight: bold;">function</span> whenSourcePropertyChanges<span style="color: #000000;">&#40;</span>object<span style="color: #000066; font-weight: bold;">:</span><a href="http://www.google.com/search?q=object%20inurl:http://livedocs.adobe.com/flex/201/langref/%20inurl:object.html"><span style="color: #004993;">Object</span></a><span style="color: #000066; font-weight: bold;">,</span> property<span style="color: #000066; font-weight: bold;">:</span><a href="http://www.google.com/search?q=string%20inurl:http://livedocs.adobe.com/flex/201/langref/%20inurl:string.html"><span style="color: #004993;">String</span></a><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">:</span><span style="color: #0033ff; font-weight: bold;">void</span> <span style="color: #000000;">&#123;</span>
		BindingUtils<span style="color: #000066; font-weight: bold;">.</span>bindProperty<span style="color: #000000;">&#40;</span>targetObject<span style="color: #000066; font-weight: bold;">,</span> targetProperty<span style="color: #000066; font-weight: bold;">,</span> object<span style="color: #000066; font-weight: bold;">,</span> property<span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>
	<span style="color: #000000;">&#125;</span> 
<span style="color: #000000;">&#125;</span></pre></td></tr></table></div>

<p>To call this function you would use:</p>

<div class="wp_codebox_msgheader wp_codebox_hide"><span class="right"><sup><a href="http://www.ericbess.com/ericblog/2008/03/03/wp-codebox/#examples" target="_blank" title="WP-CodeBox HowTo?"><span style="color: #99cc00">?</span></a></sup></span><span class="left"><a href="javascript:;" onclick="javascript:showCodeTxt('p869code6'); return false;">View Code</a> ACTIONSCRIPT3</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table><tr id="p8696"><td class="code" id="p869code6"><pre class="actionscript3" style="font-family:monospace;">Bind<span style="color: #000066; font-weight: bold;">.</span>updateProperty<span style="color: #000000;">&#40;</span>foo<span style="color: #000066; font-weight: bold;">,</span> <span style="color: #990000;">&quot;bar&quot;</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">.</span>whenSourcePropertyChanges<span style="color: #000000;">&#40;</span>baz<span style="color: #000066; font-weight: bold;">,</span> <span style="color: #990000;">&quot;bar&quot;</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span></pre></td></tr></table></div>

<p>Kinda cool! I soon realized that this technique has some characteristics that Objective-C messages don&#8217;t have. For example, each step can use more than one parameter (plus they each get their own code hinting). You can also provide multiple choices for what to do next providing a sort of branching behavior.</p>

<div class="wp_codebox_msgheader wp_codebox_hide"><span class="right"><sup><a href="http://www.ericbess.com/ericblog/2008/03/03/wp-codebox/#examples" target="_blank" title="WP-CodeBox HowTo?"><span style="color: #99cc00">?</span></a></sup></span><span class="left"><a href="javascript:;" onclick="javascript:showCodeTxt('p869code7'); return false;">View Code</a> ACTIONSCRIPT3</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table><tr id="p8697"><td class="code" id="p869code7"><pre class="actionscript3" style="font-family:monospace;">AngleFinder<span style="color: #000066; font-weight: bold;">.</span>getAngleOfVector<span style="color: #000000;">&#40;</span><span style="color: #000000; font-weight:bold;">4</span><span style="color: #000066; font-weight: bold;">,</span> <span style="color: #000000; font-weight:bold;">4</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">.</span>inDegrees<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span> 	<span style="color: #009900; font-style: italic;">// 45°</span>
AngleFinder<span style="color: #000066; font-weight: bold;">.</span>getAngleOfVector<span style="color: #000000;">&#40;</span><span style="color: #000000; font-weight:bold;">4</span><span style="color: #000066; font-weight: bold;">,</span> <span style="color: #000000; font-weight:bold;">4</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">.</span>inRadians<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span> 	<span style="color: #009900; font-style: italic;">// π/4</span></pre></td></tr></table></div>

<p>You can even do free-form stacking of functions like this.</p>

<div class="wp_codebox_msgheader wp_codebox_hide"><span class="right"><sup><a href="http://www.ericbess.com/ericblog/2008/03/03/wp-codebox/#examples" target="_blank" title="WP-CodeBox HowTo?"><span style="color: #99cc00">?</span></a></sup></span><span class="left"><a href="javascript:;" onclick="javascript:showCodeTxt('p869code8'); return false;">View Code</a> ACTIONSCRIPT3</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table><tr id="p8698"><td class="code" id="p869code8"><pre class="actionscript3" style="font-family:monospace;"><span style="color: #0033ff; font-weight: bold;">new</span> Calculator	<span style="color: #000000;">&#40;</span><span style="color: #000000; font-weight:bold;">5</span><span style="color: #000000;">&#41;</span>                    <span style="color: #009900; font-style: italic;">// 5</span>
                        <span style="color: #000066; font-weight: bold;">.</span>plus<span style="color: #000000;">&#40;</span><span style="color: #000000; font-weight:bold;">3</span><span style="color: #000000;">&#41;</span>            <span style="color: #009900; font-style: italic;">// 8</span>
                        <span style="color: #000066; font-weight: bold;">.</span>times<span style="color: #000000;">&#40;</span><span style="color: #000000; font-weight:bold;">2</span><span style="color: #000000;">&#41;</span>          <span style="color: #009900; font-style: italic;">// 16</span>
                        <span style="color: #000066; font-weight: bold;">.</span>dividedBy<span style="color: #000000;">&#40;</span><span style="color: #000000; font-weight:bold;">4</span><span style="color: #000000;">&#41;</span>   <span style="color: #009900; font-style: italic;">// 4</span>
                        <span style="color: #000066; font-weight: bold;">.</span>minus<span style="color: #000000;">&#40;</span><span style="color: #000000; font-weight:bold;">1</span><span style="color: #000000;">&#41;</span>         <span style="color: #009900; font-style: italic;">// 3</span>
                        <span style="color: #000066; font-weight: bold;">.</span>plus<span style="color: #000000;">&#40;</span><span style="color: #000000; font-weight:bold;">2</span><span style="color: #000000;">&#41;</span>            <span style="color: #009900; font-style: italic;">// 5</span>
                        <span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">equals</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span></pre></td></tr></table></div>

<p>I proudly named these &#8220;Matryoshka Functions&#8221; after the Russian stacking dolls even though I&#8217;m sure I&#8217;m not the first to try something like this. As it turns out, they&#8217;re about 10% practical and 90% clever hack. Even though there could be some potential use for this (especially with complicated, repetitive tasks), this technique conflicts too much with the way we normally code in ActionScript. Still, I thought it was cool enough to share with everyone.</p>
<p>Pros:</p>
<ul>
<li>Very descriptive</li>
<li>Branching and stacking effect is interesting and potentially useful</li>
<li>Code hinting shows the next step in the function as well as the parameter names</li>
<li>Looks cool!</li>
</ul>
<p>Cons:</p>
<ul>
<li>Abominable code style. Too weird to be useful.</li>
<li>Difficult to know when to stop calling functions</li>
<li>Not completing the function will produce unexpected results with no compile-time errors</li>
<li>Each step requires you to pass the parameters from the previous step</li>
</ul>
<p>Can you find any use of these? Can you think of a more efficient way to write the functions? Any other thoughts?</p>
<p>Check out the source with multiple examples (FlashBuilder project).<br />
<a href='http://dispatchevent.org/wp-content/uploads/2011/01/MatroshkaFunctionDemo.zip'>MatroshkaFunctionDemo</a></p>
]]></content:encoded>
			<wfw:commentRss>http://dispatchevent.org/mims/matryoshka-functions/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>ActionScript 3.0 Bible Series at FlashCoders NY</title>
		<link>http://dispatchevent.org/roger/actionscript-3-0-bible-series-at-flashcoders-ny/</link>
		<comments>http://dispatchevent.org/roger/actionscript-3-0-bible-series-at-flashcoders-ny/#comments</comments>
		<pubDate>Wed, 14 Jul 2010 15:06:06 +0000</pubDate>
		<dc:creator>Roger Braunstein</dc:creator>
				<category><![CDATA[AS3]]></category>
		<category><![CDATA[Conferences and User Groups]]></category>
		<category><![CDATA[News]]></category>

		<guid isPermaLink="false">http://dispatchevent.org/?p=859</guid>
		<description><![CDATA[Hey readers! I&#8217;ve been doing a series of dynamic, engaging, interactive, educational and disturbingly sexy workshops on topics from the new AS3 Bible. These workshops are hosted by the fearless FlashCoders NY user group. If you&#8217;re in NYC and want &#8230; <a href="http://dispatchevent.org/roger/actionscript-3-0-bible-series-at-flashcoders-ny/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>Hey readers!</p>
<p>I&#8217;ve been doing a series of dynamic, engaging, interactive, educational and disturbingly sexy workshops on topics from the new <a href="http://actionscriptbible.com/">AS3 Bible</a>. These workshops are hosted by the fearless <a href="http://www.flashcodersny.com/">FlashCoders NY</a> user group. If you&#8217;re in NYC and want to drop by, check the meeting announcements. Having a copy of the book isn&#8217;t required! (But I sure recommend it, duh!)</p>
<p>I give the workshops every other Wednesday, give or take. Tonight&#8217;s is on <b>Pixel Bender</b>! Be sure to stop by!</p>
<p>As an aside, you may be curious what I&#8217;m up to. Actually, you aren&#8217;t, but I&#8217;ll tell you anyway because I&#8217;m amped. I&#8217;m juggling several iOS projects on iPhone 4 and iPad, I&#8217;m days away from launching an amazing collaboration with artists/directors Radical Friend, the creators of openFrameworks, and the talented folks at The Science Project &#8212; an experimental art piece driven by Unity and oF. And what the hell, I&#8217;m trying to learn 3D modeling (again) (finally). I heard that I might be giving a series of iOS dev video training episodes&#8230; stay tuned if you want to hear more!</p>
]]></content:encoded>
			<wfw:commentRss>http://dispatchevent.org/roger/actionscript-3-0-bible-series-at-flashcoders-ny/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Killing 3D Transforms</title>
		<link>http://dispatchevent.org/roger/killing-3d-transforms/</link>
		<comments>http://dispatchevent.org/roger/killing-3d-transforms/#comments</comments>
		<pubDate>Sat, 03 Apr 2010 07:33:31 +0000</pubDate>
		<dc:creator>Roger Braunstein</dc:creator>
				<category><![CDATA[AS3]]></category>
		<category><![CDATA[Tips, Tricks, and Hacks]]></category>

		<guid isPermaLink="false">http://dispatchevent.org/?p=848</guid>
		<description><![CDATA[Here&#8217;s a quick tip. If you&#8217;ve ever dealt with 3D in Flash Player 10+ you&#8217;ll know that DisplayObjects in 3D in Flash Player are bitmap-cached; only the bitmap representation is transformed in 3D. Recently I was working on a site &#8230; <a href="http://dispatchevent.org/roger/killing-3d-transforms/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>Here&#8217;s a quick tip. If you&#8217;ve ever dealt with 3D in Flash Player 10+ you&#8217;ll know that DisplayObjects in 3D in Flash Player are bitmap-cached; only the bitmap representation is transformed in 3D. Recently I was working on a site where objects landed on the stage, but after landing, they appeared really muddy, which was obvious when you looked at the text they contained. Even though they were completely flat, they were still using bitmap proxies! Not great.</p>
<p>Turning a DisplayObject into a 3D DisplayObject is as simple as assigning a value to its rotationX, rotationY, rotationZ, or z properties. But how do you turn it back? I tried giving all these properties a value of 0, but after their animations completed they were already 0. An object at z=0 still renders in 3D, using bitmap caching. Setting these values to NaN was no better.</p>
<p>The solution I found is to null out the 3D transformation matrix and assign a 2D transformation matrix. This can be accomplished like so for a DisplayObject named <code>sprite</code>:</p>
<p><code>var matrix:Matrix = new Matrix();<br />
matrix.translate(sprite.x, sprite.y);<br />
matrix.rotate(sprite.rotationZ);<br />
sprite.transform.matrix3D = null;<br />
sprite.transform.matrix = matrix;</code></p>
<p>In this code I simply drop the transformations that are inapplicable to 2D space. This is fine when your object is already coplanar with the stage.</p>
<p>Anyway, quick tip if this ever had you scratching your head too.</p>
]]></content:encoded>
			<wfw:commentRss>http://dispatchevent.org/roger/killing-3d-transforms/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Side-by-side comparison shows blitting isn&#8217;t a huge speed bump</title>
		<link>http://dispatchevent.org/mims/side-by-side-comparison-shows-blitting-isnt-a-huge-speed-bump/</link>
		<comments>http://dispatchevent.org/mims/side-by-side-comparison-shows-blitting-isnt-a-huge-speed-bump/#comments</comments>
		<pubDate>Sun, 21 Mar 2010 18:43:55 +0000</pubDate>
		<dc:creator>Mims H Wright</dc:creator>
				<category><![CDATA[AS3]]></category>
		<category><![CDATA[Programming]]></category>
		<category><![CDATA[Tips, Tricks, and Hacks]]></category>
		<category><![CDATA[Videogames]]></category>
		<category><![CDATA[animation]]></category>
		<category><![CDATA[bit]]></category>
		<category><![CDATA[blit]]></category>
		<category><![CDATA[oldschool]]></category>
		<category><![CDATA[sprite]]></category>

		<guid isPermaLink="false">http://dispatchevent.org/?p=847</guid>
		<description><![CDATA[This isn&#8217;t a new article, but it touches on a topic I&#8217;ve heard a lot about recently. That is, pixel &#8216;blitting&#8216;. Blitting is an old school process used in sprite-based games of essentially erasing a spot in a bitmap image &#8230; <a href="http://dispatchevent.org/mims/side-by-side-comparison-shows-blitting-isnt-a-huge-speed-bump/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>This isn&#8217;t a new article, but it touches on a topic I&#8217;ve heard a lot about recently. That is, pixel &#8216;<a href="http://en.wikipedia.org/wiki/Bit_blit">blitting</a>&#8216;. Blitting is an old school process used in sprite-based games of essentially erasing a spot in a bitmap image based on a sprite&#8217;s alpha and using a bitwise operator to draw the sprite into that bitmap image. Most graphics systems do this transparently to the user in some fashion (pardon the pun). <a href="http://www.8bitrocket.com/">8-Bit Rocket</a> has a <a href="http://www.8bitrocket.com/newsdisplay.aspx?newspage=13430">good introduction</a> to these concepts with regards to Flash, but read on for the important part of this post.</p>
<p><a href="http://www.photonstorm.com/archives/160/is-pixel-blitting-in-as3-really-worth-the-effort"><img class="alignnone" title="blitTest" src="http://www.photonstorm.com/wp-content/uploads/2008/09/sshot-2008-09-19-1.png" alt="" width="300" /></a></p>
<p><a href="http://www.photonstorm.com/archives/160/is-pixel-blitting-in-as3-really-worth-the-effort">Read the article on Photon Storm</a></p>
<p>The article shows that Flash Player is already fairly optimized for graphical composition operations when compared to blitting. Both showed similar framerates. However, the cacheAsBitmap operation caused an exponential increase in memory consumption when the number of sprites on stage increased. Ironically, the comparison was run by the creator of the <a href="http://code.google.com/p/pixelblitz/">Pixel Blitz</a> library who, I&#8217;m sure, had a difficult time presenting the results.</p>
<p>There are some good details in the article so if you&#8217;re interested, read the whole thing before you decide if you agree.</p>
<p>Have you done any work with bit blitting or sprite sheet animation? Have you found it to be beneficial? Tell us your thoguhts.</p>
]]></content:encoded>
			<wfw:commentRss>http://dispatchevent.org/mims/side-by-side-comparison-shows-blitting-isnt-a-huge-speed-bump/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>AS3 Bible translated to 繁體中文</title>
		<link>http://dispatchevent.org/mims/as3-bible-translated-to-chinese/</link>
		<comments>http://dispatchevent.org/mims/as3-bible-translated-to-chinese/#comments</comments>
		<pubDate>Thu, 18 Mar 2010 22:08:11 +0000</pubDate>
		<dc:creator>Mims H Wright</dc:creator>
				<category><![CDATA[AS3]]></category>
		<category><![CDATA[In Real Life]]></category>
		<category><![CDATA[as3bible]]></category>
		<category><![CDATA[book]]></category>
		<category><![CDATA[chinese]]></category>
		<category><![CDATA[free as in beer]]></category>

		<guid isPermaLink="false">http://dispatchevent.org/?p=843</guid>
		<description><![CDATA[Yesterday, completely unannounced, a package arrived at my doorstep containing two copies of the ActionScript 3.0 Bible Traditional Chinese Edition! Well, that&#8217;s pretty Zang if you ask me! I&#8217;m going to keep one as a trophy but if you can &#8230; <a href="http://dispatchevent.org/mims/as3-bible-translated-to-chinese/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>Yesterday, completely unannounced, a package arrived at my doorstep containing two copies of the <a href="http://www.amazon.com/ActionScript-3-0-Bible-Roger-Braunstein/dp/0470135603">ActionScript 3.0 Bible</a> <em>Traditional Chinese Edition! </em>Well, that&#8217;s pretty Zang if you ask me!</p>
<p><a href="http://dispatchevent.org/wp-content/uploads/2010/03/chinese-bible.jpg"><img class="alignnone size-medium wp-image-844" title="chinese-bible" src="http://dispatchevent.org/wp-content/uploads/2010/03/chinese-bible-300x168.jpg" alt="" width="300" height="168" /></a></p>
<p>I&#8217;m going to keep one as a trophy but if you can read chinese and you&#8217;d like a copy, let me know and I&#8217;ll send you a present*!</p>
<p><small>*(If you&#8217;re outside the US, i&#8217;ll ask you to pay for shipping)</small></p>
]]></content:encoded>
			<wfw:commentRss>http://dispatchevent.org/mims/as3-bible-translated-to-chinese/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>IDisplayObject? &#8211; Getting around the lack of an interface for the DisplayObject in Flash</title>
		<link>http://dispatchevent.org/mims/idisplayobject/</link>
		<comments>http://dispatchevent.org/mims/idisplayobject/#comments</comments>
		<pubDate>Mon, 15 Mar 2010 02:27:22 +0000</pubDate>
		<dc:creator>Mims H Wright</dc:creator>
				<category><![CDATA[Architecture]]></category>
		<category><![CDATA[AS3]]></category>
		<category><![CDATA[Programming]]></category>
		<category><![CDATA[Tips, Tricks, and Hacks]]></category>
		<category><![CDATA[displayobject]]></category>
		<category><![CDATA[hack]]></category>
		<category><![CDATA[idisplayobject]]></category>
		<category><![CDATA[interface]]></category>
		<category><![CDATA[workaround]]></category>

		<guid isPermaLink="false">http://dispatchevent.org/?p=838</guid>
		<description><![CDATA[Interfaces are amazing things. When I was young and green, I didn&#8217;t understand their purpose, but after working with them for a while, I will defend their use to the end. I try to create lots of interfaces early on &#8230; <a href="http://dispatchevent.org/mims/idisplayobject/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p><a href="http://dispatchevent.org/wp-content/uploads/2010/03/DisplayObject_subclasses.png"><img class="alignnone size-medium wp-image-840" title="DisplayObject_subclasses" src="http://dispatchevent.org/wp-content/uploads/2010/03/DisplayObject_subclasses-300x156.png" alt="" width="300" height="156" /></a></p>
<p>Interfaces are amazing things.  When I was young and green, I didn&#8217;t understand their purpose, but after working with them for a while, I will defend their use to the end. I try to create lots of interfaces early on in my projects and I find that by keeping things flexible, it saves more time despite the extra typing, pardon the double entendre.</p>
<p>But this is not an article about why interfaces are so great. No, this is an article about the mysterious gap in the Flash Player API with regards to an interface for DisplayObjects. If you have a class typed as something like <code>IView</code>, there&#8217;s no way to enure that <code>IView</code> can be a parameter of display list functions like <code> addChild()</code>.</p>
<p><span id="more-838"></span>Why can&#8217;t we guarantee that something is a DisplayObject through interfaces? There is a practical answer. The inner workings of the Flash Player are slowing unfolding to us with each version. We now have low level access to sound, byte streams, and text rendering. However, the display list still relies exclusively on one of the only truly abstract classes in ActionScript 3.0, the DisplayObject. Because a low-level drawing engine is not exposed to AS3 programmers, we don&#8217;t know how it works and we cannot guarantee through an interface that an arbitrary class can be drawn.</p>
<p>Fortunately, there are some workarounds that can help, each with their own strengths and weaknesses. Personally, I think #2 is the way to go. It&#8217;s practically dripping with polymorphic goodness.</p>
<ol>
<li>
<h3>Make your interface inherit from IBitmapDrawable and IEventDispatcher</h3>
<p>DisplayObject is the only class that uses both of these two interfaces so by combining them in your interface, you can sort of be sure you&#8217;re working with a DisplayObject. Still, this is my least favorite solution</p>
<h4>Pros:</h4>
<ul>
<li>Uses interfaces exclusively.</li>
<li>Only a DisplayObject would implement both of these.</li>
</ul>
<h4>Cons:</h4>
<ul>
<li>There&#8217;s nothing to stop you from using this to create a class that isn&#8217;t a DisplayObject and that could cause problems.</li>
<li>You would still have to type cast to DisplayObject to use this as an argument for <code>addChild()</code>.</li>
</ul>
</li>
<li>
<h3>Create an interface that exposes a method to return the object as a DisplayObject</h3>
<p>My personal favorite solution. It not only solves the problem of guaranteeing that a class can go in the display list, it doesn&#8217;t even require that the class be a DisplayObject.</p>
<p>Here&#8217;s an example of what this would look like. <a href="http://gist.github.com/332408">IDisplayObject.as</a></p>
<h4>Pros:</h4>
<ul>
<li>Flexible solution that conforms to good OOD principles.</li>
<li>Uses interfaces exclusively.</li>
<li>Easy to apply. You can usually implement it with a single line of code: <code>return this;</code></li>
</ul>
<h4>Cons:</h4>
<ul>
<li>Requires you to use <code>asDisplayObject()</code> every time you want to use the object as a DisplayObject.</li>
<li>Calling <code>foo.asDisplayObject()</code> would throw an exception if <code>foo</code> was null so additional checks may be necessary.</li>
</ul>
</li>
<li>
<h3>Use an <a href="http://en.wikipedia.org/wiki/Abstract_type">abstract class</a> that inherits from DisplayObject</h3>
<p>Not an ideal solution primarily because Flash doesn&#8217;t have true abstract classes (although <a href="http://dispatchevent.org/mims/abstract-classes-in-as3/">there are workarounds</a>) but still totally valid.</p>
<h4>Pros:</h4>
<ul>
<li>Guarantees that the object is a DisplayObject. No type casting required.</li>
<li>Abstract classes can be treated virtually the same as an interface for practical use.</li>
</ul>
<h4>Cons:</h4>
<ul>
<li>No true abstract classes in Flash.</li>
<li>Not as flexible as an interface-based solution since it forces you to inherit from DisplayObject.</li>
</ul>
</li>
</ol>
]]></content:encoded>
			<wfw:commentRss>http://dispatchevent.org/mims/idisplayobject/feed/</wfw:commentRss>
		<slash:comments>7</slash:comments>
		</item>
		<item>
		<title>Copy text to clipboard in AS3</title>
		<link>http://dispatchevent.org/mims/as3-clipboard/</link>
		<comments>http://dispatchevent.org/mims/as3-clipboard/#comments</comments>
		<pubDate>Tue, 02 Mar 2010 06:27:34 +0000</pubDate>
		<dc:creator>Mims H Wright</dc:creator>
				<category><![CDATA[AS3]]></category>
		<category><![CDATA[Tips, Tricks, and Hacks]]></category>
		<category><![CDATA[clipboard]]></category>
		<category><![CDATA[copypasta]]></category>

		<guid isPermaLink="false">http://dispatchevent.org/?p=825</guid>
		<description><![CDATA[Here&#8217;s how you do it! http://mandarin.no/as3/as3-snippet-1-copy-text-to-clipboard/]]></description>
			<content:encoded><![CDATA[<p>Here&#8217;s how you do it!<br />
<a href="http://mandarin.no/as3/as3-snippet-1-copy-text-to-clipboard/">http://mandarin.no/as3/as3-snippet-1-copy-text-to-clipboard/</a></p>
]]></content:encoded>
			<wfw:commentRss>http://dispatchevent.org/mims/as3-clipboard/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>KitchenSync Version 2.0 is now available!</title>
		<link>http://dispatchevent.org/mims/kitchensync-v2-released/</link>
		<comments>http://dispatchevent.org/mims/kitchensync-v2-released/#comments</comments>
		<pubDate>Tue, 09 Feb 2010 03:14:49 +0000</pubDate>
		<dc:creator>Mims H Wright</dc:creator>
				<category><![CDATA[AS3]]></category>
		<category><![CDATA[News]]></category>
		<category><![CDATA[physics & motion]]></category>
		<category><![CDATA[animation]]></category>
		<category><![CDATA[KitchenSync]]></category>
		<category><![CDATA[launch]]></category>
		<category><![CDATA[tween]]></category>
		<category><![CDATA[version2.0]]></category>

		<guid isPermaLink="false">http://dispatchevent.org/?p=809</guid>
		<description><![CDATA[I&#8217;m very proud to announce that the second version of KitchenSync has arrived! What started as a labour of love about 3 years ago has finally gotten its first much needed upgrade. Just about everything in this version is newer &#8230; <a href="http://dispatchevent.org/mims/kitchensync-v2-released/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>I&#8217;m very proud to announce that the second version of KitchenSync has arrived! What started as a labour of love about 3 years ago has finally gotten its first much needed upgrade. Just about everything in this version is newer and more streamlined. The entire system for greater simplicity and practical functionality.</p>
<p>This version will not be backwards compatible, however, there&#8217;s finally some <a href="http://kitchensync.as3lib.org/manual">Decent Documentation</a>!!! There&#8217;s also a <a href="http://kitchensync.as3lib.org">new blog</a> devoted to KS.</p>
<p><a href="http://kitchensynclib.googlecode.com">GO GET IT NOW!</a></p>
<p>Here&#8217;s some of the new features. You can view all of them by checking out the <a href="http://kitchensynclib.googlecode.com/svn/trunk/docs/changelog.txt">change log</a>.</p>
<ul>
<li>Usability
<ul>
<li>REFACTORED all classes with usability and stability in mind.</li>
<li>UPDATED all ASDocs</li>
<li>ADDED several new methods in the TweenFactory for easy tween creation.</li>
</ul>
</li>
<li>Synchronizer and Time
<ul>
<li>REFACTORED The way time is handled throughout.</li>
<li>ADDED ISynchronizerCore and example core classes. This allows advanced users to switch between different methods of timing (e.g. enterframe or timer based)</li>
<li>ADDED FrameRateUtil for getting instantaneous and averaged framerates of the system. The FrameRateView now makes use of this class and has more options.</li>
</ul>
</li>
<li>Action Architecture
<ul>
<li>REFACTORED action classes and extracted several interfaces from them.</li>
<li>ADDED jumpToTime and jumpByTime functionality to actions.</li>
<li>ADDED Looping via a new group called KSLooper.</li>
<li>REMOVED complicated and rarely used action triggers from AbstractAction.</li>
<li>ADDED togglePause() method and progress variable to AbstractAction (for getting percentage complete of an action).</li>
</ul>
</li>
<li>Tweens
<ul>
<li>CHANGED constructors in KSTween. Emphasis is now on using TweenFactory.</li>
<li>IMPROVED Object parser in TweenFactory</li>
</ul>
</li>
<li>Action Groups
<ul>
<li>ADDED Syntactic sugar to the group constructors. using an array in the constructor for a parallel group adds a sequence and vice versa.</li>
<li>ADDED totalDuration to groups to show the duration of all child actions in a group.</li>
<li>ADDED KSRandomGroup.</li>
<li>REMOVED KSSteppedSequenceGroup because it seemed kinda useless.</li>
</ul>
</li>
<li>Loading Actions
<ul>
<li>REFACTORED Loading actions. Now they&#8217;re much easier to use and more powerful.</li>
<li>ADDED KSLoadQueue for quickly creating a class to load files from the network in a batch.</li>
<li>ADDED the resultList property to the ILoaderAction interface so that you can quickly access the loaded files in a batch.</li>
</ul>
</li>
<li>Misc
<ul>
<li>RENAMED several classes and reworked package structure</li>
<li>ADDED KSAsynchronousIteration for running processor-intensive for loops spaced out over a period of time so that they are essentially asynchronous.</li>
<li>FIXED several minor and major bugs.</li>
</ul>
</li>
</ul>
]]></content:encoded>
			<wfw:commentRss>http://dispatchevent.org/mims/kitchensync-v2-released/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Using %tokens% with Flex resource bundles</title>
		<link>http://dispatchevent.org/mims/using-tokens-with-flex-resource-bundles/</link>
		<comments>http://dispatchevent.org/mims/using-tokens-with-flex-resource-bundles/#comments</comments>
		<pubDate>Tue, 08 Dec 2009 19:26:08 +0000</pubDate>
		<dc:creator>Mims H Wright</dc:creator>
				<category><![CDATA[AS3]]></category>
		<category><![CDATA[Flex]]></category>
		<category><![CDATA[Tips, Tricks, and Hacks]]></category>
		<category><![CDATA[resource bundles]]></category>
		<category><![CDATA[strings]]></category>
		<category><![CDATA[token]]></category>

		<guid isPermaLink="false">http://dispatchevent.org/?p=796</guid>
		<description><![CDATA[When I use Flex, I make extensive use of Resource Bundles for all but the most basic applications. In short, they allow you to keep all of your static string values (and non-string values) separated out of your code. That &#8230; <a href="http://dispatchevent.org/mims/using-tokens-with-flex-resource-bundles/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>When I use Flex, I make extensive use of <a href="http://help.adobe.com/en_US/Flex/4.0/UsingSDK/WS2db454920e96a9e51e63e3d11c0bf69084-7fcf.html">Resource Bundles</a> for all but the most basic applications. In short, they allow you to keep all of your static string values (and non-string values) separated out of your code. That way, down the line it&#8217;s a very easy change when you want to localize the site in another language, rebrand it for another audience, or when a client asks you to change a button label or error message. Granted, this level of detail isn&#8217;t always necessary but I think it&#8217;s a good habit to get into even if it&#8217;s overkill for some projects.</p>
<p>But resource bundles can&#8217;t help you in every scenario. I often find myself needing to construct a sentence with live data inserted. For this, the resource strings are less helpful. For example, how would you write:</p>
<p><code>"At " + time + ", you received a message from " + userName + "."</code></p>
<p>With resource strings, you would have to do something like</p>
<pre>at=At
message=, you received a message from
period=.</pre>
<p>Which completely negates the whole point of using resource bundles. What to do?</p>
<h3>Token replacement</h3>
<p><img class="size-full wp-image-799 alignright" title="tokens" src="http://dispatchevent.org/wp-content/uploads/2009/12/tokens.jpg" alt="tokens" width="155" height="125" /><br />
What I really wanted was a way to inject data into the string. I&#8217;ve seen this done by use of tokens in other languages like <a href="http://developer.apple.com/mac/library/documentation/Cocoa/Conceptual/Strings/Articles/FormatStrings.html#//apple_ref/doc/uid/20000943">Objective-C</a> so I thought I&#8217;d give it a try. The result was surprisingly lightweight.</p>
<p>I created this utility that lets you use tokens (delimited by % signs) that can be replaced by live data when you retrieve the resource. Using this class, the example above would look more like this:</p>
<pre>receivedMessage=At %time%, you received a message from %userName%.

// then in your code
trace(ResourceStringUtil.getResoureceStringWithTokens("receivedMessage", {time: "11:49", userName: "Mims"}));

// displays
At 11:49, you received a message from Mims.</pre>
<p>Here&#8217;s the source code Feel free to use it and modify it for your purposes.</p>
<p><script src="http://gist.github.com/251904.js?file=ResourceStringUtil.as"></script></p>
]]></content:encoded>
			<wfw:commentRss>http://dispatchevent.org/mims/using-tokens-with-flex-resource-bundles/feed/</wfw:commentRss>
		<slash:comments>5</slash:comments>
		</item>
		<item>
		<title>The Deepening &#8211; Select Your Own Adventure Edition</title>
		<link>http://dispatchevent.org/mims/the-deepening-select-your-own-adventure-edition/</link>
		<comments>http://dispatchevent.org/mims/the-deepening-select-your-own-adventure-edition/#comments</comments>
		<pubDate>Tue, 22 Sep 2009 19:13:39 +0000</pubDate>
		<dc:creator>Mims H Wright</dc:creator>
				<category><![CDATA[AS3]]></category>
		<category><![CDATA[Flash]]></category>
		<category><![CDATA[News]]></category>
		<category><![CDATA[Videogames]]></category>
		<category><![CDATA[atom]]></category>
		<category><![CDATA[funny]]></category>
		<category><![CDATA[video]]></category>
		<category><![CDATA[work]]></category>

		<guid isPermaLink="false">http://dispatchevent.org/?p=735</guid>
		<description><![CDATA[I&#8217;m very pleased to announce that one of my latest projects has just gone live. The Deepening &#8211; Select Your Own Adventure Edition has just gone up on Atom Films. Go give it a look, it&#8217;s hilarious. The video is &#8230; <a href="http://dispatchevent.org/mims/the-deepening-select-your-own-adventure-edition/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p><a href="http://deepening.atom.com"><img class="alignnone size-full wp-image-737" title="Screen shot 2009-09-22 at 15.26.51 PM" src="http://dispatchevent.org/wp-content/uploads/2009/09/Screen-shot-2009-09-22-at-15.26.51-PM.png" alt="Screen shot 2009-09-22 at 15.26.51 PM" /></a></p>
<p>I&#8217;m very pleased to announce that one of my latest projects has just gone live. <a href="http://www.deepening.atom.com">The Deepening &#8211; Select Your Own Adventure Edition</a> has just gone up on Atom Films. Go give it a look, it&#8217;s hilarious.</p>
<p>The video is a Good Cop / Bad Cop action show where you get to choose what happens next. It was created by the brilliant <a href="http://theduncanbrothers.com/">Duncan Brothers</a> who asked me to help build the Flash portion of it. Enjoy!</p>
<p><a href="http://www.deepening.atom.com">deepening.atom.com</a></p>
]]></content:encoded>
			<wfw:commentRss>http://dispatchevent.org/mims/the-deepening-select-your-own-adventure-edition/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Fast Intro to Flash</title>
		<link>http://dispatchevent.org/calebjohnston/fast-intro-to-flash/</link>
		<comments>http://dispatchevent.org/calebjohnston/fast-intro-to-flash/#comments</comments>
		<pubDate>Wed, 08 Apr 2009 04:07:42 +0000</pubDate>
		<dc:creator>Caleb Johnston</dc:creator>
				<category><![CDATA[AIR]]></category>
		<category><![CDATA[AS3]]></category>
		<category><![CDATA[Flash]]></category>
		<category><![CDATA[Flex]]></category>
		<category><![CDATA[Meta]]></category>

		<guid isPermaLink="false">http://dispatchevent.org/?p=620</guid>
		<description><![CDATA[There is plenty of documentation, tutorials and explanation of Flash on the internet, blogs and books. However, it&#8217;s hard for me to find a good, concise article that covers Flash well. I&#8217;ve been exposing Flash 9 to a friend of &#8230; <a href="http://dispatchevent.org/calebjohnston/fast-intro-to-flash/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p><span style="font-family: Arial;">There is plenty of documentation, tutorials and explanation of Flash on the internet, blogs and books. However, it&#8217;s hard for me to find a good, concise article that covers Flash well. I&#8217;ve been exposing Flash 9 to a friend of mine recently and I&#8217;ve decided that a concise explanation is something I should write. This post will be brief, high level and will cover Flash as a platform and not the Flash IDE. This article is also intended for those with previous exposure to technical concepts such as virtual machines and compilers.<br style="font-family: Arial;" /> </span><span id="more-620"></span><br style="font-family: Arial;" /><strong><span style="font-family: Arial;">Overview</span></strong><br />
<span style="font-family: Arial;">Flash is a platform for building and deploying interactive multimedia on the internet. The term Flash is ambiguous because it can be used to describe the runtime environment (Flash Player) or one of two IDEs targeting the player (Adobe Flash and Adobe Flex Builder). Flash currently uses an ECMA-based scripting language known as Actionscript for authoring. This same language is used across all of Adobe&#8217;s platform -which includes Adobe AIR, Adobe Flex, and Adobe Flash. Actionscript uses a <em>strong, static, safe</em> type system which makes it&#8217;s syntax more similar to Java than Javascript.</span></p>
<p><strong><span style="font-family: Arial;">Runtime Environment</span></strong></p>
<p><span style="font-family: Arial;"><strong>SWF Files</strong></span><br style="font-family: Arial;" /><span style="font-family: Arial;">Swf files are compressed, multipurpose </span><span style="font-family: Arial;">packages designed to contain the following data: raster and vector graphics, video, audio, text, fonts, animation, and actionscript code. Swfs can be loaded at runtime whenever necessary and can use both static and dynamic linking based upon the compiler settings. The runtime environment uses security sandboxes for loaded swf files. The security settings primarily limit the extent of filesystem access and cross-domain access that swf files can use. Adobe has <a id="jj8r" title="provided the swf file format spec" href="http://www.adobe.com/devnet/swf/">provided the swf file format spec</a> and has recently provided the <a id="k0w6" title="FLV video format spec" href="http://www.adobe.com/devnet/flv/">FLV video format spec</a> and <a id="drt9" title="has declared that they will provide the RTMP specs" href="http://www.adobe.com/aboutadobe/pressroom/pressreleases/200901/012009RTMP.html">has declared that they will provide the RTMP spec</a> as well.</span><br />
<span style="font-family: Arial;"><strong><br />
Flash Player &amp; AVM2</strong><br />
The Flash Player runtime is a very light-weight, virtual machine and handles system calls. The Flash Player includes both AVM1 (AS1, AS2, for Flash versions 1-8) and AVM2  (AS3 for Flash 9,10+) which processes compiled <a id="obh5" title="Adobe Byte Code" href="http://www.anotherbigidea.com/javaswf/avm2/AVM2Instructions.html">Adobe Bytecode</a> (ABC). The term AVM stands for &#8220;ActionScript Virtual Machine&#8221;<strong>*</strong>. </span><span style="font-family: Arial;">The Flash Player uses a Deferred Reference Counting (DRC) mechanism combined with a conservative mark/sweep garbage collector.</span><span style="font-family: Arial;"> The Adobe VM uses both JIT compiling and code interpretation and may benefit from compile-time bytecode optimizations based upon compiler input parameters. AS3 computational performance is generally closer to Java than Javascript [<a id="zbpr" title="AS3 performance vs Java vs Javascript" href="http://www.oddhammer.com/actionscriptperformance/set4/">source</a>]. The player also maintains a variable framerate that reflects the time consumed for each frame update [<a id="w455" title="source" href="http://www.onflex.org/ted/2005/07/flash-player-mental-model-elastic.php">source</a>]. Each frame update consists of multiple stages that include internal player processing, rendering, and author script processing. The program framerate is the principle metric reflecting application performance.<br />
<span style="font-family: Arial;"><br style="font-family: Arial;" /></span><span style="font-size: small;"><strong><span style="font-family: Arial;">Development Environment</span></strong></span></span></p>
<p><strong><span style="font-family: Arial;">Actionscript API</span></strong><br style="font-family: Arial;" /> <span style="font-family: Arial;">The Actionscript API is divided up amongst the Adobe AIR environment, the Flex environment, and the Flash environment and the Flash Player</span><span style="font-family: Arial;">.</span><span style="font-family: Arial;"> The source for all the packages are divided up amongst <a id="lc9l" title="swc files" href="http://livedocs.adobe.com/flex/3/html/building_overview_5.html">swc files</a>. Swc files are pre-compiled catalogs of classes and assets. They are similar to swf files but they are used for compile-time dependency resolution. Furthermore, the native swc&#8217;s predominantly contain code and not visual assets. An overview of the Actionscript packages is kept up to date in the <a id="y1w4" title="Adobe Actionscript 3 package summary" href="http://livedocs.adobe.com/flash/9.0/ActionScriptLangRefV3/package-summary.html">Adobe Live Docs</a>.</span></p>
<p><span style="font-family: Arial;"><strong>The Flash IDE</strong><br />
The Flash IDE was designed for designers, artists and animators. So, it is equiped with a layer system which reflects the stage display list and a hierarchical timeline which reflects the temporal nature of the runtime. The objects placed on the stage are represented by the timeline and can be &#8220;tweened&#8221; (using runtime interpolated 2D geometric transformations or custom shape morphs). The same timeline is also used for object creation and destruction. All stage instances are confined to a small set of native data types including: MovieClips, Sprites, Shapes, <span style="font-family: Arial;">TextFields, </span><span style="font-family: Arial;">Videos, and Bitmaps. The IDE also has a library that contains source objects for all stage instances and even instances that aren&#8217;t used on the stage. Flash projects often have several build targets (compiled swf files) that use parts of the project codebase. After Macromedia was purchased by Adobe, the Flash authoring environment has been updated to provide much better interoperability with the Adobe Creative Suite.</span></span></p>
<p><span style="font-family: Arial;"><strong>Adobe Flex Builder</strong><br />
Flex Builder is an Eclipse-based Actionscript IDE for writing and compiling swf files. Flex Builder is primarily designed to build &#8220;Flex&#8221; projects which can be written in an interface tagging language known as MXML. MXML is a declarative XML langauge used to define interface elements in a project. MXML files provide the &#8220;view&#8221; in the MVC software design pattern. Flex Builder also provides plenty of useful features like code completion, syntax formatting, active debugging, memory profiling, and project building that expose errors and warnings during development time. Because the Flex framework is not bundled with the Flash Player, Flex projects must statically link to all swc assets specific to Flex which amounts to greater than 500kb. This is very unnatractive for most users, thus Adobe has provided <a id="ilsr" title="means by which the download can be significantly decreased" href="http://onflash.org/ted/2008/01/flex-3-framework-caching.php">means by which the download can be significantly decreased</a>. Flex Builder is also used to deploy applications for the <a id="kwwz" title="Adobe AIR platform" href="http://en.wikipedia.org/wiki/Adobe_Integrated_Runtime">Adobe AIR platform</a>. Adobe AIR is a desktop runtime that combines <a id="ffsj" title="webkit" href="http://webkit.org/">webkit</a> with the AVM2 portion of the Flash Player. AIR can be likened to a closed source <a id="k10e" title="Java SE" href="http://en.wikipedia.org/wiki/Java_SE">Java SE</a> runtime but provides a smaller learning curve and greater accessibility than what comes with the Java ecosystem. </span></p>
<p><span style="font-family: Arial;"><strong>Compiler</strong><br />
Since Adobe has launched the Flex platform they have provided free access to their Flex and Actionscript compiler and SDK. They have also provided open source projects under the <a id="mz0t" title="Mozilla public license" href="http://en.wikipedia.org/wiki/Mozilla_Public_License">Mozilla public license</a>. The compiler (<a id="n5hv" title="Adobe Flex 3 Help - Compilers" href="http://livedocs.adobe.com/flex/3/html/help.html?content=compilers_13.html">mxmlc</a>) provides an impressive amount of flexibility and customization for swf compiling. It can be configured with command line options or a <a id="xwm0" title="configuration XML file" href="http://livedocs.adobe.com/flex/3/html/compilers_11.html#134938">configuration XML file</a>.</span></p>
<p><span style="font-family: Arial;"><em><strong>* </strong>correction 09-12-2009, I had previously stated that the term AVM meant &#8220;Adobe Virtual Machine&#8221;, this is a mixup. It actually means &#8220;ActionScript Virtual Machine&#8221;. Thanks dbam.</em></span></p>
]]></content:encoded>
			<wfw:commentRss>http://dispatchevent.org/calebjohnston/fast-intro-to-flash/feed/</wfw:commentRss>
		<slash:comments>6</slash:comments>
		</item>
		<item>
		<title>AS3 number to hex converter</title>
		<link>http://dispatchevent.org/mims/as3-number-to-hex-converter/</link>
		<comments>http://dispatchevent.org/mims/as3-number-to-hex-converter/#comments</comments>
		<pubDate>Fri, 30 Jan 2009 01:38:44 +0000</pubDate>
		<dc:creator>Mims H Wright</dc:creator>
				<category><![CDATA[AS3]]></category>
		<category><![CDATA[Lab]]></category>
		<category><![CDATA[Programming]]></category>
		<category><![CDATA[as3lib]]></category>
		<category><![CDATA[bitwise]]></category>
		<category><![CDATA[converter]]></category>
		<category><![CDATA[hex]]></category>
		<category><![CDATA[hexadecimal]]></category>
		<category><![CDATA[hexit]]></category>
		<category><![CDATA[math]]></category>

		<guid isPermaLink="false">http://dispatchevent.org/?p=618</guid>
		<description><![CDATA[I&#8217;ve been working on some code for converting colors lately and getting quite into bitwise operations. In one of the demos I was making, I needed a quick and easy way to see the results of a color calculation. Of &#8230; <a href="http://dispatchevent.org/mims/as3-number-to-hex-converter/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>I&#8217;ve been working on some code for converting colors lately and getting quite into bitwise operations. In one of the demos I was making, I needed a quick and easy way to see the results of a color calculation. Of course, simply tracing a number, even if it&#8217;s in the format 0xFF, will result in a digital number string &#8220;255&#8243;. I&#8217;ve always been a little stumped about how to do this calculation but I realized that it&#8217;s actually very easy to do with the <a href="http://livedocs.adobe.com/flex/3/langref/operators.html#bitwise_AND">&amp;</a> and <a href="http://livedocs.adobe.com/flex/3/langref/operators.html#bitwise_unsigned_right_shift">&gt;&gt;&gt;</a> bitwise operators.</p>
<p><code><br />
getNumberAsHexString(255); // 0xFF<br />
getNumberAsHexString(0xABCDEF); // 0xABCDEF<br />
getNumberAsHexString(0x00FFCC); // 0xFFCC<br />
getNumberAsHexString(0x00FFCC, 6); // 0x00FFCC - Uses 6 as a minimum number of hexits</code></p>
<p>I&#8217;ve added the code to the <a href="http://as3lib.org">AS3lib</a> as  as a global function. I may move it to a utility class later on. You can <a href="http://code.google.com/p/as3lib/source/browse/trunk/src/org/as3lib/math/getNumberAsHexString.as">view the source</a> on Google Code.</p>
<p>Incidentally, in a moment of bug-fixing frustration, I found <a href="http://kinderas.blogspot.com/2008/01/quicktip-actionscript-3-and-number.html">this article on O.C.A.S.</a> which describes how the same functionality is already built into the <code>toString()</code> method! However, the work isn&#8217;t completely wasted since my version includes the option to show leading zeroes and adds &#8220;<code>0x</code>&#8221; at the front of the result.</p>
]]></content:encoded>
			<wfw:commentRss>http://dispatchevent.org/mims/as3-number-to-hex-converter/feed/</wfw:commentRss>
		<slash:comments>5</slash:comments>
		</item>
	</channel>
</rss>

