<?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>Calypso88</title>
	<atom:link href="http://www.calypso88.com/?feed=rss2" rel="self" type="application/rss+xml" />
	<link>http://www.calypso88.com</link>
	<description>ActionScript trials &#38; tribulations.</description>
	<lastBuildDate>Sun, 07 Feb 2010 22:21:28 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=abc</generator>
		<item>
		<title>Updated benchmarks: Flash 10 Release Player</title>
		<link>http://www.calypso88.com/?p=539</link>
		<comments>http://www.calypso88.com/?p=539#comments</comments>
		<pubDate>Sun, 07 Feb 2010 22:04:48 +0000</pubDate>
		<dc:creator>Rob</dc:creator>
				<category><![CDATA[AS3 Speed Benchmarking]]></category>
		<category><![CDATA[Actionscript 3.0]]></category>
		<category><![CDATA[Optimization]]></category>
		<category><![CDATA[ActionScript]]></category>
		<category><![CDATA[Speed Benchmarks]]></category>

		<guid isPermaLink="false">http://www.calypso88.com/?p=539</guid>
		<description><![CDATA[Since I had my benchmark code already warmed up from Friday and a photoshop doc open with my histograms, I figured I should make good on the updated speed tests that I promised a year ago. Here is basic math, receiving a huge boost between debug and release modes. The shaded bar is the duration [...]]]></description>
			<content:encoded><![CDATA[<p>Since I had my benchmark code already warmed up from Friday and a photoshop doc open with my histograms, I figured I should make good on the updated speed tests that <a href="http://www.calypso88.com/?p=174#comments">I promised</a> a year ago.</p>
<p>Here is basic math, receiving a huge boost between debug and release modes. The shaded bar is the duration of the call, so shorter means faster execution.</p>
<p><img src="http://www.calypso88.com/wp-content/uploads/2010/02/math_img1.gif" alt="speed benchmark: actionscript math operators" /></p>
<p>From here down, everything is running 10m iterations. The scale of these graphs is 560ms. Here's the difference in calling a static public variable, versus a local copy of same.</p>
<p><img src="http://www.calypso88.com/wp-content/uploads/2010/02/pi.gif" alt="speed benchmark: actionscript local var vs static public var" /></p>
<p>Finally, replacing the Math helper methods with some logic and basic math:</p>
<p><img src="http://www.calypso88.com/wp-content/uploads/2010/02/pow2.gif" alt="speed benchmark: actionscript math.pow squared" /><br />
<img src="http://www.calypso88.com/wp-content/uploads/2010/02/pow3.gif" alt="speed benchmark: actionscript math.pow cubed" /><br />
<img src="http://www.calypso88.com/wp-content/uploads/2010/02/min.gif" alt="speed benchmark: actionscript math.min" /><br />
<img src="http://www.calypso88.com/wp-content/uploads/2010/02/max.gif" alt="speed benchmark: actionscript math.max" /><br />
<img src="http://www.calypso88.com/wp-content/uploads/2010/02/abs.gif" alt="speed benchmark: actionscript math.abs" /><br />
<img src="http://www.calypso88.com/wp-content/uploads/2010/02/floor.gif" alt="speed benchmark: actionscript math.floor" /><br />
<img src="http://www.calypso88.com/wp-content/uploads/2010/02/ceil.gif" alt="speed benchmark: actionscript math.ceil" /><br />
<img src="http://www.calypso88.com/wp-content/uploads/2010/02/round.gif" alt="speed benchmark: actionscript math.round" /></p>
<p>These stack up pretty well with what I saw in the debug player <a href="http://www.calypso88.com/?p=174">a year ago</a> (although there is an overall speed increase in all the tests).</p>
<p>If anyone is curious, there is a slowdown in calculating powers of a number (i * i * i * i) as you have to reference that variable over and over - for me the break-even between stringing on more 'i's and just calling Math.pow() was around 60.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.calypso88.com/?feed=rss2&amp;p=539</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>AS3 Math Optimization &#8211; Math.random()</title>
		<link>http://www.calypso88.com/?p=524</link>
		<comments>http://www.calypso88.com/?p=524#comments</comments>
		<pubDate>Sat, 06 Feb 2010 07:37:55 +0000</pubDate>
		<dc:creator>Rob</dc:creator>
				<category><![CDATA[AS3 Speed Benchmarking]]></category>
		<category><![CDATA[Actionscript 3.0]]></category>
		<category><![CDATA[Optimization]]></category>
		<category><![CDATA[ActionScript]]></category>
		<category><![CDATA[Random Number Generator]]></category>

		<guid isPermaLink="false">http://www.calypso88.com/?p=524</guid>
		<description><![CDATA[I was messing around with some bitmap code this evening and I came across a performance bottleneck with some repeated calls to Math.random(). Since I haven't posted anything in a while, I decided to do some benchmarking and try out an alternate (psuedo) random number generator. I chose the XOR algorithm, primarily because AS3 is [...]]]></description>
			<content:encoded><![CDATA[<p>I was messing around with some bitmap code this evening and I came across a performance bottleneck with some repeated calls to Math.random(). Since I haven't posted anything in a while, I decided to do some benchmarking and try out an alternate (psuedo) random number generator.</p>
<p>I chose the <a href="http://en.wikipedia.org/wiki/Xorshift" target="_blank">XOR algorithm</a>, primarily because AS3 is lightning-quick with bit operations, and the algorithm is only 4 lines of code. Here are two versions I tried:</p>
<p><code>
<pre class="actionscript"><ol><li style="font-family: Monaco, Lucida Console, Lucida, 'Courier New', Courier, monospace; color: white; font-weight: normal; font-style: normal;"><div style="font-family: Monaco, Lucida Console, Lucida, 'Courier New', Courier, monospace; font-weight: normal; "><span style="color: #666666;">//  UINT</span></div></li><li style="font-family: Monaco, Lucida Console, Lucida, 'Courier New', Courier, monospace; color: white; font-weight: normal; font-style: normal;"><div style="font-family: Monaco, Lucida Console, Lucida, 'Courier New', Courier, monospace; font-weight: normal; ">&nbsp;</div></li><li style="font-family: Monaco, Lucida Console, Lucida, 'Courier New', Courier, monospace; color: white; font-weight: normal; font-style: normal;"><div style="font-family: Monaco, Lucida Console, Lucida, 'Courier New', Courier, monospace; font-weight: normal; "><span style="color: #F7De2D;">const</span> MAX_RATIO:<span style="color: #FFFFFF;">Number</span> = <span style="color: #FFFFFF;">1</span> / uint.<span style="color: #FFFFFF;">MAX_VALUE</span>;</div></li><li style="font-family: Monaco, Lucida Console, Lucida, 'Courier New', Courier, monospace; color: white; font-weight: normal; font-style: normal;"><div style="font-family: Monaco, Lucida Console, Lucida, 'Courier New', Courier, monospace; font-weight: normal; "><span style="color: #F7De2D;">var</span> r:uint = <span style="color: #FFFFFF;">Math</span>.<span style="color: #FFFFFF;">random</span><span style="color: #FFFFFF;">&#40;</span><span style="color: #FFFFFF;">&#41;</span> * uint.<span style="color: #FFFFFF;">MAX_VALUE</span>;</div></li><li style="font-family: Monaco, Lucida Console, Lucida, 'Courier New', Courier, monospace; color: white; font-weight: normal; font-style: normal;"><div style="font-family: Monaco, Lucida Console, Lucida, 'Courier New', Courier, monospace; font-weight: normal; ">&nbsp;</div></li><li style="font-family: Monaco, Lucida Console, Lucida, 'Courier New', Courier, monospace; color: white; font-weight: normal; font-style: normal;"><div style="font-family: Monaco, Lucida Console, Lucida, 'Courier New', Courier, monospace; font-weight: normal; "><span style="color: #666666;">//  returns a number from 0 - 1</span></div></li><li style="font-family: Monaco, Lucida Console, Lucida, 'Courier New', Courier, monospace; color: white; font-weight: normal; font-style: normal;"><div style="font-family: Monaco, Lucida Console, Lucida, 'Courier New', Courier, monospace; font-weight: normal; "><span style="color: #FF5E00;"><span style="color: #FFFF00;">function</span> XORandom</span><span style="color: #FFFFFF;">&#40;</span><span style="color: #FFFFFF;">&#41;</span>:<span style="color: #FFFFFF;">Number</span><span style="color: #FFFFFF;">&#123;</span></div></li><li style="font-family: Monaco, Lucida Console, Lucida, 'Courier New', Courier, monospace; color: white; font-weight: normal; font-style: normal;"><div style="font-family: Monaco, Lucida Console, Lucida, 'Courier New', Courier, monospace; font-weight: normal; ">	r ^= <span style="color: #FFFFFF;">&#40;</span>r &lt;&lt; <span style="color: #FFFFFF;">21</span><span style="color: #FFFFFF;">&#41;</span>;</div></li><li style="font-family: Monaco, Lucida Console, Lucida, 'Courier New', Courier, monospace; color: white; font-weight: normal; font-style: normal;"><div style="font-family: Monaco, Lucida Console, Lucida, 'Courier New', Courier, monospace; font-weight: normal; ">	r ^= <span style="color: #FFFFFF;">&#40;</span>r &gt;&gt;&gt; <span style="color: #FFFFFF;">35</span><span style="color: #FFFFFF;">&#41;</span>;</div></li><li style="font-family: Monaco, Lucida Console, Lucida, 'Courier New', Courier, monospace; color: white; font-weight: normal; font-style: normal;"><div style="font-family: Monaco, Lucida Console, Lucida, 'Courier New', Courier, monospace; font-weight: normal; ">	r ^= <span style="color: #FFFFFF;">&#40;</span>r &lt;&lt; <span style="color: #FFFFFF;">4</span><span style="color: #FFFFFF;">&#41;</span>;</div></li><li style="font-family: Monaco, Lucida Console, Lucida, 'Courier New', Courier, monospace; color: white; font-weight: normal; font-style: normal;"><div style="font-family: Monaco, Lucida Console, Lucida, 'Courier New', Courier, monospace; font-weight: normal; ">	<span style="color: #F7De2D;">return</span> <span style="color: #FFFFFF;">&#40;</span>r * MAX_RATIO<span style="color: #FFFFFF;">&#41;</span>;</div></li><li style="font-family: Monaco, Lucida Console, Lucida, 'Courier New', Courier, monospace; color: white; font-weight: normal; font-style: normal;"><div style="font-family: Monaco, Lucida Console, Lucida, 'Courier New', Courier, monospace; font-weight: normal; "><span style="color: #FFFFFF;">&#125;</span></div></li></ol></pre>
<p></code></p>
<p><code>
<pre class="actionscript"><ol><li style="font-family: Monaco, Lucida Console, Lucida, 'Courier New', Courier, monospace; color: white; font-weight: normal; font-style: normal;"><div style="font-family: Monaco, Lucida Console, Lucida, 'Courier New', Courier, monospace; font-weight: normal; "><span style="color: #666666;">//  INT</span></div></li><li style="font-family: Monaco, Lucida Console, Lucida, 'Courier New', Courier, monospace; color: white; font-weight: normal; font-style: normal;"><div style="font-family: Monaco, Lucida Console, Lucida, 'Courier New', Courier, monospace; font-weight: normal; ">&nbsp;</div></li><li style="font-family: Monaco, Lucida Console, Lucida, 'Courier New', Courier, monospace; color: white; font-weight: normal; font-style: normal;"><div style="font-family: Monaco, Lucida Console, Lucida, 'Courier New', Courier, monospace; font-weight: normal; "><span style="color: #F7De2D;">const</span> MAX_RATIO:<span style="color: #FFFFFF;">Number</span> = <span style="color: #FFFFFF;">1</span> / <span style="color: #FFFFFF;">int</span>.<span style="color: #FFFFFF;">MAX_VALUE</span>;</div></li><li style="font-family: Monaco, Lucida Console, Lucida, 'Courier New', Courier, monospace; color: white; font-weight: normal; font-style: normal;"><div style="font-family: Monaco, Lucida Console, Lucida, 'Courier New', Courier, monospace; font-weight: normal; "><span style="color: #F7De2D;">const</span> NEGA_MAX_RATIO:<span style="color: #FFFFFF;">Number</span> = -MAX_RATIO;</div></li><li style="font-family: Monaco, Lucida Console, Lucida, 'Courier New', Courier, monospace; color: white; font-weight: normal; font-style: normal;"><div style="font-family: Monaco, Lucida Console, Lucida, 'Courier New', Courier, monospace; font-weight: normal; "><span style="color: #F7De2D;">var</span> r:<span style="color: #FFFFFF;">int</span> = <span style="color: #FFFFFF;">Math</span>.<span style="color: #FFFFFF;">random</span><span style="color: #FFFFFF;">&#40;</span><span style="color: #FFFFFF;">&#41;</span> * <span style="color: #FFFFFF;">int</span>.<span style="color: #FFFFFF;">MAX_VALUE</span>;</div></li><li style="font-family: Monaco, Lucida Console, Lucida, 'Courier New', Courier, monospace; color: white; font-weight: normal; font-style: normal;"><div style="font-family: Monaco, Lucida Console, Lucida, 'Courier New', Courier, monospace; font-weight: normal; ">&nbsp;</div></li><li style="font-family: Monaco, Lucida Console, Lucida, 'Courier New', Courier, monospace; color: white; font-weight: normal; font-style: normal;"><div style="font-family: Monaco, Lucida Console, Lucida, 'Courier New', Courier, monospace; font-weight: normal; "><span style="color: #666666;">//  returns a number from 0 - 1</span></div></li><li style="font-family: Monaco, Lucida Console, Lucida, 'Courier New', Courier, monospace; color: white; font-weight: normal; font-style: normal;"><div style="font-family: Monaco, Lucida Console, Lucida, 'Courier New', Courier, monospace; font-weight: normal; "><span style="color: #666666;">//  comment out line 13 for -1 - 1</span></div></li><li style="font-family: Monaco, Lucida Console, Lucida, 'Courier New', Courier, monospace; color: white; font-weight: normal; font-style: normal;"><div style="font-family: Monaco, Lucida Console, Lucida, 'Courier New', Courier, monospace; font-weight: normal; "><span style="color: #FF5E00;"><span style="color: #FFFF00;">function</span> XORandom</span><span style="color: #FFFFFF;">&#40;</span><span style="color: #FFFFFF;">&#41;</span>:<span style="color: #FFFFFF;">Number</span><span style="color: #FFFFFF;">&#123;</span></div></li><li style="font-family: Monaco, Lucida Console, Lucida, 'Courier New', Courier, monospace; color: white; font-weight: normal; font-style: normal;"><div style="font-family: Monaco, Lucida Console, Lucida, 'Courier New', Courier, monospace; font-weight: normal; ">	r ^= <span style="color: #FFFFFF;">&#40;</span>r &lt;&lt; <span style="color: #FFFFFF;">21</span><span style="color: #FFFFFF;">&#41;</span>;</div></li><li style="font-family: Monaco, Lucida Console, Lucida, 'Courier New', Courier, monospace; color: white; font-weight: normal; font-style: normal;"><div style="font-family: Monaco, Lucida Console, Lucida, 'Courier New', Courier, monospace; font-weight: normal; ">	r ^= <span style="color: #FFFFFF;">&#40;</span>r &gt;&gt;&gt; <span style="color: #FFFFFF;">35</span><span style="color: #FFFFFF;">&#41;</span>;</div></li><li style="font-family: Monaco, Lucida Console, Lucida, 'Courier New', Courier, monospace; color: white; font-weight: normal; font-style: normal;"><div style="font-family: Monaco, Lucida Console, Lucida, 'Courier New', Courier, monospace; font-weight: normal; ">	r ^= <span style="color: #FFFFFF;">&#40;</span>r &lt;&lt; <span style="color: #FFFFFF;">4</span><span style="color: #FFFFFF;">&#41;</span>;</div></li><li style="font-family: Monaco, Lucida Console, Lucida, 'Courier New', Courier, monospace; color: white; font-weight: normal; font-style: normal;"><div style="font-family: Monaco, Lucida Console, Lucida, 'Courier New', Courier, monospace; font-weight: normal; ">	<span style="color: #F7De2D;">if</span><span style="color: #FFFFFF;">&#40;</span>r &lt; <span style="color: #FFFFFF;">0</span><span style="color: #FFFFFF;">&#41;</span> <span style="color: #F7De2D;">return</span> r * MAX_RATIO;</div></li><li style="font-family: Monaco, Lucida Console, Lucida, 'Courier New', Courier, monospace; color: white; font-weight: normal; font-style: normal;"><div style="font-family: Monaco, Lucida Console, Lucida, 'Courier New', Courier, monospace; font-weight: normal; ">	<span style="color: #F7De2D;">return</span> r * NEGA_MAX_RATIO;</div></li><li style="font-family: Monaco, Lucida Console, Lucida, 'Courier New', Courier, monospace; color: white; font-weight: normal; font-style: normal;"><div style="font-family: Monaco, Lucida Console, Lucida, 'Courier New', Courier, monospace; font-weight: normal; "><span style="color: #FFFFFF;">&#125;</span></div></li></ol></pre>
<p></code></p>
<p>It's worth noting that this algorithm works from a seed number. For my purposes, picking one random seed and iterating is fine, but this function is predictable enough that you wouldn't want to use this method for crypto or anything where you'd want "very random" data sets. This also could be useful in some situations where you'd want to replay a set of random numbers - such as generating enemies or levels in a game and then creating a replay by saving the seed number.</p>
<p>For my benchmark, I ran 25 sets of 10 million iterations on each function, using the 10.0 release player in Safari.</p>
<p><img src="http://www.calypso88.com/wp-content/uploads/2010/02/random_bench.gif" alt="acctionscript math.random optimization" /></p>
<p>Interestingly, the logic to gate negative numbers in the signed-int version was enough to push it out quite a bit past the uint version. All told, the uint algorithm runs in just under one fourth the time it takes to call Math.random().</p>
<p>As always, <a href="http://en.wikipedia.org/wiki/Xorshift" target="_blank">Wikipedia</a> will tell you as much as you want to know about the ins and outs of this algorithm and how it stacks up against other generators. And, just for fun, here's a frequency graph of the output.</p>

<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000"
			id="fm_random_983730954"
			class="flashmovie"
			width="460"
			height="250">
	<param name="movie" value="/wp-content/uploads/2010/02/random.swf" />
	<!--[if !IE]>-->
	<object	type="application/x-shockwave-flash"
			data="/wp-content/uploads/2010/02/random.swf"
			name="fm_random_983730954"
			width="460"
			height="250">
	<!--<![endif]-->
		
<p><a href="http://adobe.com/go/getflashplayer"><img src="http://www.adobe.com/images/shared/download_buttons/get_flash_player.gif" alt="Get Adobe Flash player" /></a></p>

	<!--[if !IE]>-->
	</object>
	<!--<![endif]-->
</object>
]]></content:encoded>
			<wfw:commentRss>http://www.calypso88.com/?feed=rss2&amp;p=524</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Rotating objects toward a point</title>
		<link>http://www.calypso88.com/?p=512</link>
		<comments>http://www.calypso88.com/?p=512#comments</comments>
		<pubDate>Tue, 15 Dec 2009 02:11:13 +0000</pubDate>
		<dc:creator>Rob</dc:creator>
				<category><![CDATA[Actionscript 3.0]]></category>

		<guid isPermaLink="false">http://www.calypso88.com/?p=512</guid>
		<description><![CDATA[I've seen a lot of questions about rotation in AS3 lately so I thought I'd post a quick writeup. It's a deceptively simple formula but there are a couple snags that can trip you up if you aren't aware of them. 
<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000"
			id="fm_rotate_00_1198476810"
			class="flashmovie"
			width="460"
			height="170">
	<param name="movie" value="/wp-content/uploads/2009/12/rotate_00.swf" />
	<!--[if !IE]>-->
	<object	type="application/x-shockwave-flash"
			data="/wp-content/uploads/2009/12/rotate_00.swf"
			name="fm_rotate_00_1198476810"
			width="460"
			height="170">
	<!--<![endif]-->
		 
	<!--[if !IE]>-->
	</object>
	<!--<![endif]-->
</object> First off - Flash uses [...]]]></description>
			<content:encoded><![CDATA[<p>I've seen a lot of questions about rotation in AS3 lately so I thought I'd post a quick writeup. It's a deceptively simple formula but there are a couple snags that can trip you up if you aren't aware of them.</p>

<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000"
			id="fm_rotate_00_718171022"
			class="flashmovie"
			width="460"
			height="170">
	<param name="movie" value="/wp-content/uploads/2009/12/rotate_00.swf" />
	<!--[if !IE]>-->
	<object	type="application/x-shockwave-flash"
			data="/wp-content/uploads/2009/12/rotate_00.swf"
			name="fm_rotate_00_718171022"
			width="460"
			height="170">
	<!--<![endif]-->
		
<p><a href="http://adobe.com/go/getflashplayer"><img src="http://www.adobe.com/images/shared/download_buttons/get_flash_player.gif" alt="Get Adobe Flash player" /></a></p>

	<!--[if !IE]>-->
	</object>
	<!--<![endif]-->
</object>
<p>First off - Flash uses a fairly confusing rotational layout. A DisplayObject's rotation is measured in degrees from 0, which is at 3 O'Clock. Degrees extend clockwise to 9 O'Clock (180°) where an odd thing happens. Flash converts any number you pass in to the closest possible value to zero, so 181° gets recorded as -179°. This is still technically correct, but it can wreak havoc on your code if you're not expecting it.</p>
<p>Here's a quick method to get the positive angle back:</p>
<p><code>
<pre class="actionscript"><ol><li style="font-family: Monaco, Lucida Console, Lucida, 'Courier New', Courier, monospace; color: white; font-weight: normal; font-style: normal;"><div style="font-family: Monaco, Lucida Console, Lucida, 'Courier New', Courier, monospace; font-weight: normal; ">spinner.<span style="color: #71A1CE;">rotation</span> = <span style="color: #FFFFFF;">181</span>;</div></li><li style="font-family: Monaco, Lucida Console, Lucida, 'Courier New', Courier, monospace; color: white; font-weight: normal; font-style: normal;"><div style="font-family: Monaco, Lucida Console, Lucida, 'Courier New', Courier, monospace; font-weight: normal; "><span style="color: #FFFFFF;">trace</span><span style="color: #FFFFFF;">&#40;</span>spinner.<span style="color: #71A1CE;">rotation</span><span style="color: #FFFFFF;">&#41;</span>;		<span style="color: #666666;">//  -179</span></div></li><li style="font-family: Monaco, Lucida Console, Lucida, 'Courier New', Courier, monospace; color: white; font-weight: normal; font-style: normal;"><div style="font-family: Monaco, Lucida Console, Lucida, 'Courier New', Courier, monospace; font-weight: normal; "><span style="color: #F7De2D;">var</span> angle:<span style="color: #FFFFFF;">Number</span> = spinner.<span style="color: #71A1CE;">rotation</span>;	<span style="color: #666666;">//  -179</span></div></li><li style="font-family: Monaco, Lucida Console, Lucida, 'Courier New', Courier, monospace; color: white; font-weight: normal; font-style: normal;"><div style="font-family: Monaco, Lucida Console, Lucida, 'Courier New', Courier, monospace; font-weight: normal; ">angle = <span style="color: #FFFFFF;">&#40;</span>angle + <span style="color: #FFFFFF;">360</span><span style="color: #FFFFFF;">&#41;</span> % <span style="color: #FFFFFF;">360</span>		<span style="color: #666666;">//  181</span></div></li></ol></pre>
<p></code></p>
<p>Alright - what people really want to know is how to calculate the angle between an object and the mouse, or another object. The solution is to take the arc-tangent of the offset in y, divided by the offset in x, which, if you remember your trig from highschool, would be the two perpendicular sides of your right triangle. Here's what the code looks like:</p>
<p><code>
<pre class="actionscript"><ol><li style="font-family: Monaco, Lucida Console, Lucida, 'Courier New', Courier, monospace; color: white; font-weight: normal; font-style: normal;"><div style="font-family: Monaco, Lucida Console, Lucida, 'Courier New', Courier, monospace; font-weight: normal; ">package <span style="color: #FFFFFF;">&#123;</span></div></li><li style="font-family: Monaco, Lucida Console, Lucida, 'Courier New', Courier, monospace; color: white; font-weight: normal; font-style: normal;"><div style="font-family: Monaco, Lucida Console, Lucida, 'Courier New', Courier, monospace; font-weight: normal; ">&nbsp;</div></li><li style="font-family: Monaco, Lucida Console, Lucida, 'Courier New', Courier, monospace; color: white; font-weight: normal; font-style: normal;"><div style="font-family: Monaco, Lucida Console, Lucida, 'Courier New', Courier, monospace; font-weight: normal; ">	<span style="color: #666666;">/*</span></div></li><li style="font-family: Monaco, Lucida Console, Lucida, 'Courier New', Courier, monospace; color: white; font-weight: normal; font-style: normal;"><div style="font-family: Monaco, Lucida Console, Lucida, 'Courier New', Courier, monospace; font-weight: normal; "><span style="color: #666666;">	*	Flash 10.0 ? ActionScript 3.0</span></div></li><li style="font-family: Monaco, Lucida Console, Lucida, 'Courier New', Courier, monospace; color: white; font-weight: normal; font-style: normal;"><div style="font-family: Monaco, Lucida Console, Lucida, 'Courier New', Courier, monospace; font-weight: normal; "><span style="color: #666666;">	*	www.calypso88.com</span></div></li><li style="font-family: Monaco, Lucida Console, Lucida, 'Courier New', Courier, monospace; color: white; font-weight: normal; font-style: normal;"><div style="font-family: Monaco, Lucida Console, Lucida, 'Courier New', Courier, monospace; font-weight: normal; "><span style="color: #666666;">	*/</span></div></li><li style="font-family: Monaco, Lucida Console, Lucida, 'Courier New', Courier, monospace; color: white; font-weight: normal; font-style: normal;"><div style="font-family: Monaco, Lucida Console, Lucida, 'Courier New', Courier, monospace; font-weight: normal; ">&nbsp;</div></li><li style="font-family: Monaco, Lucida Console, Lucida, 'Courier New', Courier, monospace; color: white; font-weight: normal; font-style: normal;"><div style="font-family: Monaco, Lucida Console, Lucida, 'Courier New', Courier, monospace; font-weight: normal; ">	<span style="color: #666666;">//--------------------------------------</span></div></li><li style="font-family: Monaco, Lucida Console, Lucida, 'Courier New', Courier, monospace; color: white; font-weight: normal; font-style: normal;"><div style="font-family: Monaco, Lucida Console, Lucida, 'Courier New', Courier, monospace; font-weight: normal; ">	<span style="color: #666666;">// PACKAGES</span></div></li><li style="font-family: Monaco, Lucida Console, Lucida, 'Courier New', Courier, monospace; color: white; font-weight: normal; font-style: normal;"><div style="font-family: Monaco, Lucida Console, Lucida, 'Courier New', Courier, monospace; font-weight: normal; ">	<span style="color: #666666;">//--------------------------------------</span></div></li><li style="font-family: Monaco, Lucida Console, Lucida, 'Courier New', Courier, monospace; color: white; font-weight: normal; font-style: normal;"><div style="font-family: Monaco, Lucida Console, Lucida, 'Courier New', Courier, monospace; font-weight: normal; ">&nbsp;</div></li><li style="font-family: Monaco, Lucida Console, Lucida, 'Courier New', Courier, monospace; color: white; font-weight: normal; font-style: normal;"><div style="font-family: Monaco, Lucida Console, Lucida, 'Courier New', Courier, monospace; font-weight: normal; ">		<span style="color: #F7De2D;">import</span> flash.<span style="color: #71A1CE;">display</span>.<span style="color: #71A1CE;">Sprite</span>;</div></li><li style="font-family: Monaco, Lucida Console, Lucida, 'Courier New', Courier, monospace; color: white; font-weight: normal; font-style: normal;"><div style="font-family: Monaco, Lucida Console, Lucida, 'Courier New', Courier, monospace; font-weight: normal; ">		<span style="color: #F7De2D;">import</span> flash.<span style="color: #71A1CE;">display</span>.<span style="color: #71A1CE;">DisplayObject</span>;</div></li><li style="font-family: Monaco, Lucida Console, Lucida, 'Courier New', Courier, monospace; color: white; font-weight: normal; font-style: normal;"><div style="font-family: Monaco, Lucida Console, Lucida, 'Courier New', Courier, monospace; font-weight: normal; ">		<span style="color: #F7De2D;">import</span> flash.<span style="color: #71A1CE;">geom</span>.<span style="color: #71A1CE;">Point</span>;</div></li><li style="font-family: Monaco, Lucida Console, Lucida, 'Courier New', Courier, monospace; color: white; font-weight: normal; font-style: normal;"><div style="font-family: Monaco, Lucida Console, Lucida, 'Courier New', Courier, monospace; font-weight: normal; ">		<span style="color: #F7De2D;">import</span> flash.<span style="color: #71A1CE;">events</span>.<span style="color: #71A1CE;">Event</span>;</div></li><li style="font-family: Monaco, Lucida Console, Lucida, 'Courier New', Courier, monospace; color: white; font-weight: normal; font-style: normal;"><div style="font-family: Monaco, Lucida Console, Lucida, 'Courier New', Courier, monospace; font-weight: normal; ">&nbsp;</div></li><li style="font-family: Monaco, Lucida Console, Lucida, 'Courier New', Courier, monospace; color: white; font-weight: normal; font-style: normal;"><div style="font-family: Monaco, Lucida Console, Lucida, 'Courier New', Courier, monospace; font-weight: normal; ">	<span style="color: #F7De2D;">public</span> final <span style="color: #FFFFFF;">class</span> Arrow <span style="color: #FFFFFF;">extends</span> Sprite <span style="color: #FFFFFF;">&#123;</span></div></li><li style="font-family: Monaco, Lucida Console, Lucida, 'Courier New', Courier, monospace; color: white; font-weight: normal; font-style: normal;"><div style="font-family: Monaco, Lucida Console, Lucida, 'Courier New', Courier, monospace; font-weight: normal; ">&nbsp;</div></li><li style="font-family: Monaco, Lucida Console, Lucida, 'Courier New', Courier, monospace; color: white; font-weight: normal; font-style: normal;"><div style="font-family: Monaco, Lucida Console, Lucida, 'Courier New', Courier, monospace; font-weight: normal; ">		<span style="color: #666666;">//--------------------------------------</span></div></li><li style="font-family: Monaco, Lucida Console, Lucida, 'Courier New', Courier, monospace; color: white; font-weight: normal; font-style: normal;"><div style="font-family: Monaco, Lucida Console, Lucida, 'Courier New', Courier, monospace; font-weight: normal; ">		<span style="color: #666666;">//  CONSTRUCTOR</span></div></li><li style="font-family: Monaco, Lucida Console, Lucida, 'Courier New', Courier, monospace; color: white; font-weight: normal; font-style: normal;"><div style="font-family: Monaco, Lucida Console, Lucida, 'Courier New', Courier, monospace; font-weight: normal; ">		<span style="color: #666666;">//--------------------------------------</span></div></li><li style="font-family: Monaco, Lucida Console, Lucida, 'Courier New', Courier, monospace; color: white; font-weight: normal; font-style: normal;"><div style="font-family: Monaco, Lucida Console, Lucida, 'Courier New', Courier, monospace; font-weight: normal; ">&nbsp;</div></li><li style="font-family: Monaco, Lucida Console, Lucida, 'Courier New', Courier, monospace; color: white; font-weight: normal; font-style: normal;"><div style="font-family: Monaco, Lucida Console, Lucida, 'Courier New', Courier, monospace; font-weight: normal; ">			<span style="color: #F7De2D;">public</span> <span style="color: #FF5E00;"><span style="color: #FFFF00;">function</span> Arrow</span><span style="color: #FFFFFF;">&#40;</span><span style="color: #FFFFFF;">&#41;</span><span style="color: #FFFFFF;">&#123;</span></div></li><li style="font-family: Monaco, Lucida Console, Lucida, 'Courier New', Courier, monospace; color: white; font-weight: normal; font-style: normal;"><div style="font-family: Monaco, Lucida Console, Lucida, 'Courier New', Courier, monospace; font-weight: normal; ">				<span style="color: #FFFFFF;">super</span><span style="color: #FFFFFF;">&#40;</span><span style="color: #FFFFFF;">&#41;</span>;</div></li><li style="font-family: Monaco, Lucida Console, Lucida, 'Courier New', Courier, monospace; color: white; font-weight: normal; font-style: normal;"><div style="font-family: Monaco, Lucida Console, Lucida, 'Courier New', Courier, monospace; font-weight: normal; ">				addEventListener<span style="color: #FFFFFF;">&#40;</span>Event.<span style="color: #71A1CE;">ENTER_FRAME</span>, enterFrame<span style="color: #FFFFFF;">&#41;</span>;</div></li><li style="font-family: Monaco, Lucida Console, Lucida, 'Courier New', Courier, monospace; color: white; font-weight: normal; font-style: normal;"><div style="font-family: Monaco, Lucida Console, Lucida, 'Courier New', Courier, monospace; font-weight: normal; ">			<span style="color: #FFFFFF;">&#125;</span></div></li><li style="font-family: Monaco, Lucida Console, Lucida, 'Courier New', Courier, monospace; color: white; font-weight: normal; font-style: normal;"><div style="font-family: Monaco, Lucida Console, Lucida, 'Courier New', Courier, monospace; font-weight: normal; ">&nbsp;</div></li><li style="font-family: Monaco, Lucida Console, Lucida, 'Courier New', Courier, monospace; color: white; font-weight: normal; font-style: normal;"><div style="font-family: Monaco, Lucida Console, Lucida, 'Courier New', Courier, monospace; font-weight: normal; ">	  	<span style="color: #666666;">//--------------------------------------</span></div></li><li style="font-family: Monaco, Lucida Console, Lucida, 'Courier New', Courier, monospace; color: white; font-weight: normal; font-style: normal;"><div style="font-family: Monaco, Lucida Console, Lucida, 'Courier New', Courier, monospace; font-weight: normal; ">	  	<span style="color: #666666;">//  EVENT HANDLERS</span></div></li><li style="font-family: Monaco, Lucida Console, Lucida, 'Courier New', Courier, monospace; color: white; font-weight: normal; font-style: normal;"><div style="font-family: Monaco, Lucida Console, Lucida, 'Courier New', Courier, monospace; font-weight: normal; ">	  	<span style="color: #666666;">//--------------------------------------</span></div></li><li style="font-family: Monaco, Lucida Console, Lucida, 'Courier New', Courier, monospace; color: white; font-weight: normal; font-style: normal;"><div style="font-family: Monaco, Lucida Console, Lucida, 'Courier New', Courier, monospace; font-weight: normal; ">&nbsp;</div></li><li style="font-family: Monaco, Lucida Console, Lucida, 'Courier New', Courier, monospace; color: white; font-weight: normal; font-style: normal;"><div style="font-family: Monaco, Lucida Console, Lucida, 'Courier New', Courier, monospace; font-weight: normal; ">			<span style="color: #F7De2D;">private</span> <span style="color: #FF5E00;"><span style="color: #FFFF00;">function</span> enterFrame</span><span style="color: #FFFFFF;">&#40;</span><span style="color: #FFFFFF;">e</span>:Event<span style="color: #FFFFFF;">&#41;</span>:<span style="color: #FFFFFF;">void</span><span style="color: #FFFFFF;">&#123;</span></div></li><li style="font-family: Monaco, Lucida Console, Lucida, 'Courier New', Courier, monospace; color: white; font-weight: normal; font-style: normal;"><div style="font-family: Monaco, Lucida Console, Lucida, 'Courier New', Courier, monospace; font-weight: normal; ">				<span style="color: #F7De2D;">var</span> p1:Point = <span style="color: #FFFFFF;">new</span> Point<span style="color: #FFFFFF;">&#40;</span><span style="color: #FFFFFF;">this</span>.<span style="color: #71A1CE;">x</span>, <span style="color: #FFFFFF;">this</span>.<span style="color: #71A1CE;">y</span><span style="color: #FFFFFF;">&#41;</span>;</div></li><li style="font-family: Monaco, Lucida Console, Lucida, 'Courier New', Courier, monospace; color: white; font-weight: normal; font-style: normal;"><div style="font-family: Monaco, Lucida Console, Lucida, 'Courier New', Courier, monospace; font-weight: normal; ">				<span style="color: #F7De2D;">var</span> p2:Point = <span style="color: #FFFFFF;">new</span> Point<span style="color: #FFFFFF;">&#40;</span><span style="color: #FFFFFF;">stage</span>.<span style="color: #71A1CE;">mouseX</span>, <span style="color: #FFFFFF;">stage</span>.<span style="color: #71A1CE;">mouseY</span><span style="color: #FFFFFF;">&#41;</span>;</div></li><li style="font-family: Monaco, Lucida Console, Lucida, 'Courier New', Courier, monospace; color: white; font-weight: normal; font-style: normal;"><div style="font-family: Monaco, Lucida Console, Lucida, 'Courier New', Courier, monospace; font-weight: normal; ">				<span style="color: #FFFFFF;">this</span>.<span style="color: #71A1CE;">rotation</span> = angleBetween<span style="color: #FFFFFF;">&#40;</span>p2, p1<span style="color: #FFFFFF;">&#41;</span>;</div></li><li style="font-family: Monaco, Lucida Console, Lucida, 'Courier New', Courier, monospace; color: white; font-weight: normal; font-style: normal;"><div style="font-family: Monaco, Lucida Console, Lucida, 'Courier New', Courier, monospace; font-weight: normal; ">			<span style="color: #FFFFFF;">&#125;</span></div></li><li style="font-family: Monaco, Lucida Console, Lucida, 'Courier New', Courier, monospace; color: white; font-weight: normal; font-style: normal;"><div style="font-family: Monaco, Lucida Console, Lucida, 'Courier New', Courier, monospace; font-weight: normal; ">&nbsp;</div></li><li style="font-family: Monaco, Lucida Console, Lucida, 'Courier New', Courier, monospace; color: white; font-weight: normal; font-style: normal;"><div style="font-family: Monaco, Lucida Console, Lucida, 'Courier New', Courier, monospace; font-weight: normal; ">		<span style="color: #666666;">//--------------------------------------</span></div></li><li style="font-family: Monaco, Lucida Console, Lucida, 'Courier New', Courier, monospace; color: white; font-weight: normal; font-style: normal;"><div style="font-family: Monaco, Lucida Console, Lucida, 'Courier New', Courier, monospace; font-weight: normal; ">		<span style="color: #666666;">//  PRIVATE &amp; PROTECTED INSTANCE METHODS</span></div></li><li style="font-family: Monaco, Lucida Console, Lucida, 'Courier New', Courier, monospace; color: white; font-weight: normal; font-style: normal;"><div style="font-family: Monaco, Lucida Console, Lucida, 'Courier New', Courier, monospace; font-weight: normal; ">		<span style="color: #666666;">//--------------------------------------</span></div></li><li style="font-family: Monaco, Lucida Console, Lucida, 'Courier New', Courier, monospace; color: white; font-weight: normal; font-style: normal;"><div style="font-family: Monaco, Lucida Console, Lucida, 'Courier New', Courier, monospace; font-weight: normal; ">&nbsp;</div></li><li style="font-family: Monaco, Lucida Console, Lucida, 'Courier New', Courier, monospace; color: white; font-weight: normal; font-style: normal;"><div style="font-family: Monaco, Lucida Console, Lucida, 'Courier New', Courier, monospace; font-weight: normal; ">			<span style="color: #F7De2D;">private</span> <span style="color: #FF5E00;"><span style="color: #FFFF00;">function</span> angleBetween</span><span style="color: #FFFFFF;">&#40;</span>p1:Point, p2:Point<span style="color: #FFFFFF;">&#41;</span>:<span style="color: #FFFFFF;">Number</span><span style="color: #FFFFFF;">&#123;</span></div></li><li style="font-family: Monaco, Lucida Console, Lucida, 'Courier New', Courier, monospace; color: white; font-weight: normal; font-style: normal;"><div style="font-family: Monaco, Lucida Console, Lucida, 'Courier New', Courier, monospace; font-weight: normal; ">				<span style="color: #F7De2D;">var</span> deltaX:<span style="color: #FFFFFF;">Number</span> = p1.<span style="color: #71A1CE;">x</span> - p2.<span style="color: #71A1CE;">x</span>;</div></li><li style="font-family: Monaco, Lucida Console, Lucida, 'Courier New', Courier, monospace; color: white; font-weight: normal; font-style: normal;"><div style="font-family: Monaco, Lucida Console, Lucida, 'Courier New', Courier, monospace; font-weight: normal; ">				<span style="color: #F7De2D;">var</span> deltaY:<span style="color: #FFFFFF;">Number</span> = p1.<span style="color: #71A1CE;">y</span> - p2.<span style="color: #71A1CE;">y</span>;</div></li><li style="font-family: Monaco, Lucida Console, Lucida, 'Courier New', Courier, monospace; color: white; font-weight: normal; font-style: normal;"><div style="font-family: Monaco, Lucida Console, Lucida, 'Courier New', Courier, monospace; font-weight: normal; ">				<span style="color: #F7De2D;">var</span> angle:<span style="color: #FFFFFF;">Number</span> = <span style="color: #FFFFFF;">Math</span>.<span style="color: #FFFFFF;">atan2</span><span style="color: #FFFFFF;">&#40;</span>deltaY, deltaX<span style="color: #FFFFFF;">&#41;</span>;		<span style="color: #666666;">//  in radians</span></div></li><li style="font-family: Monaco, Lucida Console, Lucida, 'Courier New', Courier, monospace; color: white; font-weight: normal; font-style: normal;"><div style="font-family: Monaco, Lucida Console, Lucida, 'Courier New', Courier, monospace; font-weight: normal; ">				<span style="color: #F7De2D;">return</span> radiansToDegrees<span style="color: #FFFFFF;">&#40;</span>angle<span style="color: #FFFFFF;">&#41;</span>;</div></li><li style="font-family: Monaco, Lucida Console, Lucida, 'Courier New', Courier, monospace; color: white; font-weight: normal; font-style: normal;"><div style="font-family: Monaco, Lucida Console, Lucida, 'Courier New', Courier, monospace; font-weight: normal; ">			<span style="color: #FFFFFF;">&#125;</span></div></li><li style="font-family: Monaco, Lucida Console, Lucida, 'Courier New', Courier, monospace; color: white; font-weight: normal; font-style: normal;"><div style="font-family: Monaco, Lucida Console, Lucida, 'Courier New', Courier, monospace; font-weight: normal; ">&nbsp;</div></li><li style="font-family: Monaco, Lucida Console, Lucida, 'Courier New', Courier, monospace; color: white; font-weight: normal; font-style: normal;"><div style="font-family: Monaco, Lucida Console, Lucida, 'Courier New', Courier, monospace; font-weight: normal; ">			<span style="color: #F7De2D;">private</span> <span style="color: #FF5E00;"><span style="color: #FFFF00;">function</span> radiansToDegrees</span><span style="color: #FFFFFF;">&#40;</span>r:<span style="color: #FFFFFF;">Number</span><span style="color: #FFFFFF;">&#41;</span>:<span style="color: #FFFFFF;">Number</span><span style="color: #FFFFFF;">&#123;</span></div></li><li style="font-family: Monaco, Lucida Console, Lucida, 'Courier New', Courier, monospace; color: white; font-weight: normal; font-style: normal;"><div style="font-family: Monaco, Lucida Console, Lucida, 'Courier New', Courier, monospace; font-weight: normal; ">				<span style="color: #F7De2D;">return</span><span style="color: #FFFFFF;">&#40;</span>r * <span style="color: #FFFFFF;">&#40;</span><span style="color: #FFFFFF;">180</span> / <span style="color: #FFFFFF;">Math</span>.<span style="color: #FFFFFF;">PI</span><span style="color: #FFFFFF;">&#41;</span><span style="color: #FFFFFF;">&#41;</span>;</div></li><li style="font-family: Monaco, Lucida Console, Lucida, 'Courier New', Courier, monospace; color: white; font-weight: normal; font-style: normal;"><div style="font-family: Monaco, Lucida Console, Lucida, 'Courier New', Courier, monospace; font-weight: normal; ">			<span style="color: #FFFFFF;">&#125;</span></div></li><li style="font-family: Monaco, Lucida Console, Lucida, 'Courier New', Courier, monospace; color: white; font-weight: normal; font-style: normal;"><div style="font-family: Monaco, Lucida Console, Lucida, 'Courier New', Courier, monospace; font-weight: normal; ">&nbsp;</div></li><li style="font-family: Monaco, Lucida Console, Lucida, 'Courier New', Courier, monospace; color: white; font-weight: normal; font-style: normal;"><div style="font-family: Monaco, Lucida Console, Lucida, 'Courier New', Courier, monospace; font-weight: normal; ">			<span style="color: #F7De2D;">private</span> <span style="color: #FF5E00;"><span style="color: #FFFF00;">function</span> degreesToRadians</span><span style="color: #FFFFFF;">&#40;</span>d:<span style="color: #FFFFFF;">Number</span><span style="color: #FFFFFF;">&#41;</span>:<span style="color: #FFFFFF;">Number</span><span style="color: #FFFFFF;">&#123;</span></div></li><li style="font-family: Monaco, Lucida Console, Lucida, 'Courier New', Courier, monospace; color: white; font-weight: normal; font-style: normal;"><div style="font-family: Monaco, Lucida Console, Lucida, 'Courier New', Courier, monospace; font-weight: normal; ">				<span style="color: #F7De2D;">return</span><span style="color: #FFFFFF;">&#40;</span>d * <span style="color: #FFFFFF;">&#40;</span><span style="color: #FFFFFF;">Math</span>.<span style="color: #FFFFFF;">PI</span> / <span style="color: #FFFFFF;">180</span><span style="color: #FFFFFF;">&#41;</span><span style="color: #FFFFFF;">&#41;</span>;</div></li><li style="font-family: Monaco, Lucida Console, Lucida, 'Courier New', Courier, monospace; color: white; font-weight: normal; font-style: normal;"><div style="font-family: Monaco, Lucida Console, Lucida, 'Courier New', Courier, monospace; font-weight: normal; ">			<span style="color: #FFFFFF;">&#125;</span></div></li><li style="font-family: Monaco, Lucida Console, Lucida, 'Courier New', Courier, monospace; color: white; font-weight: normal; font-style: normal;"><div style="font-family: Monaco, Lucida Console, Lucida, 'Courier New', Courier, monospace; font-weight: normal; ">	<span style="color: #FFFFFF;">&#125;</span></div></li><li style="font-family: Monaco, Lucida Console, Lucida, 'Courier New', Courier, monospace; color: white; font-weight: normal; font-style: normal;"><div style="font-family: Monaco, Lucida Console, Lucida, 'Courier New', Courier, monospace; font-weight: normal; "><span style="color: #FFFFFF;">&#125;</span></div></li></ol></pre>
<p></code></p>
<p>The last surprise is that the arc-tangent comes back in radians (&pi; radians = 180° degrees) so you'll need to convert back to degrees before you set the rotation. Here is the final result applied to a few dozen arrows.</p>

<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000"
			id="fm_rotate_01_635233008"
			class="flashmovie"
			width="460"
			height="325">
	<param name="movie" value="/wp-content/uploads/2009/12/rotate_01.swf" />
	<!--[if !IE]>-->
	<object	type="application/x-shockwave-flash"
			data="/wp-content/uploads/2009/12/rotate_01.swf"
			name="fm_rotate_01_635233008"
			width="460"
			height="325">
	<!--<![endif]-->
		
<p><a href="http://adobe.com/go/getflashplayer"><img src="http://www.adobe.com/images/shared/download_buttons/get_flash_player.gif" alt="Get Adobe Flash player" /></a></p>

	<!--[if !IE]>-->
	</object>
	<!--<![endif]-->
</object>
]]></content:encoded>
			<wfw:commentRss>http://www.calypso88.com/?feed=rss2&amp;p=512</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Feeds worth reading</title>
		<link>http://www.calypso88.com/?p=503</link>
		<comments>http://www.calypso88.com/?p=503#comments</comments>
		<pubDate>Fri, 09 Oct 2009 06:02:37 +0000</pubDate>
		<dc:creator>Rob</dc:creator>
				<category><![CDATA[Actionscript 3.0]]></category>

		<guid isPermaLink="false">http://www.calypso88.com/?p=503</guid>
		<description><![CDATA[Two friends asked for my list of RSS links within a week, so I figured I'd scrape together the sites that I like to keep an eye on for industry news, cool programming, and cutting edge Flash work. The site links are all on a list here, or you can download the set in OPML [...]]]></description>
			<content:encoded><![CDATA[<p>Two friends asked for my list of RSS links within a week, so I figured I'd scrape together the sites that I like to keep an eye on for industry news, cool programming, and cutting edge Flash work. The site links are all on a list <a href="http://www.calypso88.com/?page_id=504">here</a>, or you can download the set in OPML for direct injection into a feed reader.</p>
<p><a href="http://www.calypso88.com/?page_id=504">Links</a>  |  <a href="http://calypso88.com/wp-content/uploads/2009/10/dev.opml">OPML</a></p>
]]></content:encoded>
			<wfw:commentRss>http://www.calypso88.com/?feed=rss2&amp;p=503</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Flattening arrays</title>
		<link>http://www.calypso88.com/?p=481</link>
		<comments>http://www.calypso88.com/?p=481#comments</comments>
		<pubDate>Tue, 22 Sep 2009 02:32:36 +0000</pubDate>
		<dc:creator>Rob</dc:creator>
				<category><![CDATA[Actionscript 3.0]]></category>
		<category><![CDATA[Optimization]]></category>

		<guid isPermaLink="false">http://www.calypso88.com/?p=481</guid>
		<description><![CDATA[A big danger when working with large sets of data is the possibility of introducing a small slowdown that's compounded with every piece of data in the set. A common example is the multidimensional array; it's a powerful tool, but every time you look into the array you have to go at least two lookups [...]]]></description>
			<content:encoded><![CDATA[<p>A big danger when working with large sets of data is the possibility of introducing a small slowdown that's compounded with every piece of data in the set. A common example is the multidimensional array; it's a powerful tool, but every time you look into the array you have to go at least two lookups deep to find your data. Normally that's not a big deal but if you're touching the set thousands of times per frame, it adds up quickly.</p>
<p>A fairly drastic solution is to flatten your arrays - it will give you a nice performance boost when you access the data, but it comes at the cost of obfuscation. Here's how it works:</p>
<p><img class="alignnone size-full wp-image-482" title="flat_array" src="http://www.calypso88.com/wp-content/uploads/2009/09/flat_array.gif" alt="flat_array" width="450" height="200" /></p>
<blockquote style="color:#AAA; font-size:.9em; text-align:center"><p>(Sorry the numbers are goofy between the diagram and the code -  CS4 crashed and I didn't feel like re-making that graphic)</p></blockquote>
<p>In the traditional 2D view each "row" is a new Array object - this is where the added computing cost comes in. By flattening the data into one super-long array, you can access any piece of data with just one lookup. Finding the correct cell is a little more tricky though.</p>
<p><code>
<pre class="actionscript"><ol><li style="font-family: Monaco, Lucida Console, Lucida, 'Courier New', Courier, monospace; color: white; font-weight: normal; font-style: normal;"><div style="font-family: Monaco, Lucida Console, Lucida, 'Courier New', Courier, monospace; font-weight: normal; "><span style="color: #F7De2D;">var</span> myMDArray:<span style="color: #FFFFFF;">Array</span> = <span style="color: #F7De2D;"><span style="color: #FFFFFF;">&#91;</span></span></div></li><li style="font-family: Monaco, Lucida Console, Lucida, 'Courier New', Courier, monospace; color: white; font-weight: normal; font-style: normal;"><div style="font-family: Monaco, Lucida Console, Lucida, 'Courier New', Courier, monospace; font-weight: normal; ">	<span style="color: #F7De2D;"><span style="color: #FFFFFF;">&#91;</span></span><span style="color: #5FCE3C;">'0a'</span>, <span style="color: #5FCE3C;">'0b'</span>, <span style="color: #5FCE3C;">'0c'</span>, <span style="color: #5FCE3C;">'0d'</span>, <span style="color: #5FCE3C;">'0e'</span><span style="color: #FFFFFF;">&#93;</span>,</div></li><li style="font-family: Monaco, Lucida Console, Lucida, 'Courier New', Courier, monospace; color: white; font-weight: normal; font-style: normal;"><div style="font-family: Monaco, Lucida Console, Lucida, 'Courier New', Courier, monospace; font-weight: normal; ">	<span style="color: #FFFFFF;">&#91;</span><span style="color: #5FCE3C;">'1a'</span>, <span style="color: #5FCE3C;">'1b'</span>, <span style="color: #5FCE3C;">'1c'</span>, <span style="color: #5FCE3C;">'1d'</span>, <span style="color: #5FCE3C;">'1e'</span><span style="color: #FFFFFF;">&#93;</span>,</div></li><li style="font-family: Monaco, Lucida Console, Lucida, 'Courier New', Courier, monospace; color: white; font-weight: normal; font-style: normal;"><div style="font-family: Monaco, Lucida Console, Lucida, 'Courier New', Courier, monospace; font-weight: normal; ">	<span style="color: #FFFFFF;">&#91;</span><span style="color: #5FCE3C;">'2a'</span>, <span style="color: #5FCE3C;">'2b'</span>, <span style="color: #5FCE3C;">'2c'</span>, <span style="color: #5FCE3C;">'2d'</span>, <span style="color: #5FCE3C;">'2e'</span><span style="color: #F7De2D;"><span style="color: #FFFFFF;">&#93;</span></span><span style="color: #FFFFFF;">&#93;</span>;</div></li><li style="font-family: Monaco, Lucida Console, Lucida, 'Courier New', Courier, monospace; color: white; font-weight: normal; font-style: normal;"><div style="font-family: Monaco, Lucida Console, Lucida, 'Courier New', Courier, monospace; font-weight: normal; ">&nbsp;</div></li><li style="font-family: Monaco, Lucida Console, Lucida, 'Courier New', Courier, monospace; color: white; font-weight: normal; font-style: normal;"><div style="font-family: Monaco, Lucida Console, Lucida, 'Courier New', Courier, monospace; font-weight: normal; "><span style="color: #F7De2D;">var</span> myFlatArray:<span style="color: #FFFFFF;">Array</span> = <span style="color: #F7De2D;"><span style="color: #FFFFFF;">&#91;</span></span><span style="color: #5FCE3C;">'0a'</span>, <span style="color: #5FCE3C;">'0b'</span>, <span style="color: #5FCE3C;">'0c'</span>, <span style="color: #5FCE3C;">'0d'</span>, <span style="color: #5FCE3C;">'0e'</span>, <span style="color: #5FCE3C;">'1a'</span>, <span style="color: #5FCE3C;">'1b'</span>, <span style="color: #5FCE3C;">'1c'</span>, <span style="color: #5FCE3C;">'1d'</span>, <span style="color: #5FCE3C;">'1e'</span>, <span style="color: #5FCE3C;">'2a'</span>, <span style="color: #5FCE3C;">'2b'</span>, <span style="color: #5FCE3C;">'2c'</span>, <span style="color: #5FCE3C;">'2d'</span>, <span style="color: #5FCE3C;">'2e'</span><span style="color: #F7De2D;"><span style="color: #FFFFFF;">&#93;</span></span>;</div></li><li style="font-family: Monaco, Lucida Console, Lucida, 'Courier New', Courier, monospace; color: white; font-weight: normal; font-style: normal;"><div style="font-family: Monaco, Lucida Console, Lucida, 'Courier New', Courier, monospace; font-weight: normal; ">&nbsp;</div></li><li style="font-family: Monaco, Lucida Console, Lucida, 'Courier New', Courier, monospace; color: white; font-weight: normal; font-style: normal;"><div style="font-family: Monaco, Lucida Console, Lucida, 'Courier New', Courier, monospace; font-weight: normal; "><span style="color: #F7De2D;">var</span> columns:<span style="color: #FFFFFF;">int</span> = <span style="color: #FFFFFF;">5</span>;</div></li><li style="font-family: Monaco, Lucida Console, Lucida, 'Courier New', Courier, monospace; color: white; font-weight: normal; font-style: normal;"><div style="font-family: Monaco, Lucida Console, Lucida, 'Courier New', Courier, monospace; font-weight: normal; ">&nbsp;</div></li><li style="font-family: Monaco, Lucida Console, Lucida, 'Courier New', Courier, monospace; color: white; font-weight: normal; font-style: normal;"><div style="font-family: Monaco, Lucida Console, Lucida, 'Courier New', Courier, monospace; font-weight: normal; "><span style="color: #FFFFFF;">trace</span><span style="color: #FFFFFF;">&#40;</span>myMDArray<span style="color: #FFFFFF;">&#91;</span><span style="color: #FFFFFF;">2</span><span style="color: #FFFFFF;">&#93;</span><span style="color: #FFFFFF;">&#91;</span><span style="color: #FFFFFF;">4</span><span style="color: #FFFFFF;">&#93;</span><span style="color: #FFFFFF;">&#41;</span>;</div></li><li style="font-family: Monaco, Lucida Console, Lucida, 'Courier New', Courier, monospace; color: white; font-weight: normal; font-style: normal;"><div style="font-family: Monaco, Lucida Console, Lucida, 'Courier New', Courier, monospace; font-weight: normal; "><span style="color: #FFFFFF;">trace</span><span style="color: #FFFFFF;">&#40;</span>myFlatArray<span style="color: #FFFFFF;">&#91;</span><span style="color: #FFFFFF;">14</span><span style="color: #FFFFFF;">&#93;</span><span style="color: #FFFFFF;">&#41;</span>;</div></li><li style="font-family: Monaco, Lucida Console, Lucida, 'Courier New', Courier, monospace; color: white; font-weight: normal; font-style: normal;"><div style="font-family: Monaco, Lucida Console, Lucida, 'Courier New', Courier, monospace; font-weight: normal; "><span style="color: #FFFFFF;">trace</span><span style="color: #FFFFFF;">&#40;</span>myFlatArray<span style="color: #FFFFFF;">&#91;</span><span style="color: #FFFFFF;">&#40;</span><span style="color: #FFFFFF;">2</span> * columns<span style="color: #FFFFFF;">&#41;</span> + <span style="color: #FFFFFF;">4</span><span style="color: #FFFFFF;">&#93;</span><span style="color: #FFFFFF;">&#41;</span>;</div></li><li style="font-family: Monaco, Lucida Console, Lucida, 'Courier New', Courier, monospace; color: white; font-weight: normal; font-style: normal;"><div style="font-family: Monaco, Lucida Console, Lucida, 'Courier New', Courier, monospace; font-weight: normal; "><span style="color: #666666;">//  2e, 2e, 2e</span></div></li></ol></pre>
<p></code></p>
<p>Now - supposing you have an index for something and want to reverse engineer the row and column - just break out the <a href="http://www.calypso88.com/?p=453">modulo grid</a> code:</p>
<p><code>
<pre class="actionscript"><ol start="15"><li style="font-family: Monaco, Lucida Console, Lucida, 'Courier New', Courier, monospace; color: white; font-weight: normal; font-style: normal;"><div style="font-family: Monaco, Lucida Console, Lucida, 'Courier New', Courier, monospace; font-weight: normal; "><span style="color: #F7De2D;">var</span> row:<span style="color: #FFFFFF;">int</span> = <span style="color: #FFFFFF;">int</span><span style="color: #FFFFFF;">&#40;</span><span style="color: #FFFFFF;">14</span> / columns<span style="color: #FFFFFF;">&#41;</span>;</div></li><li style="font-family: Monaco, Lucida Console, Lucida, 'Courier New', Courier, monospace; color: white; font-weight: normal; font-style: normal;"><div style="font-family: Monaco, Lucida Console, Lucida, 'Courier New', Courier, monospace; font-weight: normal; "><span style="color: #F7De2D;">var</span> col:<span style="color: #FFFFFF;">int</span> = <span style="color: #FFFFFF;">14</span> % columns;</div></li><li style="font-family: Monaco, Lucida Console, Lucida, 'Courier New', Courier, monospace; color: white; font-weight: normal; font-style: normal;"><div style="font-family: Monaco, Lucida Console, Lucida, 'Courier New', Courier, monospace; font-weight: normal; ">&nbsp;</div></li><li style="font-family: Monaco, Lucida Console, Lucida, 'Courier New', Courier, monospace; color: white; font-weight: normal; font-style: normal;"><div style="font-family: Monaco, Lucida Console, Lucida, 'Courier New', Courier, monospace; font-weight: normal; "><span style="color: #FFFFFF;">trace</span><span style="color: #FFFFFF;">&#40;</span>row, col<span style="color: #FFFFFF;">&#41;</span>;</div></li><li style="font-family: Monaco, Lucida Console, Lucida, 'Courier New', Courier, monospace; color: white; font-weight: normal; font-style: normal;"><div style="font-family: Monaco, Lucida Console, Lucida, 'Courier New', Courier, monospace; font-weight: normal; "><span style="color: #666666;">//  2, 4</span></div></li></ol></pre>
<p></code></p>
]]></content:encoded>
			<wfw:commentRss>http://www.calypso88.com/?feed=rss2&amp;p=481</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>Hacked (yes really).</title>
		<link>http://www.calypso88.com/?p=465</link>
		<comments>http://www.calypso88.com/?p=465#comments</comments>
		<pubDate>Mon, 03 Aug 2009 06:59:47 +0000</pubDate>
		<dc:creator>Rob</dc:creator>
				<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://www.calypso88.com/?p=465</guid>
		<description><![CDATA[Hey readers - I want to apologize to anyone who tried to get to my last post and got a bunch of spam for cheap foreign pharmaceuticals instead. That certainly wasn't my intention (when I sell out, it won't be for gasex pills) and I'm taking steps to guard against this sort of thing in [...]]]></description>
			<content:encoded><![CDATA[<p><img class="alignright" align="right" title="hacked" src="http://calypso88.com/wp-content/uploads/2009/07/hack.png" alt="" width="132" height="155" style="align:right; padding-left: 5px" />
<p><em>Hey readers - I want to apologize to anyone who tried to get to my last post and got a bunch of spam for cheap foreign pharmaceuticals instead. That certainly wasn't my intention (when I sell out, it won't be for gasex pills) and I'm taking steps to guard against this sort of thing in the future. If you want specifics on the hack, the best thread I've seen so far is <a href="http://groups.google.com/group/google-reader-troubleshoot/browse_thread/thread/39a7eef288c65dd0/3d177143fb8f5be1?lnk=gst&amp;q=spam#3d177143fb8f5be1" target="_blank">here</a>.</em></p>
<p>Sincerely,<br />
-Rob</p>
]]></content:encoded>
			<wfw:commentRss>http://www.calypso88.com/?feed=rss2&amp;p=465</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Modulo Grids</title>
		<link>http://www.calypso88.com/?p=453</link>
		<comments>http://www.calypso88.com/?p=453#comments</comments>
		<pubDate>Sat, 01 Aug 2009 14:19:13 +0000</pubDate>
		<dc:creator>Rob</dc:creator>
				<category><![CDATA[Actionscript 3.0]]></category>
		<category><![CDATA[Optimization]]></category>

		<guid isPermaLink="false">http://www.calypso88.com/?p=453</guid>
		<description><![CDATA[Here's a quick optimization for people making grids of things. The traditional method is a pair of loops, nested to make rows and columns: const ROWS:int = 30;const COLUMNS:int = 88;&#160;for&#40;var row:int = 0; row &#60; ROWS; row++&#41;&#123; for&#40;var column:int = 0; column &#60; COLUMNS; column++&#41;&#123; var s:Shape = new Shape&#40;&#41;; s.x = column * [...]]]></description>
			<content:encoded><![CDATA[<p>Here's a quick optimization for people making grids of things. The traditional method is a pair of loops, nested to make rows and columns:</p>
<p><code>
<pre class="actionscript"><ol><li style="font-family: Monaco, Lucida Console, Lucida, 'Courier New', Courier, monospace; color: white; font-weight: normal; font-style: normal;"><div style="font-family: Monaco, Lucida Console, Lucida, 'Courier New', Courier, monospace; font-weight: normal; "><span style="color: #F7De2D;">const</span> ROWS:<span style="color: #FFFFFF;">int</span> = <span style="color: #FFFFFF;">30</span>;</div></li><li style="font-family: Monaco, Lucida Console, Lucida, 'Courier New', Courier, monospace; color: white; font-weight: normal; font-style: normal;"><div style="font-family: Monaco, Lucida Console, Lucida, 'Courier New', Courier, monospace; font-weight: normal; "><span style="color: #F7De2D;">const</span> COLUMNS:<span style="color: #FFFFFF;">int</span> = <span style="color: #FFFFFF;">88</span>;</div></li><li style="font-family: Monaco, Lucida Console, Lucida, 'Courier New', Courier, monospace; color: white; font-weight: normal; font-style: normal;"><div style="font-family: Monaco, Lucida Console, Lucida, 'Courier New', Courier, monospace; font-weight: normal; ">&nbsp;</div></li><li style="font-family: Monaco, Lucida Console, Lucida, 'Courier New', Courier, monospace; color: white; font-weight: normal; font-style: normal;"><div style="font-family: Monaco, Lucida Console, Lucida, 'Courier New', Courier, monospace; font-weight: normal; "><span style="color: #F7De2D;">for</span><span style="color: #FFFFFF;">&#40;</span><span style="color: #F7De2D;">var</span> row:<span style="color: #FFFFFF;">int</span> = <span style="color: #FFFFFF;">0</span>; row &lt; ROWS; row++<span style="color: #FFFFFF;">&#41;</span><span style="color: #FFFFFF;">&#123;</span></div></li><li style="font-family: Monaco, Lucida Console, Lucida, 'Courier New', Courier, monospace; color: white; font-weight: normal; font-style: normal;"><div style="font-family: Monaco, Lucida Console, Lucida, 'Courier New', Courier, monospace; font-weight: normal; ">	<span style="color: #F7De2D;">for</span><span style="color: #FFFFFF;">&#40;</span><span style="color: #F7De2D;">var</span> column:<span style="color: #FFFFFF;">int</span> = <span style="color: #FFFFFF;">0</span>; column &lt; COLUMNS; column++<span style="color: #FFFFFF;">&#41;</span><span style="color: #FFFFFF;">&#123;</span></div></li><li style="font-family: Monaco, Lucida Console, Lucida, 'Courier New', Courier, monospace; color: white; font-weight: normal; font-style: normal;"><div style="font-family: Monaco, Lucida Console, Lucida, 'Courier New', Courier, monospace; font-weight: normal; ">		<span style="color: #F7De2D;">var</span> s:Shape = <span style="color: #FFFFFF;">new</span> Shape<span style="color: #FFFFFF;">&#40;</span><span style="color: #FFFFFF;">&#41;</span>;</div></li><li style="font-family: Monaco, Lucida Console, Lucida, 'Courier New', Courier, monospace; color: white; font-weight: normal; font-style: normal;"><div style="font-family: Monaco, Lucida Console, Lucida, 'Courier New', Courier, monospace; font-weight: normal; ">		s.<span style="color: #71A1CE;">x</span> = column * <span style="color: #FFFFFF;">5</span>;</div></li><li style="font-family: Monaco, Lucida Console, Lucida, 'Courier New', Courier, monospace; color: white; font-weight: normal; font-style: normal;"><div style="font-family: Monaco, Lucida Console, Lucida, 'Courier New', Courier, monospace; font-weight: normal; ">		s.<span style="color: #71A1CE;">y</span> = row * <span style="color: #FFFFFF;">5</span>;</div></li><li style="font-family: Monaco, Lucida Console, Lucida, 'Courier New', Courier, monospace; color: white; font-weight: normal; font-style: normal;"><div style="font-family: Monaco, Lucida Console, Lucida, 'Courier New', Courier, monospace; font-weight: normal; ">&nbsp;</div></li><li style="font-family: Monaco, Lucida Console, Lucida, 'Courier New', Courier, monospace; color: white; font-weight: normal; font-style: normal;"><div style="font-family: Monaco, Lucida Console, Lucida, 'Courier New', Courier, monospace; font-weight: normal; ">		s.<span style="color: #71A1CE;">graphics</span>.<span style="color: #FFFFFF;">beginFill</span><span style="color: #FFFFFF;">&#40;</span>0x666666<span style="color: #FFFFFF;">&#41;</span>;</div></li><li style="font-family: Monaco, Lucida Console, Lucida, 'Courier New', Courier, monospace; color: white; font-weight: normal; font-style: normal;"><div style="font-family: Monaco, Lucida Console, Lucida, 'Courier New', Courier, monospace; font-weight: normal; ">		s.<span style="color: #71A1CE;">graphics</span>.<span style="color: #71A1CE;">drawRect</span><span style="color: #FFFFFF;">&#40;</span><span style="color: #FFFFFF;">0</span>, <span style="color: #FFFFFF;">0</span>, <span style="color: #FFFFFF;">4</span>, <span style="color: #FFFFFF;">4</span><span style="color: #FFFFFF;">&#41;</span>;</div></li><li style="font-family: Monaco, Lucida Console, Lucida, 'Courier New', Courier, monospace; color: white; font-weight: normal; font-style: normal;"><div style="font-family: Monaco, Lucida Console, Lucida, 'Courier New', Courier, monospace; font-weight: normal; ">		addChild<span style="color: #FFFFFF;">&#40;</span>s<span style="color: #FFFFFF;">&#41;</span>;</div></li><li style="font-family: Monaco, Lucida Console, Lucida, 'Courier New', Courier, monospace; color: white; font-weight: normal; font-style: normal;"><div style="font-family: Monaco, Lucida Console, Lucida, 'Courier New', Courier, monospace; font-weight: normal; ">	<span style="color: #FFFFFF;">&#125;</span></div></li><li style="font-family: Monaco, Lucida Console, Lucida, 'Courier New', Courier, monospace; color: white; font-weight: normal; font-style: normal;"><div style="font-family: Monaco, Lucida Console, Lucida, 'Courier New', Courier, monospace; font-weight: normal; "><span style="color: #FFFFFF;">&#125;</span></div></li></ol></pre>
<p></code></p>
<p>This can be simplified and sped up by taking advantage of the relationship between division and modulus to generate the row and column dynamically:</p>
<p><code>
<pre class="actionscript"><ol><li style="font-family: Monaco, Lucida Console, Lucida, 'Courier New', Courier, monospace; color: white; font-weight: normal; font-style: normal;"><div style="font-family: Monaco, Lucida Console, Lucida, 'Courier New', Courier, monospace; font-weight: normal; "><span style="color: #F7De2D;">const</span> ROWS:<span style="color: #FFFFFF;">int</span> = <span style="color: #FFFFFF;">30</span>;</div></li><li style="font-family: Monaco, Lucida Console, Lucida, 'Courier New', Courier, monospace; color: white; font-weight: normal; font-style: normal;"><div style="font-family: Monaco, Lucida Console, Lucida, 'Courier New', Courier, monospace; font-weight: normal; "><span style="color: #F7De2D;">const</span> COLUMNS:<span style="color: #FFFFFF;">int</span> = <span style="color: #FFFFFF;">88</span>;</div></li><li style="font-family: Monaco, Lucida Console, Lucida, 'Courier New', Courier, monospace; color: white; font-weight: normal; font-style: normal;"><div style="font-family: Monaco, Lucida Console, Lucida, 'Courier New', Courier, monospace; font-weight: normal; "><span style="color: #F7De2D;">const</span> ITEMS:<span style="color: #FFFFFF;">int</span> = ROWS * COLUMNS;</div></li><li style="font-family: Monaco, Lucida Console, Lucida, 'Courier New', Courier, monospace; color: white; font-weight: normal; font-style: normal;"><div style="font-family: Monaco, Lucida Console, Lucida, 'Courier New', Courier, monospace; font-weight: normal; ">&nbsp;</div></li><li style="font-family: Monaco, Lucida Console, Lucida, 'Courier New', Courier, monospace; color: white; font-weight: normal; font-style: normal;"><div style="font-family: Monaco, Lucida Console, Lucida, 'Courier New', Courier, monospace; font-weight: normal; "><span style="color: #F7De2D;">for</span><span style="color: #FFFFFF;">&#40;</span><span style="color: #F7De2D;">var</span> i:<span style="color: #FFFFFF;">int</span> = <span style="color: #FFFFFF;">0</span>; i &lt; ITEMS; i++<span style="color: #FFFFFF;">&#41;</span><span style="color: #FFFFFF;">&#123;</span></div></li><li style="font-family: Monaco, Lucida Console, Lucida, 'Courier New', Courier, monospace; color: white; font-weight: normal; font-style: normal;"><div style="font-family: Monaco, Lucida Console, Lucida, 'Courier New', Courier, monospace; font-weight: normal; ">	<span style="color: #F7De2D;">var</span> s:Shape = <span style="color: #FFFFFF;">new</span> Shape<span style="color: #FFFFFF;">&#40;</span><span style="color: #FFFFFF;">&#41;</span>;</div></li><li style="font-family: Monaco, Lucida Console, Lucida, 'Courier New', Courier, monospace; color: white; font-weight: normal; font-style: normal;"><div style="font-family: Monaco, Lucida Console, Lucida, 'Courier New', Courier, monospace; font-weight: normal; ">	s.<span style="color: #71A1CE;">x</span> = <span style="color: #FFFFFF;">int</span><span style="color: #FFFFFF;">&#40;</span>i / ROWS<span style="color: #FFFFFF;">&#41;</span> * <span style="color: #FFFFFF;">5</span>;		<span style="color: #666666;">//  this is the same as Math.floor(i / ROWS), just faster</span></div></li><li style="font-family: Monaco, Lucida Console, Lucida, 'Courier New', Courier, monospace; color: white; font-weight: normal; font-style: normal;"><div style="font-family: Monaco, Lucida Console, Lucida, 'Courier New', Courier, monospace; font-weight: normal; ">	s.<span style="color: #71A1CE;">y</span> = <span style="color: #FFFFFF;">&#40;</span>i % ROWS<span style="color: #FFFFFF;">&#41;</span> * <span style="color: #FFFFFF;">5</span>;</div></li><li style="font-family: Monaco, Lucida Console, Lucida, 'Courier New', Courier, monospace; color: white; font-weight: normal; font-style: normal;"><div style="font-family: Monaco, Lucida Console, Lucida, 'Courier New', Courier, monospace; font-weight: normal; ">&nbsp;</div></li><li style="font-family: Monaco, Lucida Console, Lucida, 'Courier New', Courier, monospace; color: white; font-weight: normal; font-style: normal;"><div style="font-family: Monaco, Lucida Console, Lucida, 'Courier New', Courier, monospace; font-weight: normal; ">	s.<span style="color: #71A1CE;">graphics</span>.<span style="color: #FFFFFF;">beginFill</span><span style="color: #FFFFFF;">&#40;</span>0x666666<span style="color: #FFFFFF;">&#41;</span>;</div></li><li style="font-family: Monaco, Lucida Console, Lucida, 'Courier New', Courier, monospace; color: white; font-weight: normal; font-style: normal;"><div style="font-family: Monaco, Lucida Console, Lucida, 'Courier New', Courier, monospace; font-weight: normal; ">	s.<span style="color: #71A1CE;">graphics</span>.<span style="color: #71A1CE;">drawRect</span><span style="color: #FFFFFF;">&#40;</span><span style="color: #FFFFFF;">0</span>, <span style="color: #FFFFFF;">0</span>, <span style="color: #FFFFFF;">4</span>, <span style="color: #FFFFFF;">4</span><span style="color: #FFFFFF;">&#41;</span>;</div></li><li style="font-family: Monaco, Lucida Console, Lucida, 'Courier New', Courier, monospace; color: white; font-weight: normal; font-style: normal;"><div style="font-family: Monaco, Lucida Console, Lucida, 'Courier New', Courier, monospace; font-weight: normal; ">	addChild<span style="color: #FFFFFF;">&#40;</span>s<span style="color: #FFFFFF;">&#41;</span>;</div></li><li style="font-family: Monaco, Lucida Console, Lucida, 'Courier New', Courier, monospace; color: white; font-weight: normal; font-style: normal;"><div style="font-family: Monaco, Lucida Console, Lucida, 'Courier New', Courier, monospace; font-weight: normal; "><span style="color: #FFFFFF;">&#125;</span></div></li></ol></pre>
<p></code></p>
<p>By upgrading to loop-invariants, we can cut the nested for-loop for a nice boost. And, as a bonus, this new code can work with sets that don't end squarely at the end of a column.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.calypso88.com/?feed=rss2&amp;p=453</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
		<item>
		<title>FIVe3D Extreme Optimization</title>
		<link>http://www.calypso88.com/?p=442</link>
		<comments>http://www.calypso88.com/?p=442#comments</comments>
		<pubDate>Sat, 11 Jul 2009 20:28:40 +0000</pubDate>
		<dc:creator>Rob</dc:creator>
				<category><![CDATA[Actionscript 3.0]]></category>
		<category><![CDATA[FIVe3D]]></category>
		<category><![CDATA[Optimization]]></category>

		<guid isPermaLink="false">http://www.calypso88.com/?p=442</guid>
		<description><![CDATA[It's not often that my experimental projects line up with my day job, but a couple months ago I talked the higher-ups into letting me do some crossover work with 3D terrain rendering. The obvious issue with Flash and 3D is performance. The maps we wanted to show we're rectilinear height-maps, 256 vertices to a [...]]]></description>
			<content:encoded><![CDATA[<p>It's not often that my experimental projects line up with my <a href="http://i42.tinypic.com/2uep4iw.jpg" target="_blank">day job</a>, but a couple months ago I talked the higher-ups into letting me do some crossover work with 3D terrain rendering. </p>
<p>The obvious issue with Flash and 3D is performance. The maps we wanted to show we're rectilinear height-maps, 256 vertices to a side. I already knew there was no way to do this in a photo-realistic way (256&sup2; is just over 65,000 squares, which would be 130,050 triangles to render...last I checked, Papervision gets unusable around 2000) so I decided to go with a wireframe style instead.</p>
<p>Since I didn't need camera's or any of the weight of the bigger engines, I opted to use Mathieu Badimon's very lightweight and (imo) thoughtfully laid out <a href="http://five3d.mathieu-badimon.com" target="_blank">FIVe3D</a> library as my starting point. From there I got a quick proof of concept up and realized there was still no way I could get away with the full 256&sup2; grid so I started cutting down the resolution. Using every third node (64&sup2;) struck a good compromise with the fidelity of the original mesh, and the performance limitations I needed to stay in to work for the majority of our users.</p>
<p>Off the shelf, FIVe3D was giving me roughly 12fps and consuming a pretty weighty chunk of system memory, so I started digging in and looking for optimizations I could make. To start with, I created a specific class for my model to eliminate all the cross-class calls between Shape3D and Graphics3D. I also decided the Point3D class had to go since every render pass would create tens of thousands of throwaway objects in order to calculate the z-translations for my nodes. After internalizing those, I brought in the Matrix3D class as well and started combining some of the heavy-use functions so the AVM could stay within one scope for the majority of the calculation and drawing.</p>
<p>That gave me a boost of about 50% but I still needed a little more oomph. Finally, I took the dive and flattened my arrays and ended up restructuring the core FIVe3D engine so it was operating a little more specifically to my needs (mostly hard typing some things and taking out optional calls to the flat-fill shader and the like). At this point, the code is fairly incomprehensible and some of the extensibility of the engine was lost, but it did put my frame rate just under 30fps so I can't complain. </p>
<p>Here is a standalone copy showing the final mesh, and if you want to melt your processor, <a href="http://calypso88.com/wp-content/uploads/2009/07/">click for a version with the original full-detail grid</a>.</p>

<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000"
			id="fm_terrain_sm_1875570124"
			class="flashmovie"
			width="450"
			height="300">
	<param name="movie" value="wp-content/uploads/2009/07/terrain_sm.swf" />
	<param name="allowscriptaccess" value="always" />
	<!--[if !IE]>-->
	<object	type="application/x-shockwave-flash"
			data="wp-content/uploads/2009/07/terrain_sm.swf"
			name="fm_terrain_sm_1875570124"
			width="450"
			height="300">
		<param name="allowscriptaccess" value="always" />
	<!--<![endif]-->
		
<p><a href="http://adobe.com/go/getflashplayer"><img src="http://www.adobe.com/images/shared/download_buttons/get_flash_player.gif" alt="Get Adobe Flash player" /></a></p>

	<!--[if !IE]>-->
	</object>
	<!--<![endif]-->
</object>
]]></content:encoded>
			<wfw:commentRss>http://www.calypso88.com/?feed=rss2&amp;p=442</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Flex Test 0.02 &#8211; Cel Shading</title>
		<link>http://www.calypso88.com/?p=427</link>
		<comments>http://www.calypso88.com/?p=427#comments</comments>
		<pubDate>Fri, 19 Jun 2009 06:18:34 +0000</pubDate>
		<dc:creator>Rob</dc:creator>
				<category><![CDATA[Actionscript 3.0]]></category>
		<category><![CDATA[Flex Framework]]></category>

		<guid isPermaLink="false">http://www.calypso88.com/?p=427</guid>
		<description><![CDATA[I'm iterating on my first test and some of the results are turning out pretty cool. The mxml is coming easier now, but I'm still pretty confounded by what's going on in the API. For starters, trying to figure out a slider solution took me on a tour of s:Slider, s:HSlider, and finally (past mx:Slider) [...]]]></description>
			<content:encoded><![CDATA[<p>I'm iterating on my first test and some of the results are turning out pretty cool. The mxml is coming easier now, but I'm still pretty confounded by what's going on in the API.</p>
<p>For starters, trying to figure out a slider solution took me on a tour of s:Slider, s:HSlider, and finally (past mx:Slider) to mx:HSlider. I haven't kept up on the Flex news that well in the past months so I get the feeling there's some big paradigm shift that's catching me by surprise (something about shifting from the mx package to the new s package for the Spark theme?). I'm guessing that half of these classes will get culled out by launch time, so I guess that's what I get for learning on the beta.</p>
<p>One thing I'm excited about is how quickly you can prototype ideas in here. Getting a webcam up took all of 5 minutes, and throwing out three color pickers was instant. I did spend some time fussing with the width bindings between the slider and the palettes but in a real project I'd probably take the time to design and write a true component for that functionality so I can't complain too much.</p>
<p><span style="background:#EEE; display:block; color:#222; padding: 10px 10px 10px 10px; margin:10px 0px 0px 0px; border: 1px solid #CCD"><strong>UPDATE</strong>: This thing seems to be crashing some peoples browsers. I haven't looked into it too far but I think there are some circular references in the bindings that are getting into a loop or something (I knew that idea was too good to be true!). For now I've moved the offending swf to it's own page: <a href="http://www.calypso88.com/?page_id=435" />enter if you dare</a>.</span></p>
]]></content:encoded>
			<wfw:commentRss>http://www.calypso88.com/?feed=rss2&amp;p=427</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Gettin&#8217; my Gumbo on</title>
		<link>http://www.calypso88.com/?p=415</link>
		<comments>http://www.calypso88.com/?p=415#comments</comments>
		<pubDate>Wed, 17 Jun 2009 06:22:35 +0000</pubDate>
		<dc:creator>Rob</dc:creator>
				<category><![CDATA[Actionscript 3.0]]></category>
		<category><![CDATA[Flex Framework]]></category>

		<guid isPermaLink="false">http://www.calypso88.com/?p=415</guid>
		<description><![CDATA[With the big Flash Builder/Catalyst thing going on right now, it seemed like a good time to get myself up to speed on the Flex framework. At the moment, I'm at that stage where everything takes about six times longer to get working than if I just knocked it together in Flash. I keep getting [...]]]></description>
			<content:encoded><![CDATA[<p>With the big Flash Builder/Catalyst <em>thing</em> going on right now, it seemed like a good time to get myself up to speed on the Flex framework. At the moment, I'm at that stage where everything takes about six times longer to get working than if I just knocked it together in Flash. I keep getting this suspicion that Flex is just VBasic written in ActionScript with some xml in there to gum up the works, but I'm determined to stick it out. (By the way, if anyone has the link to download a copy of the langref, please let me know - waiting for the livedocs is killing me!) </p>
<p>So, for <em>Flex Experiment 0.01</em>, I recreated an old demo I wrote for a paint bucket/magic wand tool. The actual Flex components went together pretty easily - the big issue for me was deciphering which of the 1000+ components in the framework I needed to use. Once that was figured out, the real chore became negotiating the inputs and outputs of the components (s:BitmapImage takes an Object for source and doesn't output a BitmapData anywhere? Really?) - somehow it all seems to work, but the components really are black boxes that developers are not meant to get into. </p>
<p>Anywho - click and drag around to see it in action, and (I'll grudgingly give Flex a gold star here) right click for the source.</p>

<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000"
			id="fm_main_1824742663"
			class="flashmovie"
			width="450"
			height="400">
	<param name="movie" value="wp-content/uploads/2009/06/main.swf" />
	<param name="allowscriptaccess" value="always" />
	<!--[if !IE]>-->
	<object	type="application/x-shockwave-flash"
			data="wp-content/uploads/2009/06/main.swf"
			name="fm_main_1824742663"
			width="450"
			height="400">
		<param name="allowscriptaccess" value="always" />
	<!--<![endif]-->
		
<p><a href="http://adobe.com/go/getflashplayer"><img src="http://www.adobe.com/images/shared/download_buttons/get_flash_player.gif" alt="Get Adobe Flash player" /></a></p>

	<!--[if !IE]>-->
	</object>
	<!--<![endif]-->
</object>
]]></content:encoded>
			<wfw:commentRss>http://www.calypso88.com/?feed=rss2&amp;p=415</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>A little walk down memory lane</title>
		<link>http://www.calypso88.com/?p=406</link>
		<comments>http://www.calypso88.com/?p=406#comments</comments>
		<pubDate>Fri, 12 Jun 2009 05:37:54 +0000</pubDate>
		<dc:creator>Rob</dc:creator>
				<category><![CDATA[Actionscript 3.0]]></category>

		<guid isPermaLink="false">http://www.calypso88.com/?p=406</guid>
		<description><![CDATA[I was cleaning out an old work directory when I came across some experiments I built back in my AS2 days. Most of them are pretty hacky (proofs of various concepts and interactive mouse toys) but I came across an old b&#233;zier path following test. It's not very complex (or even very tricky) but it's [...]]]></description>
			<content:encoded><![CDATA[<p>I was cleaning out an old work directory when I came across some experiments I built back in my AS2 days. Most of them are pretty hacky (proofs of various concepts and interactive mouse toys) but I came across an old b&eacute;zier path following test. It's not very complex (or even very tricky) but it's got a zen quality and I like it. I didn't crack open the source (AS2!!!) but if anyone is dying for it, I could probably dig it up on request. Also if you're curious, the math for this lives over on my <a href="http://www.calypso88.com/?page_id=4">EWIKAL</a>.</p>

<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000"
			id="fm_bezier5_754349910"
			class="flashmovie"
			width="450"
			height="350">
	<param name="movie" value="http://www.calypso88.com/wp-content/uploads/2009/06/bezier5.swf" />
	<!--[if !IE]>-->
	<object	type="application/x-shockwave-flash"
			data="http://www.calypso88.com/wp-content/uploads/2009/06/bezier5.swf"
			name="fm_bezier5_754349910"
			width="450"
			height="350">
	<!--<![endif]-->
		
<p><a href="http://adobe.com/go/getflashplayer"><img src="http://www.adobe.com/images/shared/download_buttons/get_flash_player.gif" alt="Get Adobe Flash player" /></a></p>

	<!--[if !IE]>-->
	</object>
	<!--<![endif]-->
</object>
<p>Drag the three points around to alter the path.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.calypso88.com/?feed=rss2&amp;p=406</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>AS2 to AS3: Null or Undefined in the Constructor</title>
		<link>http://www.calypso88.com/?p=303</link>
		<comments>http://www.calypso88.com/?p=303#comments</comments>
		<pubDate>Sat, 18 Apr 2009 14:58:56 +0000</pubDate>
		<dc:creator>Rob</dc:creator>
				<category><![CDATA[AS2 to AS3]]></category>
		<category><![CDATA[Actionscript 3.0]]></category>

		<guid isPermaLink="false">http://www.calypso88.com/?p=303</guid>
		<description><![CDATA[Quick post today. If you're making the jump from timeline coding to class based development (and I definitely encourage you to!) you'll undoubtedly run into this problem. It goes something like this: Designate a Document Class for your fla - let's call it ProjectMain Create the ProjectMain class and save it alongside your fla as [...]]]></description>
			<content:encoded><![CDATA[<p>Quick post today. If you're making the jump from timeline coding to class based development (and I definitely encourage you to!) you'll undoubtedly run into this problem. It goes something like this:</p>
<ol>
<li>Designate a Document Class for your fla - let's call it ProjectMain</li>
<li>Create the ProjectMain class and save it alongside your fla as ProjectMain.as</li>
<li>Set a property of something on stage, let's say myCoolLogo.x&nbsp;=&nbsp;stage.stageWidth&nbsp;/&nbsp;2;</li>
<li>Compile to receive your TypeError: Error #1009</li>
</ol>
<ul></ul>
<p>Your code is otherwise fine - commenting out that line seems to fix everything. Furthermore the object is right there on stage in your fla – your constructor just refuses to acknowledge it!</p>
<p>The problem goes back to AS2 prehistory and the top-down/bottom-up problem. If you don't remember that (admittedly it's a little obscure even if you did work in AS2 a lot), here's the gist: Flash is single-threaded, meaning it can only do one discrete task at a time, which includes running your constructor, and parsing everything on stage. In AS2 you could specify whether you wanted to run your code "top down" - meaning, 'run all the code in the top layer, then the next below and so on' or vice versa for "bottom up."</p>
<p>At this point you should be wondering what this has to do with anything - well let's say you create a variable on layer 10 (top layer) and give it a value - and in layer 1 (bottom layer) you wan't to do something with that value - it's only going to work if you're running top-down. If you run that fla bottom-up you'll execute the layer 1 code first and the variable will be undefined until frame 2. The exact same thing is happening with your constructor in AS3.</p>
<p>The constructor will always precede any timeline code or bytecode (including positioning things on stage, tweens, &amp;c.) - so you need to be careful with your initialization. It's alright to create new objects and work with them, but you can't query anything that you put down on stage (the same goes for library-linked Classes) until at least one render cycle has passed and allowed all those objects to be generated. Luckily, AS3 has an event for that so it takes some of the pain out.</p>
<p>Here's how:</p>
<p><code>
<pre class="actionscript"><ol start="30"><li style="font-family: Monaco, Lucida Console, Lucida, 'Courier New', Courier, monospace; color: white; font-weight: normal; font-style: normal;"><div style="font-family: Monaco, Lucida Console, Lucida, 'Courier New', Courier, monospace; font-weight: normal; "><span style="color: #666666;">//  ...</span></div></li><li style="font-family: Monaco, Lucida Console, Lucida, 'Courier New', Courier, monospace; color: white; font-weight: normal; font-style: normal;"><div style="font-family: Monaco, Lucida Console, Lucida, 'Courier New', Courier, monospace; font-weight: normal; ">&nbsp;</div></li><li style="font-family: Monaco, Lucida Console, Lucida, 'Courier New', Courier, monospace; color: white; font-weight: normal; font-style: normal;"><div style="font-family: Monaco, Lucida Console, Lucida, 'Courier New', Courier, monospace; font-weight: normal; "><span style="color: #666666;">//--------------------------------------</span></div></li><li style="font-family: Monaco, Lucida Console, Lucida, 'Courier New', Courier, monospace; color: white; font-weight: normal; font-style: normal;"><div style="font-family: Monaco, Lucida Console, Lucida, 'Courier New', Courier, monospace; font-weight: normal; "><span style="color: #666666;">//  CONSTRUCTOR</span></div></li><li style="font-family: Monaco, Lucida Console, Lucida, 'Courier New', Courier, monospace; color: white; font-weight: normal; font-style: normal;"><div style="font-family: Monaco, Lucida Console, Lucida, 'Courier New', Courier, monospace; font-weight: normal; "><span style="color: #666666;">//--------------------------------------</span></div></li><li style="font-family: Monaco, Lucida Console, Lucida, 'Courier New', Courier, monospace; color: white; font-weight: normal; font-style: normal;"><div style="font-family: Monaco, Lucida Console, Lucida, 'Courier New', Courier, monospace; font-weight: normal; ">&nbsp;</div></li><li style="font-family: Monaco, Lucida Console, Lucida, 'Courier New', Courier, monospace; color: white; font-weight: normal; font-style: normal;"><div style="font-family: Monaco, Lucida Console, Lucida, 'Courier New', Courier, monospace; font-weight: normal; "><span style="color: #F7De2D;">public</span> <span style="color: #FF5E00;"><span style="color: #FFFF00;">function</span> ProjectMain</span><span style="color: #FFFFFF;">&#40;</span><span style="color: #FFFFFF;">&#41;</span><span style="color: #FFFFFF;">&#123;</span></div></li><li style="font-family: Monaco, Lucida Console, Lucida, 'Courier New', Courier, monospace; color: white; font-weight: normal; font-style: normal;"><div style="font-family: Monaco, Lucida Console, Lucida, 'Courier New', Courier, monospace; font-weight: normal; ">	<span style="color: #FFFFFF;">super</span><span style="color: #FFFFFF;">&#40;</span><span style="color: #FFFFFF;">&#41;</span>;</div></li><li style="font-family: Monaco, Lucida Console, Lucida, 'Courier New', Courier, monospace; color: white; font-weight: normal; font-style: normal;"><div style="font-family: Monaco, Lucida Console, Lucida, 'Courier New', Courier, monospace; font-weight: normal; ">	addEventListener<span style="color: #FFFFFF;">&#40;</span>Event.<span style="color: #71A1CE;">ADDED_TO_STAGE</span>, <span style="color: #FFFF00;">function</span><span style="color: #FFFFFF;">&#40;</span><span style="color: #FFFFFF;">e</span>:Event<span style="color: #FFFFFF;">&#41;</span>:<span style="color: #FFFFFF;">void</span><span style="color: #FFFFFF;">&#123;</span></div></li><li style="font-family: Monaco, Lucida Console, Lucida, 'Courier New', Courier, monospace; color: white; font-weight: normal; font-style: normal;"><div style="font-family: Monaco, Lucida Console, Lucida, 'Courier New', Courier, monospace; font-weight: normal; ">		<span style="color: #FFFFFF;">e</span>.<span style="color: #FFFFFF;">target</span>.<span style="color: #71A1CE;">removeEventListener</span><span style="color: #FFFFFF;">&#40;</span><span style="color: #FFFFFF;">e</span>.<span style="color: #FFFFFF;">type</span>, <span style="color: #FFFFFF;">arguments</span>.<span style="color: #FFFFFF;">callee</span><span style="color: #FFFFFF;">&#41;</span>;</div></li><li style="font-family: Monaco, Lucida Console, Lucida, 'Courier New', Courier, monospace; color: white; font-weight: normal; font-style: normal;"><div style="font-family: Monaco, Lucida Console, Lucida, 'Courier New', Courier, monospace; font-weight: normal; ">		myCoolLogo.<span style="color: #71A1CE;">x</span> = <span style="color: #FFFFFF;">stage</span>.<span style="color: #71A1CE;">stageWidth</span> &gt;&gt; <span style="color: #FFFFFF;">1</span>;</div></li><li style="font-family: Monaco, Lucida Console, Lucida, 'Courier New', Courier, monospace; color: white; font-weight: normal; font-style: normal;"><div style="font-family: Monaco, Lucida Console, Lucida, 'Courier New', Courier, monospace; font-weight: normal; ">	<span style="color: #FFFFFF;">&#125;</span><span style="color: #FFFFFF;">&#41;</span>;</div></li><li style="font-family: Monaco, Lucida Console, Lucida, 'Courier New', Courier, monospace; color: white; font-weight: normal; font-style: normal;"><div style="font-family: Monaco, Lucida Console, Lucida, 'Courier New', Courier, monospace; font-weight: normal; "><span style="color: #FFFFFF;">&#125;</span></div></li></ol></pre>
<p></code></p>
<p>If you're curious about line 39 in there, it's a generic way to remove event listeners - there's a little more detail over on the <a href="http://www.calypso88.com/?page_id=21">code page</a>. Also as an added bonus, all the code has been moved into a second function - and since the ActionScript JIT compiler doesn't optimize constructors, there's a good chance that this code will run faster than before.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.calypso88.com/?feed=rss2&amp;p=303</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Build a better volume controller</title>
		<link>http://www.calypso88.com/?p=364</link>
		<comments>http://www.calypso88.com/?p=364#comments</comments>
		<pubDate>Tue, 14 Apr 2009 01:36:50 +0000</pubDate>
		<dc:creator>Rob</dc:creator>
				<category><![CDATA[Actionscript 3.0]]></category>

		<guid isPermaLink="false">http://www.calypso88.com/?p=364</guid>
		<description><![CDATA[I've been messing around with audio lately and it reminded me of a pet peeve so inane that I couldn't help but post about it. Volume controls! In AS3, the volume attribute ranges from from 0 to 1. Graphically it's a pretty obvious choice to just link your fader up on a one-to-one relation - [...]]]></description>
			<content:encoded><![CDATA[<p>I've been messing around with audio lately and it reminded me of a pet peeve so inane that I couldn't help but post about it. Volume controls!</p>
<p>In AS3, the volume attribute ranges from from 0 to 1. Graphically it's a pretty obvious choice to just link your fader up on a one-to-one relation - the math is straightforward and you can quickly verify that, as you scale up the volume, it gets louder, and when you scale down you approach silence. Easy.</p>
<p>The problem comes in when you listen to that audio with your fleshy human-ears, which detect sound logarithmically instead of linearly. That means that the perceptual difference in lower volume is much more noticeable than in higher volumes.</p>
<p>Here's a linear slider:<br />

<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000"
			id="fm_linear_1001849632"
			class="flashmovie"
			width="440"
			height="65">
	<param name="movie" value="wp-content/uploads/2009/04/linear.swf" />
	<!--[if !IE]>-->
	<object	type="application/x-shockwave-flash"
			data="wp-content/uploads/2009/04/linear.swf"
			name="fm_linear_1001849632"
			width="440"
			height="65">
	<!--<![endif]-->
		
<p><a href="http://adobe.com/go/getflashplayer"><img src="http://www.adobe.com/images/shared/download_buttons/get_flash_player.gif" alt="Get Adobe Flash player" /></a></p>

	<!--[if !IE]>-->
	</object>
	<!--<![endif]-->
</object>
<p><code>
<pre class="actionscript"><ol start="45"><li style="font-family: Monaco, Lucida Console, Lucida, 'Courier New', Courier, monospace; color: white; font-weight: normal; font-style: normal;"><div style="font-family: Monaco, Lucida Console, Lucida, 'Courier New', Courier, monospace; font-weight: normal; "><span style="color: #F7De2D;">var</span> v:<span style="color: #FFFFFF;">Number</span> = fader.<span style="color: #FFFFFF;">width</span> / totalWidth;</div></li><li style="font-family: Monaco, Lucida Console, Lucida, 'Courier New', Courier, monospace; color: white; font-weight: normal; font-style: normal;"><div style="font-family: Monaco, Lucida Console, Lucida, 'Courier New', Courier, monospace; font-weight: normal; ">SoundMixer.<span style="color: #71A1CE;">soundTransform</span> = <span style="color: #FFFFFF;">new</span> SoundTransform<span style="color: #FFFFFF;">&#40;</span>v<span style="color: #FFFFFF;">&#41;</span>;</div></li></ol></pre>
<p></code></p>
<p>Notice that all the real action happens in the first half of the slider - the first 20% is a huge pickup in sound while the last 20% is almost imperceptible. Because your ear is countering the amplification, it's up to you to counter-counteract the faulty hardware (e.g. your user's inferior hearing) and still deliver a good experience. To do that, you need to remap the amplification from a linear input-equals-output model, onto a curve that's roughly opposite to the users perception.</p>
<p>Here's that same slider remapped to a simple quadratic gain:<br />

<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000"
			id="fm_quadratic_1851218573"
			class="flashmovie"
			width="440"
			height="65">
	<param name="movie" value="wp-content/uploads/2009/04/quadratic.swf" />
	<!--[if !IE]>-->
	<object	type="application/x-shockwave-flash"
			data="wp-content/uploads/2009/04/quadratic.swf"
			name="fm_quadratic_1851218573"
			width="440"
			height="65">
	<!--<![endif]-->
		
<p><a href="http://adobe.com/go/getflashplayer"><img src="http://www.adobe.com/images/shared/download_buttons/get_flash_player.gif" alt="Get Adobe Flash player" /></a></p>

	<!--[if !IE]>-->
	</object>
	<!--<![endif]-->
</object>
<p><code>
<pre class="actionscript"><ol start="45"><li style="font-family: Monaco, Lucida Console, Lucida, 'Courier New', Courier, monospace; color: white; font-weight: normal; font-style: normal;"><div style="font-family: Monaco, Lucida Console, Lucida, 'Courier New', Courier, monospace; font-weight: normal; "><span style="color: #F7De2D;">var</span> v:<span style="color: #FFFFFF;">Number</span> = fader.<span style="color: #FFFFFF;">width</span> / totalWidth;</div></li><li style="font-family: Monaco, Lucida Console, Lucida, 'Courier New', Courier, monospace; color: white; font-weight: normal; font-style: normal;"><div style="font-family: Monaco, Lucida Console, Lucida, 'Courier New', Courier, monospace; font-weight: normal; ">SoundMixer.<span style="color: #71A1CE;">soundTransform</span> = <span style="color: #FFFFFF;">new</span> SoundTransform<span style="color: #FFFFFF;">&#40;</span><span style="color: #FFFFFF;">Math</span>.<span style="color: #FFFFFF;">pow</span><span style="color: #FFFFFF;">&#40;</span>v, <span style="color: #FFFFFF;">2</span><span style="color: #FFFFFF;">&#41;</span>;</div></li></ol></pre>
<p></code></p>
<p>This has a lot more punch to it - the loud end definitely has teeth now, and the quiet end gives you a much finer control. Since we're already working between zero and one, we can employe a simple x&sup2; formula without dealing with offsetting or scaling in the equation. To really fine-tune you could use any exponent you want - say 1&frac12; for a half-and-half approach, or 3 to move all the weight to the right side of the slider.</p>
<p><img src="wp-content/uploads/2009/04/graph.gif" /><br />
To sum up, here's a rough graph that I <del>generated</del> drew in photoshop to illustrate the principle. And if you're wondering, the music is <em>Ode to the Bridge Builder</em> from <a href="http://kylegabler.com/WorldOfGooSoundtrack/" target="_blank">Kyle Gabler's fantastic World of Goo Soundtrack</a> – I'm using it here without permission because it's all I have on my laptop right now – please <a href="http://2dboy.com/games.php" target="_blank">go buy the game</a> so I get sued less (also because you're a Flash dev and it's an inspiring example of great gameplay)!</p>
]]></content:encoded>
			<wfw:commentRss>http://www.calypso88.com/?feed=rss2&amp;p=364</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>News, props, and shameless plugs</title>
		<link>http://www.calypso88.com/?p=359</link>
		<comments>http://www.calypso88.com/?p=359#comments</comments>
		<pubDate>Mon, 02 Mar 2009 22:37:43 +0000</pubDate>
		<dc:creator>Rob</dc:creator>
				<category><![CDATA[Actionscript 3.0]]></category>

		<guid isPermaLink="false">http://www.calypso88.com/?p=359</guid>
		<description><![CDATA[I just secured space for the very first meeting of the Eugene Flash &#038; Flex User Group! I've wanted a group like this for a while but it's difficult in a smaller city so ultimately I gave up and created it myself. I'm hoping we can get some interested people and a good mix of [...]]]></description>
			<content:encoded><![CDATA[<p>I just secured space for the very first meeting of the Eugene Flash & Flex User Group! I've wanted a group like this for a while but it's difficult in a smaller city so ultimately I gave up and created it myself. I'm hoping we can get some interested people and a good mix of creatives and devs from the full spectrum. However this thing shakes out, I'm sure it will be an interesting experience.</p>
<p>In the course of that news, I put up a dedicated blog for the group: <a href="http://effx.org/">effx.org</a>, using a standalone WordPress install and the extremely slick <a href="http://onepresscommunity.com/" target="_blank">OnePress framework</a> that the smart guys over at <a href="http://pushbuttonlabs.com/" target="_blank">PBL</a> have been developing, without which this thing would never have gotten off the ground.</p>
<p>So if you have an interest in Flash, Flex, or AS and you live in the greater Eugene area, drop by the meeting and check it out.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.calypso88.com/?feed=rss2&amp;p=359</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Suspended animation</title>
		<link>http://www.calypso88.com/?p=343</link>
		<comments>http://www.calypso88.com/?p=343#comments</comments>
		<pubDate>Sun, 08 Feb 2009 22:34:48 +0000</pubDate>
		<dc:creator>Rob</dc:creator>
				<category><![CDATA[Actionscript 3.0]]></category>

		<guid isPermaLink="false">http://www.calypso88.com/?p=343</guid>
		<description><![CDATA[Recently, I've been working on a project with some unorthodox requirements; the flash piece in question needed to be removed from the page and brought back later without losing its state or reloading its external assets. To that end I knocked together a loop which removes everything from the stage and stores it to an [...]]]></description>
			<content:encoded><![CDATA[<p>Recently, I've been working on a project with some unorthodox requirements; the flash piece in question needed to be removed from the page and brought back later without losing its state or reloading its external assets. To that end I knocked together a loop which removes everything from the stage and stores it to an array for later. Once clear, the swf is then throttled down to the minimum framerate.</p>
<p><code>
<pre class="actionscript"><ol start="0"><li style="font-family: Monaco, Lucida Console, Lucida, 'Courier New', Courier, monospace; color: white; font-weight: normal; font-style: normal;"><div style="font-family: Monaco, Lucida Console, Lucida, 'Courier New', Courier, monospace; font-weight: normal; "><span style="color: #F7De2D;">private</span> <span style="color: #F7De2D;">const</span> COLD_STORAGE:<span style="color: #FFFFFF;">Array</span> = <span style="color: #F7De2D;"><span style="color: #FFFFFF;">&#91;</span></span><span style="color: #FFFFFF;">&#93;</span>;</div></li><li style="font-family: Monaco, Lucida Console, Lucida, 'Courier New', Courier, monospace; color: white; font-weight: normal; font-style: normal;"><div style="font-family: Monaco, Lucida Console, Lucida, 'Courier New', Courier, monospace; font-weight: normal; ">&nbsp;</div></li><li style="font-family: Monaco, Lucida Console, Lucida, 'Courier New', Courier, monospace; color: white; font-weight: normal; font-style: normal;"><div style="font-family: Monaco, Lucida Console, Lucida, 'Courier New', Courier, monospace; font-weight: normal; "><span style="color: #F7De2D;">public</span> <span style="color: #FF5E00;"><span style="color: #FFFF00;">function</span> freeze</span><span style="color: #FFFFFF;">&#40;</span><span style="color: #FFFFFF;">&#41;</span>:<span style="color: #FFFFFF;">void</span><span style="color: #FFFFFF;">&#123;</span></div></li><li style="font-family: Monaco, Lucida Console, Lucida, 'Courier New', Courier, monospace; color: white; font-weight: normal; font-style: normal;"><div style="font-family: Monaco, Lucida Console, Lucida, 'Courier New', Courier, monospace; font-weight: normal; ">	<span style="color: #F7De2D;">while</span><span style="color: #FFFFFF;">&#40;</span>numChilren<span style="color: #FFFFFF;">&#41;</span><span style="color: #FFFFFF;">&#123;</span> COLD_STORAGE.<span style="color: #FFFFFF;">unshift</span><span style="color: #FFFFFF;">&#40;</span>removeChildAt<span style="color: #FFFFFF;">&#40;</span><span style="color: #FFFFFF;">0</span><span style="color: #FFFFFF;">&#41;</span><span style="color: #FFFFFF;">&#41;</span> <span style="color: #FFFFFF;">&#125;</span></div></li><li style="font-family: Monaco, Lucida Console, Lucida, 'Courier New', Courier, monospace; color: white; font-weight: normal; font-style: normal;"><div style="font-family: Monaco, Lucida Console, Lucida, 'Courier New', Courier, monospace; font-weight: normal; ">	<span style="color: #FFFFFF;">stage</span>.<span style="color: #FFFFFF;">quality</span> = StageQuality.<span style="color: #71A1CE;">LOW</span>;</div></li><li style="font-family: Monaco, Lucida Console, Lucida, 'Courier New', Courier, monospace; color: white; font-weight: normal; font-style: normal;"><div style="font-family: Monaco, Lucida Console, Lucida, 'Courier New', Courier, monospace; font-weight: normal; ">	<span style="color: #FFFFFF;">stage</span>.<span style="color: #71A1CE;">frameRate</span> = .<span style="color: #FFFFFF;">01</span>;</div></li><li style="font-family: Monaco, Lucida Console, Lucida, 'Courier New', Courier, monospace; color: white; font-weight: normal; font-style: normal;"><div style="font-family: Monaco, Lucida Console, Lucida, 'Courier New', Courier, monospace; font-weight: normal; "><span style="color: #FFFFFF;">&#125;</span></div></li></ol></pre>
<p></code></p>
<p>In hibernation, the swf has nothing to render (which takes care of enterFrames, mouseEvents, etc.) and the stage refreshes are pushed out to one every 100 seconds, so cpu use is essentially nil, while all the swf assets chill out in memory until I want them again. </p>
<p><code>
<pre class="actionscript"><ol start="8"><li style="font-family: Monaco, Lucida Console, Lucida, 'Courier New', Courier, monospace; color: white; font-weight: normal; font-style: normal;"><div style="font-family: Monaco, Lucida Console, Lucida, 'Courier New', Courier, monospace; font-weight: normal; "><span style="color: #F7De2D;">public</span> <span style="color: #FF5E00;"><span style="color: #FFFF00;">function</span> thaw</span><span style="color: #FFFFFF;">&#40;</span><span style="color: #FFFFFF;">&#41;</span>:<span style="color: #FFFFFF;">void</span><span style="color: #FFFFFF;">&#123;</span></div></li><li style="font-family: Monaco, Lucida Console, Lucida, 'Courier New', Courier, monospace; color: white; font-weight: normal; font-style: normal;"><div style="font-family: Monaco, Lucida Console, Lucida, 'Courier New', Courier, monospace; font-weight: normal; ">	<span style="color: #F7De2D;">while</span><span style="color: #FFFFFF;">&#40;</span>COLD_STORAGE.<span style="color: #FFFFFF;">length</span><span style="color: #FFFFFF;">&#41;</span><span style="color: #FFFFFF;">&#123;</span> addChild<span style="color: #FFFFFF;">&#40;</span>COLD_STORAGE.<span style="color: #FFFFFF;">pop</span><span style="color: #FFFFFF;">&#40;</span><span style="color: #FFFFFF;">&#41;</span><span style="color: #FFFFFF;">&#41;</span> <span style="color: #FFFFFF;">&#125;</span></div></li><li style="font-family: Monaco, Lucida Console, Lucida, 'Courier New', Courier, monospace; color: white; font-weight: normal; font-style: normal;"><div style="font-family: Monaco, Lucida Console, Lucida, 'Courier New', Courier, monospace; font-weight: normal; ">	<span style="color: #FFFFFF;">stage</span>.<span style="color: #FFFFFF;">quality</span> = StageQuality.<span style="color: #71A1CE;">BEST</span>;</div></li><li style="font-family: Monaco, Lucida Console, Lucida, 'Courier New', Courier, monospace; color: white; font-weight: normal; font-style: normal;"><div style="font-family: Monaco, Lucida Console, Lucida, 'Courier New', Courier, monospace; font-weight: normal; ">	<span style="color: #FFFFFF;">stage</span>.<span style="color: #71A1CE;">frameRate</span> = <span style="color: #FFFFFF;">30</span>;</div></li><li style="font-family: Monaco, Lucida Console, Lucida, 'Courier New', Courier, monospace; color: white; font-weight: normal; font-style: normal;"><div style="font-family: Monaco, Lucida Console, Lucida, 'Courier New', Courier, monospace; font-weight: normal; "><span style="color: #FFFFFF;">&#125;</span></div></li></ol></pre>
<p></code></p>
<p>While I was working on the code to reanimate, I got to thinking about the <a href="http://www.craftymind.com/2008/04/18/updated-elastic-racetrack-for-flash-9-and-avm2/">elastic racetrack</a> and it occurred to me that throttling the framerate down to under a second may be problematic – luckily the ExternalInterface (which I so <a href="http://www.calypso88.com/?p=25">love to hate</a>) already supplied the answer. Since external callbacks are synchronous, they interrupt the normal progression of the code, so it's possible to reset the framefrate without waiting for the next frame to fire. </p>
<p><code>
<pre class="actionscript"><ol start="14"><li style="font-family: Monaco, Lucida Console, Lucida, 'Courier New', Courier, monospace; color: white; font-weight: normal; font-style: normal;"><div style="font-family: Monaco, Lucida Console, Lucida, 'Courier New', Courier, monospace; font-weight: normal; ">ExternalInterface.<span style="color: #71A1CE;">addCallback</span><span style="color: #FFFFFF;">&#40;</span><span style="color: #5FCE3C;">'freeze'</span>, freeze<span style="color: #FFFFFF;">&#41;</span>;</div></li><li style="font-family: Monaco, Lucida Console, Lucida, 'Courier New', Courier, monospace; color: white; font-weight: normal; font-style: normal;"><div style="font-family: Monaco, Lucida Console, Lucida, 'Courier New', Courier, monospace; font-weight: normal; ">ExternalInterface.<span style="color: #71A1CE;">addCallback</span><span style="color: #FFFFFF;">&#40;</span><span style="color: #5FCE3C;">'thaw'</span>, thaw<span style="color: #FFFFFF;">&#41;</span>;</div></li></ol></pre>
<p></code></p>
]]></content:encoded>
			<wfw:commentRss>http://www.calypso88.com/?feed=rss2&amp;p=343</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>AS2 to AS3: Dynamic instance names</title>
		<link>http://www.calypso88.com/?p=302</link>
		<comments>http://www.calypso88.com/?p=302#comments</comments>
		<pubDate>Tue, 20 Jan 2009 15:31:27 +0000</pubDate>
		<dc:creator>Rob</dc:creator>
				<category><![CDATA[AS2 to AS3]]></category>
		<category><![CDATA[Actionscript 3.0]]></category>

		<guid isPermaLink="false">http://www.calypso88.com/?p=302</guid>
		<description><![CDATA[There are a handful of questions that get posted over and over again in the forums that all boil down to the same issue: setting up instance names in AS3 doesn't work. Everyone who hits this problem comes up with a plan of attack that goes something like this: for&#40;i = 0; i &#60; 5; [...]]]></description>
			<content:encoded><![CDATA[<p>There are a handful of questions that get posted over and over again in the forums that all boil down to the same issue: setting up instance names in AS3 doesn't work.</p>
<p>Everyone who hits this problem comes up with a plan of attack that goes something like this:</p>
<p><code>
<pre class="actionscript"><ol start="0"><li style="font-family: Monaco, Lucida Console, Lucida, 'Courier New', Courier, monospace; color: white; font-weight: normal; font-style: normal;"><div style="font-family: Monaco, Lucida Console, Lucida, 'Courier New', Courier, monospace; font-weight: normal; "><span style="color: #F7De2D;">for</span><span style="color: #FFFFFF;">&#40;</span>i = <span style="color: #FFFFFF;">0</span>; i &lt; <span style="color: #FFFFFF;">5</span>; i++<span style="color: #FFFFFF;">&#41;</span><span style="color: #FFFFFF;">&#123;</span></div></li><li style="font-family: Monaco, Lucida Console, Lucida, 'Courier New', Courier, monospace; color: white; font-weight: normal; font-style: normal;"><div style="font-family: Monaco, Lucida Console, Lucida, 'Courier New', Courier, monospace; font-weight: normal; ">	<span style="color: #F7De2D;">var</span> mc:<span style="color: #FFFFFF;">MovieClip</span> = <span style="color: #FFFFFF;">new</span> <span style="color: #FFFFFF;">MovieClip</span><span style="color: #FFFFFF;">&#40;</span><span style="color: #FFFFFF;">&#41;</span>;</div></li><li style="font-family: Monaco, Lucida Console, Lucida, 'Courier New', Courier, monospace; color: white; font-weight: normal; font-style: normal;"><div style="font-family: Monaco, Lucida Console, Lucida, 'Courier New', Courier, monospace; font-weight: normal; ">	mc.<span style="color: #FFFFFF;">name</span> = <span style="color: #5FCE3C;">&quot;mc&quot;</span> + i;</div></li><li style="font-family: Monaco, Lucida Console, Lucida, 'Courier New', Courier, monospace; color: white; font-weight: normal; font-style: normal;"><div style="font-family: Monaco, Lucida Console, Lucida, 'Courier New', Courier, monospace; font-weight: normal; ">	addChild<span style="color: #FFFFFF;">&#40;</span>mc<span style="color: #FFFFFF;">&#41;</span>;</div></li><li style="font-family: Monaco, Lucida Console, Lucida, 'Courier New', Courier, monospace; color: white; font-weight: normal; font-style: normal;"><div style="font-family: Monaco, Lucida Console, Lucida, 'Courier New', Courier, monospace; font-weight: normal; "><span style="color: #FFFFFF;">&#125;</span></div></li><li style="font-family: Monaco, Lucida Console, Lucida, 'Courier New', Courier, monospace; color: white; font-weight: normal; font-style: normal;"><div style="font-family: Monaco, Lucida Console, Lucida, 'Courier New', Courier, monospace; font-weight: normal; ">&nbsp;</div></li><li style="font-family: Monaco, Lucida Console, Lucida, 'Courier New', Courier, monospace; color: white; font-weight: normal; font-style: normal;"><div style="font-family: Monaco, Lucida Console, Lucida, 'Courier New', Courier, monospace; font-weight: normal; ">mc3.<span style="color: #FFFFFF;">play</span><span style="color: #FFFFFF;">&#40;</span><span style="color: #FFFFFF;">&#41;</span>;</div></li></ol></pre>
<p></code></p>
<p>Which sounds pretty good on paper, but generally ends with this:<br />
<code>
<pre class="text"><ol start="0"><li style="font-family: Monaco, Lucida Console, Lucida, 'Courier New', Courier, monospace; color: white; font-weight: normal; font-style: normal;"><div style="font-family: Monaco, Lucida Console, Lucida, 'Courier New', Courier, monospace; font-weight: normal; ">Error 1120: Access of undefined property mc3.</div></li></ol></pre>
<p></code></p>
<p>So what went wrong? This is easily one of the biggest stumbling blocks for new AS3 users, and Adobe goes to great lengths to ignore it and pretend the problem doesn't exist. Here's the secret: Instance names don't really exist! </p>
<p>Ok, more specifically, when you assign an instance name in Flash, there is secret code generated for you behind the scenes that creates two variables which work together to give you the perception of an instance name. To do the same thing in your own code you would use this:</p>
<p><code>
<pre class="actionscript"><ol start="0"><li style="font-family: Monaco, Lucida Console, Lucida, 'Courier New', Courier, monospace; color: white; font-weight: normal; font-style: normal;"><div style="font-family: Monaco, Lucida Console, Lucida, 'Courier New', Courier, monospace; font-weight: normal; "><span style="color: #F7De2D;">public</span> <span style="color: #F7De2D;">var</span> mc3:<span style="color: #FFFFFF;">MovieClip</span> = <span style="color: #FFFFFF;">new</span> <span style="color: #FFFFFF;">MovieClip</span><span style="color: #FFFFFF;">&#40;</span><span style="color: #FFFFFF;">&#41;</span>;</div></li><li style="font-family: Monaco, Lucida Console, Lucida, 'Courier New', Courier, monospace; color: white; font-weight: normal; font-style: normal;"><div style="font-family: Monaco, Lucida Console, Lucida, 'Courier New', Courier, monospace; font-weight: normal; ">mc3.<span style="color: #FFFFFF;">name</span> = <span style="color: #5FCE3C;">&quot;mc3&quot;</span>;</div></li></ol></pre>
<p></code></p>
<h3>A .name is not a thing</h3>
<p>The first half of this solution is repairing a misconception; There is a general belief that setting the name property on an object gives it mystical powers. It doesn't. The name is just a string that is attached to objects for your convenience, it is not a unique identifier. Saying you want to play the clip named "mc3" is just as silly as saying you want to play the clip at <code>.x = 50</code>, or <code>.alpha = 1</code> – these are all attributes of objects, not pointers to the objects themselves.</p>
<p>So with all of that said, now it's time to contradict myself. Adobe has tried to redeem themselves by making a little workaround function for this problem. It comes in the form of the <code>getChildByName("mc3")</code> method. It's not particularly efficient and you can have multiple things share one name so it's not great code practice, but it is a handy tool to be aware of in a pinch.</p>
<h3>Create dynamic variables at runtime</h3>
<p>Having completely debunked .name, we've now got the other half of this issue to deal with - how to create dynamic vars in AS3. Again the answer is, you can't. What you can do, is leverage a single Array to point at all your clips at once.</p>
<p><code>
<pre class="actionscript"><ol start="0"><li style="font-family: Monaco, Lucida Console, Lucida, 'Courier New', Courier, monospace; color: white; font-weight: normal; font-style: normal;"><div style="font-family: Monaco, Lucida Console, Lucida, 'Courier New', Courier, monospace; font-weight: normal; "><span style="color: #F7De2D;">var</span> clips:<span style="color: #FFFFFF;">Array</span> = <span style="color: #F7De2D;"><span style="color: #FFFFFF;">&#91;</span></span><span style="color: #FFFFFF;">&#93;</span>;</div></li><li style="font-family: Monaco, Lucida Console, Lucida, 'Courier New', Courier, monospace; color: white; font-weight: normal; font-style: normal;"><div style="font-family: Monaco, Lucida Console, Lucida, 'Courier New', Courier, monospace; font-weight: normal; ">&nbsp;</div></li><li style="font-family: Monaco, Lucida Console, Lucida, 'Courier New', Courier, monospace; color: white; font-weight: normal; font-style: normal;"><div style="font-family: Monaco, Lucida Console, Lucida, 'Courier New', Courier, monospace; font-weight: normal; "><span style="color: #F7De2D;">for</span><span style="color: #FFFFFF;">&#40;</span>i = <span style="color: #FFFFFF;">0</span>; i &lt; <span style="color: #FFFFFF;">5</span>; i++<span style="color: #FFFFFF;">&#41;</span><span style="color: #FFFFFF;">&#123;</span></div></li><li style="font-family: Monaco, Lucida Console, Lucida, 'Courier New', Courier, monospace; color: white; font-weight: normal; font-style: normal;"><div style="font-family: Monaco, Lucida Console, Lucida, 'Courier New', Courier, monospace; font-weight: normal; ">	<span style="color: #F7De2D;">var</span> mc:<span style="color: #FFFFFF;">MovieClip</span> = <span style="color: #FFFFFF;">new</span> <span style="color: #FFFFFF;">MovieClip</span><span style="color: #FFFFFF;">&#40;</span><span style="color: #FFFFFF;">&#41;</span>;</div></li><li style="font-family: Monaco, Lucida Console, Lucida, 'Courier New', Courier, monospace; color: white; font-weight: normal; font-style: normal;"><div style="font-family: Monaco, Lucida Console, Lucida, 'Courier New', Courier, monospace; font-weight: normal; ">	mc.<span style="color: #FFFFFF;">name</span> = <span style="color: #5FCE3C;">&quot;mc&quot;</span> + i;</div></li><li style="font-family: Monaco, Lucida Console, Lucida, 'Courier New', Courier, monospace; color: white; font-weight: normal; font-style: normal;"><div style="font-family: Monaco, Lucida Console, Lucida, 'Courier New', Courier, monospace; font-weight: normal; ">	addChild<span style="color: #FFFFFF;">&#40;</span>mc<span style="color: #FFFFFF;">&#41;</span>;</div></li><li style="font-family: Monaco, Lucida Console, Lucida, 'Courier New', Courier, monospace; color: white; font-weight: normal; font-style: normal;"><div style="font-family: Monaco, Lucida Console, Lucida, 'Courier New', Courier, monospace; font-weight: normal; ">	clips<span style="color: #FFFFFF;">&#91;</span>i<span style="color: #FFFFFF;">&#93;</span> = mc;</div></li><li style="font-family: Monaco, Lucida Console, Lucida, 'Courier New', Courier, monospace; color: white; font-weight: normal; font-style: normal;"><div style="font-family: Monaco, Lucida Console, Lucida, 'Courier New', Courier, monospace; font-weight: normal; "><span style="color: #FFFFFF;">&#125;</span></div></li></ol></pre>
<p></code></p>
<p>That code will create 5 distinct MovieClips and stick them all into the clips Array under different indices. To get a specific clip back later, you just have to know the index:</p>
<p><code>
<pre class="actionscript"><ol start="8"><li style="font-family: Monaco, Lucida Console, Lucida, 'Courier New', Courier, monospace; color: white; font-weight: normal; font-style: normal;"><div style="font-family: Monaco, Lucida Console, Lucida, 'Courier New', Courier, monospace; font-weight: normal; ">clips<span style="color: #FFFFFF;">&#91;</span><span style="color: #FFFFFF;">3</span><span style="color: #FFFFFF;">&#93;</span>.<span style="color: #FFFFFF;">play</span><span style="color: #FFFFFF;">&#40;</span><span style="color: #FFFFFF;">&#41;</span>;</div></li></ol></pre>
<p></code></p>
]]></content:encoded>
			<wfw:commentRss>http://www.calypso88.com/?feed=rss2&amp;p=302</wfw:commentRss>
		<slash:comments>23</slash:comments>
		</item>
		<item>
		<title>AS2 to AS3: Calling a Method of a .parent Class (2 of 2)</title>
		<link>http://www.calypso88.com/?p=301</link>
		<comments>http://www.calypso88.com/?p=301#comments</comments>
		<pubDate>Sun, 18 Jan 2009 22:38:26 +0000</pubDate>
		<dc:creator>Rob</dc:creator>
				<category><![CDATA[Actionscript 3.0]]></category>

		<guid isPermaLink="false">http://www.calypso88.com/?p=301</guid>
		<description><![CDATA[&#8672; AS2 to AS3: Calling a Method of a .parent Class (1 of 2) And now - the thrilling conclusion! So, The Easy Way is great for getting your project working and out the door - however it's the opposite of great for writing re-usable code and observing happy OOP best practices. If you're asking [...]]]></description>
			<content:encoded><![CDATA[<p><a href="http://www.calypso88.com/?p=288"><em>&#8672; AS2 to AS3: Calling a Method of a .parent Class (1 of 2)</em></a></p>
<h3>And now - the thrilling conclusion!</h3>
<p>So, <a href="http://www.calypso88.com/?p=288">The Easy Way</a> is great for getting your project working and out the door - however it's the opposite of great for writing re-usable code and observing happy OOP best practices. If you're asking "why?," well here's the answer: you're breaking the chain of command. The child class should never (<em>ever!</em>) be issuing commands to the parent – the most it should do is alert the parent to any changes and let the parent be the judge of what to do.</p>
<p>For the sake of argument, let's say that your child class is a pre-loader and your parent class is the main movie. When that loader hits 100%, it's going to kick the main timeline in the ass and start the playhead immediately. Depending on your setup, that might be ok - but imagine we also have a fancy loading animation on screen - even though the load is done, we still want to play out the last 20 frames of animation before we run off to the next scene. The workaround is clearly not going to help us in that respect because the loader has no idea what's going on with the animation - and what's more, if you've got the loader calling the shots, you can't ever re-use it in another project without reworking a bunch of that code.</p>
<h3>The Hard Way</h3>
<p>We need passive alerting, and that means Events. So let's scratch the parent.someFunction line and dispatch a custom event instead:</p>
<p><code></p>
<pre class="actionscript"><ol start="0"><li style="font-family: Monaco, Lucida Console, Lucida, 'Courier New', Courier, monospace; color: white; font-weight: normal; font-style: normal;"><div style="font-family: Monaco, Lucida Console, Lucida, 'Courier New', Courier, monospace; font-weight: normal; "><span style="color: #F7De2D;">import</span> flash.<span style="color: #71A1CE;">display</span>.<span style="color: #71A1CE;">Sprite</span>;</div></li><li style="font-family: Monaco, Lucida Console, Lucida, 'Courier New', Courier, monospace; color: white; font-weight: normal; font-style: normal;"><div style="font-family: Monaco, Lucida Console, Lucida, 'Courier New', Courier, monospace; font-weight: normal; "><span style="color: #F7De2D;">import</span> flash.<span style="color: #71A1CE;">events</span>.<span style="color: #71A1CE;">Event</span>;</div></li><li style="font-family: Monaco, Lucida Console, Lucida, 'Courier New', Courier, monospace; color: white; font-weight: normal; font-style: normal;"><div style="font-family: Monaco, Lucida Console, Lucida, 'Courier New', Courier, monospace; font-weight: normal; ">&nbsp;</div></li><li style="font-family: Monaco, Lucida Console, Lucida, 'Courier New', Courier, monospace; color: white; font-weight: normal; font-style: normal;"><div style="font-family: Monaco, Lucida Console, Lucida, 'Courier New', Courier, monospace; font-weight: normal; "><span style="color: #F7De2D;">public</span> <span style="color: #FFFFFF;">class</span> ChildClass <span style="color: #FFFFFF;">extends</span> Sprite<span style="color: #FFFFFF;">&#123;</span></div></li><li style="font-family: Monaco, Lucida Console, Lucida, 'Courier New', Courier, monospace; color: white; font-weight: normal; font-style: normal;"><div style="font-family: Monaco, Lucida Console, Lucida, 'Courier New', Courier, monospace; font-weight: normal; ">&nbsp;</div></li><li style="font-family: Monaco, Lucida Console, Lucida, 'Courier New', Courier, monospace; color: white; font-weight: normal; font-style: normal;"><div style="font-family: Monaco, Lucida Console, Lucida, 'Courier New', Courier, monospace; font-weight: normal; ">		<span style="color: #666666;">//  ...</span></div></li><li style="font-family: Monaco, Lucida Console, Lucida, 'Courier New', Courier, monospace; color: white; font-weight: normal; font-style: normal;"><div style="font-family: Monaco, Lucida Console, Lucida, 'Courier New', Courier, monospace; font-weight: normal; ">		<span style="color: #666666;">//  MainClass(parent).someFunction();</span></div></li><li style="font-family: Monaco, Lucida Console, Lucida, 'Courier New', Courier, monospace; color: white; font-weight: normal; font-style: normal;"><div style="font-family: Monaco, Lucida Console, Lucida, 'Courier New', Courier, monospace; font-weight: normal; ">&nbsp;</div></li><li style="font-family: Monaco, Lucida Console, Lucida, 'Courier New', Courier, monospace; color: white; font-weight: normal; font-style: normal;"><div style="font-family: Monaco, Lucida Console, Lucida, 'Courier New', Courier, monospace; font-weight: normal; ">		<span style="color: #F7De2D;">var</span> <span style="color: #FFFFFF;">e</span>:Event = <span style="color: #FFFFFF;">new</span> Event<span style="color: #FFFFFF;">&#40;</span><span style="color: #5FCE3C;">'readyToGo'</span><span style="color: #FFFFFF;">&#41;</span>;</div></li><li style="font-family: Monaco, Lucida Console, Lucida, 'Courier New', Courier, monospace; color: white; font-weight: normal; font-style: normal;"><div style="font-family: Monaco, Lucida Console, Lucida, 'Courier New', Courier, monospace; font-weight: normal; ">		dispatchEvent<span style="color: #FFFFFF;">&#40;</span><span style="color: #FFFFFF;">e</span><span style="color: #FFFFFF;">&#41;</span>;</div></li></ol></pre>
<p></code></p>
<p>Ok, that looks pretty good. Now whenever the child class needs to do something, it just shouts out that it's ready and anyone else can listen to it and act (or ignore) accordingly. What's more, we've eliminated a targetted call so now the child class will work inside any parent class (not just those with someFunction() defined).</p>
<p>Now, the parent has to listen to the child and take over the responsibility of acting when that event is fired.</p>
<p><code></p>
<pre class="actionscript"><ol start="0"><li style="font-family: Monaco, Lucida Console, Lucida, 'Courier New', Courier, monospace; color: white; font-weight: normal; font-style: normal;"><div style="font-family: Monaco, Lucida Console, Lucida, 'Courier New', Courier, monospace; font-weight: normal; "><span style="color: #F7De2D;">import</span> flash.<span style="color: #71A1CE;">display</span>.<span style="color: #71A1CE;">Sprite</span>;</div></li><li style="font-family: Monaco, Lucida Console, Lucida, 'Courier New', Courier, monospace; color: white; font-weight: normal; font-style: normal;"><div style="font-family: Monaco, Lucida Console, Lucida, 'Courier New', Courier, monospace; font-weight: normal; "><span style="color: #F7De2D;">import</span> ChildClass;</div></li><li style="font-family: Monaco, Lucida Console, Lucida, 'Courier New', Courier, monospace; color: white; font-weight: normal; font-style: normal;"><div style="font-family: Monaco, Lucida Console, Lucida, 'Courier New', Courier, monospace; font-weight: normal; ">&nbsp;</div></li><li style="font-family: Monaco, Lucida Console, Lucida, 'Courier New', Courier, monospace; color: white; font-weight: normal; font-style: normal;"><div style="font-family: Monaco, Lucida Console, Lucida, 'Courier New', Courier, monospace; font-weight: normal; "><span style="color: #F7De2D;">public</span> <span style="color: #FFFFFF;">class</span> MainClass <span style="color: #FFFFFF;">extends</span> Sprite<span style="color: #FFFFFF;">&#123;</span></div></li><li style="font-family: Monaco, Lucida Console, Lucida, 'Courier New', Courier, monospace; color: white; font-weight: normal; font-style: normal;"><div style="font-family: Monaco, Lucida Console, Lucida, 'Courier New', Courier, monospace; font-weight: normal; ">&nbsp;</div></li><li style="font-family: Monaco, Lucida Console, Lucida, 'Courier New', Courier, monospace; color: white; font-weight: normal; font-style: normal;"><div style="font-family: Monaco, Lucida Console, Lucida, 'Courier New', Courier, monospace; font-weight: normal; ">		<span style="color: #666666;">//  ...</span></div></li><li style="font-family: Monaco, Lucida Console, Lucida, 'Courier New', Courier, monospace; color: white; font-weight: normal; font-style: normal;"><div style="font-family: Monaco, Lucida Console, Lucida, 'Courier New', Courier, monospace; font-weight: normal; ">		<span style="color: #F7De2D;">var</span> c:ChildClass = <span style="color: #FFFFFF;">new</span> ChildClass<span style="color: #FFFFFF;">&#40;</span><span style="color: #FFFFFF;">&#41;</span>;</div></li><li style="font-family: Monaco, Lucida Console, Lucida, 'Courier New', Courier, monospace; color: white; font-weight: normal; font-style: normal;"><div style="font-family: Monaco, Lucida Console, Lucida, 'Courier New', Courier, monospace; font-weight: normal; ">		c.<span style="color: #71A1CE;">addEventListener</span><span style="color: #FFFFFF;">&#40;</span><span style="color: #5FCE3C;">'readyToGo'</span>, someFunction<span style="color: #FFFFFF;">&#41;</span>;</div></li></ol></pre>
<p></code></p>
<p>Perfect - now things are working as intended and there's no breach of OOP responsibilities!</p>
<p><a href="http://www.calypso88.com/?p=288"><em>&#8672; AS2 to AS3: Calling a Method of a .parent Class (1 of 2)</em></a></p>
]]></content:encoded>
			<wfw:commentRss>http://www.calypso88.com/?feed=rss2&amp;p=301</wfw:commentRss>
		<slash:comments>7</slash:comments>
		</item>
		<item>
		<title>AS2 to AS3: Calling a Method of a .parent Class (1 of 2)</title>
		<link>http://www.calypso88.com/?p=288</link>
		<comments>http://www.calypso88.com/?p=288#comments</comments>
		<pubDate>Sun, 18 Jan 2009 20:54:03 +0000</pubDate>
		<dc:creator>Rob</dc:creator>
				<category><![CDATA[AS2 to AS3]]></category>
		<category><![CDATA[Actionscript 3.0]]></category>

		<guid isPermaLink="false">http://www.calypso88.com/?p=288</guid>
		<description><![CDATA[I haven't posted in ages so I'm throwing out a quickie to get myself back in the rhythm. I don't have anything super-cool today so I'm going to kick off a series of posts for users who are jumping from AS2 to AS3. Mostly these will just be answers to super-common questions out on the [...]]]></description>
			<content:encoded><![CDATA[<p><em>I haven't posted in ages so I'm throwing out a quickie to get myself back in the rhythm. I don't have anything super-cool today so I'm going to kick off a series of posts for users who are jumping from AS2 to AS3. Mostly these will just be answers to super-common questions out on the forums so I can stop re-typing them all the time.</em></p>
<p>I see some version of this question posted almost daily: <em>"I'm new to AS3 and I have a parent class and a child class; how can I call a function in the parent class from inside the child?"</em></p>
<p>By this time you've already tried parent.someFunction() and gotten this</p>
<blockquote><p><code>Error 1061: Call to a possibly undefined method someFunction through a reference with static type flash.display:DisplayObjectContainer.</code></p></blockquote>
<p>The problem is that the child class is essentially deaf and blind - it has no way of knowing what kind of object the parent is (it could be a Sprite, MC, stage, custom class, whatever) so Flash has to be safe and restrict you to the common denominator, DisplayObjectContainer, from which all those other classes derive. Because of that, the .parent property will only allow you to call DisplayObjectContainer methods on it such as removeChild, getChildByName, mouseEnabled, &amp;c.</p>
<p>So right here there is a fork in the road – you can make a couple of assumptions and get a quick and easy answer and be done, or you can do a little reworking of your code and get to the bottom of the problem once and for all.</p>
<h3>The Easy Way</h3>
<p>Since most custom classes extend MovieClip, we can tell the compiler to go ahead and open up that functionality to us by treating .parent as a MovieClip instead of just a DisplayObjectContainer:</p>
<p><code></p>
<pre class="actionscript"><ol><li style="font-family: Monaco, Lucida Console, Lucida, 'Courier New', Courier, monospace; color: white; font-weight: normal; font-style: normal;"><div style="font-family: Monaco, Lucida Console, Lucida, 'Courier New', Courier, monospace; font-weight: normal; "><span style="color: #FFFFFF;">MovieClip</span><span style="color: #FFFFFF;">&#40;</span>parent<span style="color: #FFFFFF;">&#41;</span>.<span style="color: #71A1CE;">someFunction</span><span style="color: #FFFFFF;">&#40;</span><span style="color: #FFFFFF;">&#41;</span>;</div></li></ol></pre>
<p></code></p>
<p>That line tells Flash that the parent is a MovieClip (or some offshoot) and therefore is a dymamic class – meaning you can add properties and public functions to it on the fly – so you can call anything you want on it and the compiler will search for it instead of falling back to what is explicitly stated in the class at compile-time.</p>
<p>If that's a no-go for you (say your parent is a Sprite, for example), you can still use this trick but you'll need to target the functionality of the main class a little more specifically.</p>
<p><code></p>
<pre class="actionscript"><ol start="0"><li style="font-family: Monaco, Lucida Console, Lucida, 'Courier New', Courier, monospace; color: white; font-weight: normal; font-style: normal;"><div style="font-family: Monaco, Lucida Console, Lucida, 'Courier New', Courier, monospace; font-weight: normal; "><span style="color: #F7De2D;">import</span> flash.<span style="color: #71A1CE;">display</span>.<span style="color: #71A1CE;">Sprite</span>;</div></li><li style="font-family: Monaco, Lucida Console, Lucida, 'Courier New', Courier, monospace; color: white; font-weight: normal; font-style: normal;"><div style="font-family: Monaco, Lucida Console, Lucida, 'Courier New', Courier, monospace; font-weight: normal; "><span style="color: #F7De2D;">import</span> MainClass;</div></li><li style="font-family: Monaco, Lucida Console, Lucida, 'Courier New', Courier, monospace; color: white; font-weight: normal; font-style: normal;"><div style="font-family: Monaco, Lucida Console, Lucida, 'Courier New', Courier, monospace; font-weight: normal; ">&nbsp;</div></li><li style="font-family: Monaco, Lucida Console, Lucida, 'Courier New', Courier, monospace; color: white; font-weight: normal; font-style: normal;"><div style="font-family: Monaco, Lucida Console, Lucida, 'Courier New', Courier, monospace; font-weight: normal; "><span style="color: #F7De2D;">public</span> <span style="color: #FFFFFF;">class</span> ChildClass <span style="color: #FFFFFF;">extends</span> Sprite<span style="color: #FFFFFF;">&#123;</span></div></li><li style="font-family: Monaco, Lucida Console, Lucida, 'Courier New', Courier, monospace; color: white; font-weight: normal; font-style: normal;"><div style="font-family: Monaco, Lucida Console, Lucida, 'Courier New', Courier, monospace; font-weight: normal; ">&nbsp;</div></li><li style="font-family: Monaco, Lucida Console, Lucida, 'Courier New', Courier, monospace; color: white; font-weight: normal; font-style: normal;"><div style="font-family: Monaco, Lucida Console, Lucida, 'Courier New', Courier, monospace; font-weight: normal; ">		<span style="color: #666666;">//  ...</span></div></li><li style="font-family: Monaco, Lucida Console, Lucida, 'Courier New', Courier, monospace; color: white; font-weight: normal; font-style: normal;"><div style="font-family: Monaco, Lucida Console, Lucida, 'Courier New', Courier, monospace; font-weight: normal; ">		MainClass<span style="color: #FFFFFF;">&#40;</span>parent<span style="color: #FFFFFF;">&#41;</span>.<span style="color: #71A1CE;">someFunction</span><span style="color: #FFFFFF;">&#40;</span><span style="color: #FFFFFF;">&#41;</span>;</div></li></ol></pre>
<p></code></p>
<h3>The Hard Way</h3>
<p>Ok - judge me if you want but I've already spent way too much time on the first half of this post and I'm not even to the good stuff yet. I'm going to hammer out the second half of this and post it a little bit later so that this whole concept is more digestible. Continuation is imminent!</p>
<p><em>continued: <a href="http://www.calypso88.com/?p=301">AS2 to AS3: Calling a Method of a .parent Class (2 of 2) &#8674;</a></em> </p>
]]></content:encoded>
			<wfw:commentRss>http://www.calypso88.com/?feed=rss2&amp;p=288</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Moved &amp; Mangled</title>
		<link>http://www.calypso88.com/?p=220</link>
		<comments>http://www.calypso88.com/?p=220#comments</comments>
		<pubDate>Wed, 03 Dec 2008 15:07:00 +0000</pubDate>
		<dc:creator>Rob</dc:creator>
				<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://www.calypso88.com/?p=220</guid>
		<description><![CDATA[I got up the gumption to move the site last night and it seems to have been (for the most part?) successful! First off my apologies to anyone inconvenienced – I'm trying to clean up my file structure so a lot of stuff is still in flux. Secondly, it seems as though my encoding has [...]]]></description>
			<content:encoded><![CDATA[<p>I got up the gumption to move the site last night and it seems to have been (for the most part?) successful! First off my apologies to anyone inconvenienced – I'm trying to clean up my file structure so a lot of stuff is still in flux. Secondly, it seems as though my encoding has gone all pear-shaped and changed non-roman glyphs into ASCII-soup. I'm working on both issues and hope to have things running smoothly in a couple of days. If you need a class or formula urgently, please give me a shout at <a href="&#109;&#x61;&#x69;&#x6c;&#x74;&#111;&#58;&#x72;&#x6f;&#98;&#x40;&#104;&#97;&#116;&#x74;&#x76;&#x2e;&#x63;&#111;&#109;" class="style1" style="text-decoration:none ">&#x72;&#x6f;&#98;&#x40;&#104;&#97;&#116;&#x74;&#x76;&#x2e;&#x63;&#111;&#109;</a>.</p>
<p>Now the good news; My new host runs entirely on wind power and my out of pocket expense is a quarter of what I used to pay. Huzzah! </p>
]]></content:encoded>
			<wfw:commentRss>http://www.calypso88.com/?feed=rss2&amp;p=220</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>AS3 Math Optimization – int is the new floor()</title>
		<link>http://www.calypso88.com/?p=174</link>
		<comments>http://www.calypso88.com/?p=174#comments</comments>
		<pubDate>Thu, 23 Oct 2008 07:08:40 +0000</pubDate>
		<dc:creator>Rob</dc:creator>
				<category><![CDATA[AS3 Speed Benchmarking]]></category>
		<category><![CDATA[Actionscript 3.0]]></category>
		<category><![CDATA[Optimization]]></category>

		<guid isPermaLink="false">http://www.calypso88.com/?p=174</guid>
		<description><![CDATA[UPDATE: The benchmarks on this thread were taken in the Flash 9 Debug player (which includes some crazy bloating) - I've posted an updated set of tests here using the Flash 10 Release player, which should give you a better picture of real-world savings for the majority of web users. In case you missed my [...]]]></description>
			<content:encoded><![CDATA[<p><span style="background:#EEE; display:block; color:#222; padding: 10px 10px 10px 10px; margin:10px 0px 0px 0px; border: 1px solid #CCD"><strong>UPDATE</strong>: The benchmarks on this thread were taken in the Flash 9 Debug player (which includes some crazy bloating) - I've posted <a href="http://www.calypso88.com/?p=539">an updated set of tests here</a> using the Flash 10 Release player, which should give you a better picture of real-world savings for the majority of web users.</span></p>
<p>In case you missed my <a href="http://www.calypso88.com/?p=130">earlier post</a>, I've had a raging Flash-on for optimization lately, and today I'm jumping into the <a href="http://livedocs.adobe.com/flash/9.0/ActionScriptLangRefV3/index.html?Math.html&#038;">Math</a> class. But first! A little warmup with operators.</p>
<p>I've often heard that addition is fastest, followed by subtraction and multiplication, with division being the slowest but I'd never seen any proof so I threw together my own test:</p>
<p style="text-align:center"><img src="http://calypso88.com/wp-content/uploads/2008/10/math_img1.gif" /></p>
<p>Way to go subtraction, almost 12% faster than addition! Ok, on to the good stuff. From here on down I'm running 1,000,000 iterations per test, the same <a href="http://www.calypso88.com/?page_id=160">test code</a> I used previously, and compiling each test individually about five times (or until I'm satisfied with an average time).</p>
<p>Alright - the Math class. First and foremost this class holds some handy constants so my human meat-brain doesn't have to. The downside is that the AVM doesn't play well with static properties of other classes so there's a pretty significant slowdown. Instead, just retrieve the constant from Math once and store it in a locally scoped variable.</p>
<p><img src="http://calypso88.com/wp-content/uploads/2008/10/pi.gif" /></p>
<p>While a lot of the Math methods are invaluable (Math.atan2 == &hearts;), there are also a few that aren't as complex and slow your swf down unnecessarily. A big one that's easy to work around is the pow method – unless you're doing some heavy lifting with it, you'll see a good boost by keying out your formula by hand:</p>
<p><img src="http://calypso88.com/wp-content/uploads/2008/10/math_pow2.gif" /><br />
<img src="http://calypso88.com/wp-content/uploads/2008/10/math_pow3.gif" /></p>
<p>Or you can replace costly comparison calls with a little logic:</p>
<p><img src="http://calypso88.com/wp-content/uploads/2008/10/math_min.gif" /><br />
<img src="http://calypso88.com/wp-content/uploads/2008/10/math_max.gif" /><br />
<img src="http://calypso88.com/wp-content/uploads/2008/10/math_abs.gif" /></p>
<p>Going a step further, you can take advantage of int casting to shear off any significant digits to the right of the decimal.</p>
<p><img src="http://calypso88.com/wp-content/uploads/2008/10/math_floor.gif" /></p>
<p>By substituting int as a super fast round-down, it's an easy jump to true rounding:</p>
<p><img src="http://calypso88.com/wp-content/uploads/2008/10/math_round.gif" /></p>
<p><span style="background:#EEE; display:block; color:#222; padding: 10px 10px 10px 10px; margin:10px 0px 0px 0px; border: 1px solid #CCD"><strong>UPDATE</strong>: A lot of other people have posted that you can recreate Math.ceil() by using <code>int(i)+1</code>, which never rang true to me – it only works on non-integers. I finally came around to a fix using modulus:<br />&nbsp;<br /><code>(i % 1) ? int(i) + 1 : i;</code><br />&nbsp;<br />I don't have a fancy graph for this one but I benched it around 75% faster than Math.ceil. </span></p>
<p>My last trick is a monstrous, ugly, hack that I'm hiding over on <a href=http://www.calypso88.com/?page_id=21#fastsine>the code page</a>, it's an approximation for computing sine (which means you can also use it for co-sine by adding &pi;/2 radians). Interestingly, this method of calculating the sine of an angle is actually less efficient and less accurate than the built in method, but the lag from calling the static method pushes Math.sin over the top.</p>
<p><img src="http://calypso88.com/wp-content/uploads/2008/10/math_sin.gif" /></p>
<blockquote><p><strong>Next</strong>: I'm hoping to give arrays a little loving in the not too distant future...if I ever get some free time that is. In the meantime – steer clear of unshift!</p>
<p>
<p><strong>Further reading</strong>:<br /><a href="http://blog.joa-ebert.com/2008/04/26/actionscript-3-optimization-techniques/" target="_blank">Joa Ebert on optimization</a><br /><a href="http://osflash.org/as3_speed_optimizations" target="_blank">Speed tests over on OS Flash</a><br /><a href="http://lab.polygonal.de/2007/05/10/bitwise-gems-fast-integer-math/" target="_blank">Bitwise gems at Polygonal</a></p>
</p>
</blockquote>
]]></content:encoded>
			<wfw:commentRss>http://www.calypso88.com/?feed=rss2&amp;p=174</wfw:commentRss>
		<slash:comments>6</slash:comments>
		</item>
		<item>
		<title>Loops!</title>
		<link>http://www.calypso88.com/?p=130</link>
		<comments>http://www.calypso88.com/?p=130#comments</comments>
		<pubDate>Sat, 04 Oct 2008 04:52:25 +0000</pubDate>
		<dc:creator>Rob</dc:creator>
				<category><![CDATA[AS3 Speed Benchmarking]]></category>
		<category><![CDATA[Actionscript 3.0]]></category>
		<category><![CDATA[Optimization]]></category>

		<guid isPermaLink="false">http://www.calypso88.com/?p=130</guid>
		<description><![CDATA[I've been thinking about AS3 optimization lately so I dusted off the old benchmark code and started speed testing some things. I meant to put together a post filled with exciting optimizations and tricks, but I got bogged down almost immediately in loop code. When I started getting into it, I was somewhat surprised by [...]]]></description>
			<content:encoded><![CDATA[<p>I've been thinking about AS3 optimization lately so I dusted off the old <a href="http://www.calypso88.com/?page_id=160">benchmark code</a> and started speed testing some things. I meant to put together a post filled with exciting optimizations and tricks, but I got bogged down almost immediately in loop code.</p>
<p>When I started getting into it, I was somewhat surprised by how many ways there are to write a basic <em>for</em> loop. Combined with the different number types, that grows into a huge amount of variation in the way people can write code, so it follows that some methods must be better than others. I broke it down into four different structures:</p>
<ol>
<li>Undefined variable, count up to ten.</li>
<li>Variable set to 10, negative increment to zero.</li>
<li>Variable set to 0, increment to ten.</li>
<li>Variable set to 10, decrement to zero.</li>
</ol>
<div>From there I also tested the three number types (Number, int, uint), as well as an untyped variable. And in the interest of full disclosure, I ran these loops exactly as they appear in a test harness set to iterate one million times. I compiled each test separately instead of running them in sequence just to make sure there was no weirdness from the garbage collector, and I ran each test at least three times (averaging them roughly in my head). The longest test clocked 660ms, the shortest was around 5. Here's the nitty-gritty:</div>
<p><img src="http://www.calypso88.com/wp-content/uploads/2008/10/loop-chart.gif" alt="" /></p>
<p>These results are a little odd…let's look at what's going on. First of all, the obvious one: int is fast, uint is slow, and untyped is downright painful. So int it is, now on to technique.</p>
<p>The first and third test appear to be the same code, but there's a pretty large discrepancy between them at runtime. In fact the first test always wins by a visible margin. <del>The difference between the first technique and the other three, is that the first test doesn't need an extra trip to memory to manually assign value to the newly instanced variable.</del></p>
<p>You may also be wondering about the negative increment in the second test – this is actually two tricks in one (and for a long time, I believed this to be the fastest execution). Even using a negative value, the addition operator takes about ¾ the time of the decrement (j--) operator. On top of that, looping backwards from a high value to zero, means you don't need to run a comparison, you can just cast the variable directly to a boolean.</p>
<p>All the rest of the code should be pretty pedestrian. There is one little snag in the untyped results but I suspect that's coming from weirdness in the JIT when it has to continually recast those values, and it's worth noting that uint really doesn't like the increment/decrement operators. And lastly, if you're wondering, I didn't test while loops here because both while and for loops are compiled into the same code – as far as the player is concerned, there is no difference, so use whichever you prefer.</p>
<p><span style="background:#EEE; display:block; color:#222; padding: 10px 10px 10px 10px; margin:10px 0px 0px 0px; border: 1px solid #CCD""><strong>UPDATE</strong>: Ok this is borked. In the middle of the night it came to me (in a vision?) – since the variable is never defined in the first test, maybe the JIT is just jumping the rails and never going through that loop at all? That would certainly explain the speed increase (better than my feeble explanation earlier).<br />&nbsp;<br />So testing should have been an easy iterator variable - testing a loop that counts to 10, over 1 million iterations should trace out 10 million. Somehow the undefined loop code is so extremely broken that it's actually leaking out into the scope above! When I tested I got back 10...implying that the test code actually broke my benchmark harness. I'm still trying to get to the bottom of this but in the meantime, just go with method #2.</span></p>
]]></content:encoded>
			<wfw:commentRss>http://www.calypso88.com/?feed=rss2&amp;p=130</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
		<item>
		<title>SWF: Automatic swf loader</title>
		<link>http://www.calypso88.com/?p=41</link>
		<comments>http://www.calypso88.com/?p=41#comments</comments>
		<pubDate>Tue, 16 Sep 2008 02:28:17 +0000</pubDate>
		<dc:creator>Rob</dc:creator>
				<category><![CDATA[AS3 Utility Classes]]></category>
		<category><![CDATA[Actionscript 3.0]]></category>

		<guid isPermaLink="false">http://www.calypso88.com/?p=41</guid>
		<description><![CDATA[SWF: [AS3] [Zip] [doc] When I posted the Pic class earlier, I knew immediately that I should code a companion class to handle the specific loading of swf files. With static images, you usually don't need a handle on the actual bitmap, but when you get into loading external Flash content, you generally want to [...]]]></description>
			<content:encoded><![CDATA[<div style="width: 130px; padding: 6px; display: inline; float: right; text-align: center;"><a href="http://calypso88.com/wp-content/uploads/2008/09/SWF.zip"><img src="http://calypso88.com/wp-content/themes/dl.jpg" alt="Download this class" width="130" height="30" /></a></p>
<p>SWF: [<a href="http://www.calypso88.com/?page_id=88">AS3</a>] [<a href="http://calypso88.com/wp-content/uploads/2008/09/SWF.zip">Zip</a>] [<a href="http://www.calypso88.com/?page_id=107">doc</a>]</div>
<p>When I posted <a href="http://www.calypso88.com/?p=34">the Pic class</a> earlier, I knew immediately that I should code a companion class to handle the specific loading of swf files. With static images, you usually don't need a handle on the actual bitmap, but when you get into loading external Flash content, you generally want to interact with it.</p>
<p>To that end, I'm working on a class that will pass all the normal MovieClip properties back and forth between the parent and the loaded swf as though the wrapper were the swf itself, but that's going to take a while to really put together and test.</p>
<blockquote><p><strong>NOTE</strong>: I briefly considered a <a href="http://www.bit-101.com/blog/?p=1290">monkey-patch</a> to just add a little loader directly onto the native MovieClip class but the idea of modifying all MC instances in the entire language just to add one niggling bit of functionality makes my blood boil. If Adobe wanted us to ignore the Loader class, they would have built things that way to start with (and named the whole mess AS2)!</p></blockquote>
<p>In the meantime, here's the SWF class; A lightweight (~1500 bytes) loader that hides all the nitty-gritty stuff so you can just drop it in and go. Loading a swf and putting it on stage is as easy as this:</p>
<p><code></p>
<pre class="actionscript"><ol start="0"><li style="font-family: Monaco, Lucida Console, Lucida, 'Courier New', Courier, monospace; color: white; font-weight: normal; font-style: normal;"><div style="font-family: Monaco, Lucida Console, Lucida, 'Courier New', Courier, monospace; font-weight: normal; "><span style="color: #F7De2D;">import</span> com.<span style="color: #71A1CE;">calypso88</span>.<span style="color: #71A1CE;">SWF</span>;</div></li><li style="font-family: Monaco, Lucida Console, Lucida, 'Courier New', Courier, monospace; color: white; font-weight: normal; font-style: normal;"><div style="font-family: Monaco, Lucida Console, Lucida, 'Courier New', Courier, monospace; font-weight: normal; ">&nbsp;</div></li><li style="font-family: Monaco, Lucida Console, Lucida, 'Courier New', Courier, monospace; color: white; font-weight: normal; font-style: normal;"><div style="font-family: Monaco, Lucida Console, Lucida, 'Courier New', Courier, monospace; font-weight: normal; "><span style="color: #F7De2D;">var</span> mySWF:SWF = <span style="color: #FFFFFF;">new</span> SWF<span style="color: #FFFFFF;">&#40;</span><span style="color: #5FCE3C;">'http://www.calypso88.com/test.swf'</span><span style="color: #FFFFFF;">&#41;</span>;</div></li><li style="font-family: Monaco, Lucida Console, Lucida, 'Courier New', Courier, monospace; color: white; font-weight: normal; font-style: normal;"><div style="font-family: Monaco, Lucida Console, Lucida, 'Courier New', Courier, monospace; font-weight: normal; ">addChild<span style="color: #FFFFFF;">&#40;</span>mySWF<span style="color: #FFFFFF;">&#41;</span>;</div></li></ol></pre>
<p></code></p>
<p>Fine and dandy - but you'll want to get into the guts of the loaded content. To do that you need to wait for the loading to finish and then target the <em>.mc</em> property. Here's how:</p>
<p><code></p>
<pre class="actionscript"><ol start="0"><li style="font-family: Monaco, Lucida Console, Lucida, 'Courier New', Courier, monospace; color: white; font-weight: normal; font-style: normal;"><div style="font-family: Monaco, Lucida Console, Lucida, 'Courier New', Courier, monospace; font-weight: normal; "><span style="color: #F7De2D;">import</span> com.<span style="color: #71A1CE;">calypso88</span>.<span style="color: #71A1CE;">SWF</span>;</div></li><li style="font-family: Monaco, Lucida Console, Lucida, 'Courier New', Courier, monospace; color: white; font-weight: normal; font-style: normal;"><div style="font-family: Monaco, Lucida Console, Lucida, 'Courier New', Courier, monospace; font-weight: normal; ">&nbsp;</div></li><li style="font-family: Monaco, Lucida Console, Lucida, 'Courier New', Courier, monospace; color: white; font-weight: normal; font-style: normal;"><div style="font-family: Monaco, Lucida Console, Lucida, 'Courier New', Courier, monospace; font-weight: normal; "><span style="color: #F7De2D;">var</span> mySWF:SWF = <span style="color: #FFFFFF;">new</span> SWF<span style="color: #FFFFFF;">&#40;</span><span style="color: #5FCE3C;">'http://calypso88.com/tester.swf'</span>, <span style="color: #FFFFFF;">false</span><span style="color: #FFFFFF;">&#41;</span>;</div></li><li style="font-family: Monaco, Lucida Console, Lucida, 'Courier New', Courier, monospace; color: white; font-weight: normal; font-style: normal;"><div style="font-family: Monaco, Lucida Console, Lucida, 'Courier New', Courier, monospace; font-weight: normal; ">addChild<span style="color: #FFFFFF;">&#40;</span>mySWF<span style="color: #FFFFFF;">&#41;</span>;</div></li><li style="font-family: Monaco, Lucida Console, Lucida, 'Courier New', Courier, monospace; color: white; font-weight: normal; font-style: normal;"><div style="font-family: Monaco, Lucida Console, Lucida, 'Courier New', Courier, monospace; font-weight: normal; ">&nbsp;</div></li><li style="font-family: Monaco, Lucida Console, Lucida, 'Courier New', Courier, monospace; color: white; font-weight: normal; font-style: normal;"><div style="font-family: Monaco, Lucida Console, Lucida, 'Courier New', Courier, monospace; font-weight: normal; "><span style="color: #666666;">//  trace out the loading %</span></div></li><li style="font-family: Monaco, Lucida Console, Lucida, 'Courier New', Courier, monospace; color: white; font-weight: normal; font-style: normal;"><div style="font-family: Monaco, Lucida Console, Lucida, 'Courier New', Courier, monospace; font-weight: normal; ">mySWF.<span style="color: #71A1CE;">addEventListener</span><span style="color: #FFFFFF;">&#40;</span>ProgressEvent.<span style="color: #71A1CE;">PROGRESS</span>, onProg<span style="color: #FFFFFF;">&#41;</span>;</div></li><li style="font-family: Monaco, Lucida Console, Lucida, 'Courier New', Courier, monospace; color: white; font-weight: normal; font-style: normal;"><div style="font-family: Monaco, Lucida Console, Lucida, 'Courier New', Courier, monospace; font-weight: normal; ">&nbsp;</div></li><li style="font-family: Monaco, Lucida Console, Lucida, 'Courier New', Courier, monospace; color: white; font-weight: normal; font-style: normal;"><div style="font-family: Monaco, Lucida Console, Lucida, 'Courier New', Courier, monospace; font-weight: normal; "><span style="color: #FF5E00;"><span style="color: #FFFF00;">function</span> onProg</span><span style="color: #FFFFFF;">&#40;</span><span style="color: #FFFFFF;">e</span>:ProgressEvent<span style="color: #FFFFFF;">&#41;</span>:<span style="color: #FFFFFF;">void</span><span style="color: #FFFFFF;">&#123;</span></div></li><li style="font-family: Monaco, Lucida Console, Lucida, 'Courier New', Courier, monospace; color: white; font-weight: normal; font-style: normal;"><div style="font-family: Monaco, Lucida Console, Lucida, 'Courier New', Courier, monospace; font-weight: normal; ">	<span style="color: #FFFFFF;">trace</span><span style="color: #FFFFFF;">&#40;</span><span style="color: #FFFFFF;">e</span>.<span style="color: #FFFFFF;">target</span>.<span style="color: #71A1CE;">percent</span><span style="color: #FFFFFF;">&#41;</span>;</div></li><li style="font-family: Monaco, Lucida Console, Lucida, 'Courier New', Courier, monospace; color: white; font-weight: normal; font-style: normal;"><div style="font-family: Monaco, Lucida Console, Lucida, 'Courier New', Courier, monospace; font-weight: normal; "><span style="color: #FFFFFF;">&#125;</span></div></li><li style="font-family: Monaco, Lucida Console, Lucida, 'Courier New', Courier, monospace; color: white; font-weight: normal; font-style: normal;"><div style="font-family: Monaco, Lucida Console, Lucida, 'Courier New', Courier, monospace; font-weight: normal; ">&nbsp;</div></li><li style="font-family: Monaco, Lucida Console, Lucida, 'Courier New', Courier, monospace; color: white; font-weight: normal; font-style: normal;"><div style="font-family: Monaco, Lucida Console, Lucida, 'Courier New', Courier, monospace; font-weight: normal; "><span style="color: #666666;">//  when loaded, customize the guts</span></div></li><li style="font-family: Monaco, Lucida Console, Lucida, 'Courier New', Courier, monospace; color: white; font-weight: normal; font-style: normal;"><div style="font-family: Monaco, Lucida Console, Lucida, 'Courier New', Courier, monospace; font-weight: normal; ">mySWF.<span style="color: #71A1CE;">addEventListener</span><span style="color: #FFFFFF;">&#40;</span>Event.<span style="color: #71A1CE;">COMPLETE</span>, onLoaded<span style="color: #FFFFFF;">&#41;</span>;</div></li><li style="font-family: Monaco, Lucida Console, Lucida, 'Courier New', Courier, monospace; color: white; font-weight: normal; font-style: normal;"><div style="font-family: Monaco, Lucida Console, Lucida, 'Courier New', Courier, monospace; font-weight: normal; ">&nbsp;</div></li><li style="font-family: Monaco, Lucida Console, Lucida, 'Courier New', Courier, monospace; color: white; font-weight: normal; font-style: normal;"><div style="font-family: Monaco, Lucida Console, Lucida, 'Courier New', Courier, monospace; font-weight: normal; "><span style="color: #FF5E00;"><span style="color: #FFFF00;">function</span> onLoaded</span><span style="color: #FFFFFF;">&#40;</span><span style="color: #FFFFFF;">e</span>:Event<span style="color: #FFFFFF;">&#41;</span>:<span style="color: #FFFFFF;">void</span><span style="color: #FFFFFF;">&#123;</span></div></li><li style="font-family: Monaco, Lucida Console, Lucida, 'Courier New', Courier, monospace; color: white; font-weight: normal; font-style: normal;"><div style="font-family: Monaco, Lucida Console, Lucida, 'Courier New', Courier, monospace; font-weight: normal; ">	<span style="color: #FFFFFF;">trace</span><span style="color: #FFFFFF;">&#40;</span><span style="color: #5FCE3C;">'complete'</span><span style="color: #FFFFFF;">&#41;</span>;</div></li><li style="font-family: Monaco, Lucida Console, Lucida, 'Courier New', Courier, monospace; color: white; font-weight: normal; font-style: normal;"><div style="font-family: Monaco, Lucida Console, Lucida, 'Courier New', Courier, monospace; font-weight: normal; ">	mySWF.<span style="color: #71A1CE;">mc</span>.<span style="color: #71A1CE;">spinner</span>.<span style="color: #FFFFFF;">stop</span><span style="color: #FFFFFF;">&#40;</span><span style="color: #FFFFFF;">&#41;</span>;</div></li><li style="font-family: Monaco, Lucida Console, Lucida, 'Courier New', Courier, monospace; color: white; font-weight: normal; font-style: normal;"><div style="font-family: Monaco, Lucida Console, Lucida, 'Courier New', Courier, monospace; font-weight: normal; ">	mySWF.<span style="color: #71A1CE;">mc</span>.<span style="color: #71A1CE;">txt</span>.<span style="color: #FFFFFF;">text</span> = <span style="color: #5FCE3C;">'Hello from the outside!'</span>;</div></li><li style="font-family: Monaco, Lucida Console, Lucida, 'Courier New', Courier, monospace; color: white; font-weight: normal; font-style: normal;"><div style="font-family: Monaco, Lucida Console, Lucida, 'Courier New', Courier, monospace; font-weight: normal; ">	mySWF.<span style="color: #71A1CE;">mc</span>.<span style="color: #FFFFFF;">gotoAndStop</span><span style="color: #FFFFFF;">&#40;</span><span style="color: #FFFFFF;">2</span><span style="color: #FFFFFF;">&#41;</span>;</div></li><li style="font-family: Monaco, Lucida Console, Lucida, 'Courier New', Courier, monospace; color: white; font-weight: normal; font-style: normal;"><div style="font-family: Monaco, Lucida Console, Lucida, 'Courier New', Courier, monospace; font-weight: normal; "><span style="color: #FFFFFF;">&#125;</span></div></li><li style="font-family: Monaco, Lucida Console, Lucida, 'Courier New', Courier, monospace; color: white; font-weight: normal; font-style: normal;"><div style="font-family: Monaco, Lucida Console, Lucida, 'Courier New', Courier, monospace; font-weight: normal; ">&nbsp;</div></li><li style="font-family: Monaco, Lucida Console, Lucida, 'Courier New', Courier, monospace; color: white; font-weight: normal; font-style: normal;"><div style="font-family: Monaco, Lucida Console, Lucida, 'Courier New', Courier, monospace; font-weight: normal; "><span style="color: #666666;">//  start loading</span></div></li><li style="font-family: Monaco, Lucida Console, Lucida, 'Courier New', Courier, monospace; color: white; font-weight: normal; font-style: normal;"><div style="font-family: Monaco, Lucida Console, Lucida, 'Courier New', Courier, monospace; font-weight: normal; ">mySWF.<span style="color: #71A1CE;">go</span><span style="color: #FFFFFF;">&#40;</span><span style="color: #FFFFFF;">&#41;</span>;</div></li></ol></pre>
<p></code></p>
<p>To stay consistent with the Pic class, I included a clone function here too, but again, the way the loaders work, this requires some trickery so you can't just clone the swf and start manipulating, you'll have to wait for it to get initialized:</p>
<p><code></p>
<pre class="actionscript"><ol start="0"><li style="font-family: Monaco, Lucida Console, Lucida, 'Courier New', Courier, monospace; color: white; font-weight: normal; font-style: normal;"><div style="font-family: Monaco, Lucida Console, Lucida, 'Courier New', Courier, monospace; font-weight: normal; "><span style="color: #F7De2D;">import</span> com.<span style="color: #71A1CE;">calypso88</span>.<span style="color: #71A1CE;">SWF</span>;</div></li><li style="font-family: Monaco, Lucida Console, Lucida, 'Courier New', Courier, monospace; color: white; font-weight: normal; font-style: normal;"><div style="font-family: Monaco, Lucida Console, Lucida, 'Courier New', Courier, monospace; font-weight: normal; ">&nbsp;</div></li><li style="font-family: Monaco, Lucida Console, Lucida, 'Courier New', Courier, monospace; color: white; font-weight: normal; font-style: normal;"><div style="font-family: Monaco, Lucida Console, Lucida, 'Courier New', Courier, monospace; font-weight: normal; "><span style="color: #F7De2D;">var</span> mySWF:SWF = <span style="color: #FFFFFF;">new</span> SWF<span style="color: #FFFFFF;">&#40;</span><span style="color: #5FCE3C;">'http://calypso88.com/tester.swf'</span>, <span style="color: #FFFFFF;">false</span><span style="color: #FFFFFF;">&#41;</span>;</div></li><li style="font-family: Monaco, Lucida Console, Lucida, 'Courier New', Courier, monospace; color: white; font-weight: normal; font-style: normal;"><div style="font-family: Monaco, Lucida Console, Lucida, 'Courier New', Courier, monospace; font-weight: normal; ">&nbsp;</div></li><li style="font-family: Monaco, Lucida Console, Lucida, 'Courier New', Courier, monospace; color: white; font-weight: normal; font-style: normal;"><div style="font-family: Monaco, Lucida Console, Lucida, 'Courier New', Courier, monospace; font-weight: normal; ">mySWF.<span style="color: #71A1CE;">addEventListener</span><span style="color: #FFFFFF;">&#40;</span>SWF.<span style="color: #FFFFFF;">LOADED</span>, onLoaded<span style="color: #FFFFFF;">&#41;</span>;</div></li><li style="font-family: Monaco, Lucida Console, Lucida, 'Courier New', Courier, monospace; color: white; font-weight: normal; font-style: normal;"><div style="font-family: Monaco, Lucida Console, Lucida, 'Courier New', Courier, monospace; font-weight: normal; ">&nbsp;</div></li><li style="font-family: Monaco, Lucida Console, Lucida, 'Courier New', Courier, monospace; color: white; font-weight: normal; font-style: normal;"><div style="font-family: Monaco, Lucida Console, Lucida, 'Courier New', Courier, monospace; font-weight: normal; "><span style="color: #FF5E00;"><span style="color: #FFFF00;">function</span> onLoaded</span><span style="color: #FFFFFF;">&#40;</span><span style="color: #FFFFFF;">e</span>:Event<span style="color: #FFFFFF;">&#41;</span>:<span style="color: #FFFFFF;">void</span><span style="color: #FFFFFF;">&#123;</span></div></li><li style="font-family: Monaco, Lucida Console, Lucida, 'Courier New', Courier, monospace; color: white; font-weight: normal; font-style: normal;"><div style="font-family: Monaco, Lucida Console, Lucida, 'Courier New', Courier, monospace; font-weight: normal; ">	addChild<span style="color: #FFFFFF;">&#40;</span>mySWF<span style="color: #FFFFFF;">&#41;</span>;</div></li><li style="font-family: Monaco, Lucida Console, Lucida, 'Courier New', Courier, monospace; color: white; font-weight: normal; font-style: normal;"><div style="font-family: Monaco, Lucida Console, Lucida, 'Courier New', Courier, monospace; font-weight: normal; ">	<span style="color: #F7De2D;">var</span> myOtherSWF:<span style="color: #FFFFFF;">MovieClip</span> = mySWF.<span style="color: #71A1CE;">cloneMC</span><span style="color: #FFFFFF;">&#40;</span><span style="color: #FFFFFF;">false</span><span style="color: #FFFFFF;">&#41;</span>;</div></li><li style="font-family: Monaco, Lucida Console, Lucida, 'Courier New', Courier, monospace; color: white; font-weight: normal; font-style: normal;"><div style="font-family: Monaco, Lucida Console, Lucida, 'Courier New', Courier, monospace; font-weight: normal; ">	myOtherSWF.<span style="color: #71A1CE;">y</span> = <span style="color: #FFFFFF;">10</span> + mySWF.<span style="color: #FFFFFF;">height</span>;</div></li><li style="font-family: Monaco, Lucida Console, Lucida, 'Courier New', Courier, monospace; color: white; font-weight: normal; font-style: normal;"><div style="font-family: Monaco, Lucida Console, Lucida, 'Courier New', Courier, monospace; font-weight: normal; ">	addChild<span style="color: #FFFFFF;">&#40;</span>myOtherSWF<span style="color: #FFFFFF;">&#41;</span>;</div></li><li style="font-family: Monaco, Lucida Console, Lucida, 'Courier New', Courier, monospace; color: white; font-weight: normal; font-style: normal;"><div style="font-family: Monaco, Lucida Console, Lucida, 'Courier New', Courier, monospace; font-weight: normal; ">&nbsp;</div></li><li style="font-family: Monaco, Lucida Console, Lucida, 'Courier New', Courier, monospace; color: white; font-weight: normal; font-style: normal;"><div style="font-family: Monaco, Lucida Console, Lucida, 'Courier New', Courier, monospace; font-weight: normal; ">	myOtherSWF.<span style="color: #71A1CE;">addEventListener</span><span style="color: #FFFFFF;">&#40;</span>SWF.<span style="color: #71A1CE;">CLONE_COMPLETE</span>, <span style="color: #FFFF00;">function</span><span style="color: #FFFFFF;">&#40;</span><span style="color: #FFFFFF;">e</span>:Event<span style="color: #FFFFFF;">&#41;</span>:<span style="color: #FFFFFF;">void</span><span style="color: #FFFFFF;">&#123;</span></div></li><li style="font-family: Monaco, Lucida Console, Lucida, 'Courier New', Courier, monospace; color: white; font-weight: normal; font-style: normal;"><div style="font-family: Monaco, Lucida Console, Lucida, 'Courier New', Courier, monospace; font-weight: normal; ">		<span style="color: #666666;">//  the clone uses the same .mc wrapper as the original</span></div></li><li style="font-family: Monaco, Lucida Console, Lucida, 'Courier New', Courier, monospace; color: white; font-weight: normal; font-style: normal;"><div style="font-family: Monaco, Lucida Console, Lucida, 'Courier New', Courier, monospace; font-weight: normal; ">		myOtherSWF.<span style="color: #71A1CE;">mc</span>.<span style="color: #71A1CE;">txt</span>.<span style="color: #FFFFFF;">text</span> = <span style="color: #5FCE3C;">'This swf is a clone!'</span>;</div></li><li style="font-family: Monaco, Lucida Console, Lucida, 'Courier New', Courier, monospace; color: white; font-weight: normal; font-style: normal;"><div style="font-family: Monaco, Lucida Console, Lucida, 'Courier New', Courier, monospace; font-weight: normal; ">		<span style="color: #FFFFFF;">e</span>.<span style="color: #FFFFFF;">target</span>.<span style="color: #71A1CE;">mc</span>.<span style="color: #71A1CE;">spinner</span>.<span style="color: #FFFFFF;">stop</span><span style="color: #FFFFFF;">&#40;</span><span style="color: #FFFFFF;">&#41;</span>;</div></li><li style="font-family: Monaco, Lucida Console, Lucida, 'Courier New', Courier, monospace; color: white; font-weight: normal; font-style: normal;"><div style="font-family: Monaco, Lucida Console, Lucida, 'Courier New', Courier, monospace; font-weight: normal; ">	<span style="color: #FFFFFF;">&#125;</span><span style="color: #FFFFFF;">&#41;</span>;</div></li><li style="font-family: Monaco, Lucida Console, Lucida, 'Courier New', Courier, monospace; color: white; font-weight: normal; font-style: normal;"><div style="font-family: Monaco, Lucida Console, Lucida, 'Courier New', Courier, monospace; font-weight: normal; "><span style="color: #FFFFFF;">&#125;</span></div></li><li style="font-family: Monaco, Lucida Console, Lucida, 'Courier New', Courier, monospace; color: white; font-weight: normal; font-style: normal;"><div style="font-family: Monaco, Lucida Console, Lucida, 'Courier New', Courier, monospace; font-weight: normal; ">&nbsp;</div></li><li style="font-family: Monaco, Lucida Console, Lucida, 'Courier New', Courier, monospace; color: white; font-weight: normal; font-style: normal;"><div style="font-family: Monaco, Lucida Console, Lucida, 'Courier New', Courier, monospace; font-weight: normal; ">mySWF.<span style="color: #71A1CE;">go</span><span style="color: #FFFFFF;">&#40;</span><span style="color: #FFFFFF;">&#41;</span>;</div></li></ol></pre>
<p></code></p>
<blockquote><p><span style="background:#800; display:block; color:#EEE; padding: 1px 10px 10px 10px"><br />
<strong>SECURITY WARNING</strong>: This class uses the URLLoader class instead of the more traditional Loader class. For most users this won't be a problem but if you are building an application that allows the loading of swfs from outside users, this class will open your swf to the possibility of cross-site script-injection. Use this at your own risk!<br />
</span></p></blockquote>
<p>And just because this post isn't long enough, here are a few shots out of the <a href="http://www.calypso88.com/?page_id=107">Documentation Cannon</a>!</p>
]]></content:encoded>
			<wfw:commentRss>http://www.calypso88.com/?feed=rss2&amp;p=41</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Eureka!</title>
		<link>http://www.calypso88.com/?p=36</link>
		<comments>http://www.calypso88.com/?p=36#comments</comments>
		<pubDate>Fri, 05 Sep 2008 05:55:05 +0000</pubDate>
		<dc:creator>Rob</dc:creator>
				<category><![CDATA[Pathfinding]]></category>

		<guid isPermaLink="false">http://www.calypso88.com/?p=36</guid>
		<description><![CDATA[This stunning video turned up in my news feeds today and it got me thinking: Lightning, you cheeky bastard! Is that naturally occurring pathfinding or are you just happy to see me!? As soon as I saw the beginning of that video I was reminded of my first maze test, and the unintended (yet quite [...]]]></description>
			<content:encoded><![CDATA[<p>This stunning video turned up in my news feeds today and it got me thinking:</p>
<p><object classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" width="460" height="345" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,40,0"><param name="allowscriptaccess" value="always" /><param name="src" value="http://vimeo.com/moogaloop.swf?clip_id=1491917&amp;server=vimeo.com&amp;show_title=0&amp;show_byline=0&amp;show_portrait=0&amp;color=ff9933&amp;fullscreen=1" /><embed type="application/x-shockwave-flash" width="460" height="345" src="http://vimeo.com/moogaloop.swf?clip_id=1491917&amp;server=vimeo.com&amp;show_title=0&amp;show_byline=0&amp;show_portrait=0&amp;color=ff9933&amp;fullscreen=1" allowscriptaccess="always"></embed></object></p>
<p>Lightning, you cheeky bastard! Is that naturally occurring pathfinding or are you just happy to see me!?</p>
<p>As soon as I saw the beginning of that video I was reminded of <a href="http://www.calypso88.com/?p=27" target="_blank">my first maze test</a>, and the unintended (yet quite interesting to watch) motion as the algorithm chewed through the possible paths. What's more, my latest maze experiment was built around the concept of tracing the path-of-least-resistance through a bitmap – precisely how the lightning is searching through the ionosphere for a positive electrical ground!</p>
<p>It took me about 5 minutes to overwrite the old maze with some render clouds and throw a little glow filter at the final path - and the result already looks pretty good. This is definitely a rough pass (there's a pixel-trap somewhere that's hanging the algorithm so I just jammed it all into a try/catch and ignored the timeout error), and there is a lot of weird clumping that I need to iron out, but the core concept is there.</p>
<p>Keep an eye out – I'll try and put up an animated (and less buggy) version sometime this weekend.</p>
<div class="mceTemp">
<dl id="attachment_37" class="wp-caption alignnone" style="width: 339px;">
<dt class="wp-caption-dt" style="text-align: center;"><img class="size-full wp-image-37" title="lightning" src="http://www.calypso88.com/wp-content/uploads/2008/09/lightning.jpg" alt="Lightning in AS3" width="329" height="438" /></dt>
</dl>
</div>
]]></content:encoded>
			<wfw:commentRss>http://www.calypso88.com/?feed=rss2&amp;p=36</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Pic: Automatic image loader</title>
		<link>http://www.calypso88.com/?p=34</link>
		<comments>http://www.calypso88.com/?p=34#comments</comments>
		<pubDate>Fri, 15 Aug 2008 19:08:38 +0000</pubDate>
		<dc:creator>Rob</dc:creator>
				<category><![CDATA[AS3 Utility Classes]]></category>
		<category><![CDATA[Actionscript 3.0]]></category>

		<guid isPermaLink="false">http://www.calypso88.com/?p=34</guid>
		<description><![CDATA[Pic: [AS3] [Zip] [doc] Updated: Version 1.1.0 Here's a little throwaway class that I've been using for a while. For a skimpy 1200 1500 bytes, this little guy handles image loading and smoothing, and it will even spin off duplicate Bitmaps for thumbnails. w00t! Simple implementation: import com.calypso88.Pic;&#160;var p:Pic = new Pic&#40;'http://make-some-noise.info/badges/88x31.gif'&#41;;addChild&#40;p&#41;; And some advanced [...]]]></description>
			<content:encoded><![CDATA[<div style="width: 130px; padding: 6px; display: inline; float: right; text-align: center;"><a href="http://calypso88.com/wp-content/uploads/2008/08/Pic.zip"><img src="http://calypso88.com/wp-content/themes/dl.jpg" alt="Download this class" width="130" height="30" /></a></p>
<p>Pic: [<a href="http://www.calypso88.com/?page_id=82">AS3</a>] [<a href="http://calypso88.com/wp-content/uploads/2008/08/Pic.zip">Zip</a>] [<a href="http://www.calypso88.com/?page_id=94">doc</a>]</p>
<p>Updated: Version 1.1.0</p></div>
<p>Here's a little throwaway class that I've been using for a while. For a skimpy <del>1200</del> 1500 bytes, this little guy handles image loading and smoothing, and it will even spin off duplicate Bitmaps for thumbnails. w00t!</p>
<p>Simple implementation:</p>
<p><code></p>
<pre class="actionscript"><ol start="0"><li style="font-family: Monaco, Lucida Console, Lucida, 'Courier New', Courier, monospace; color: white; font-weight: normal; font-style: normal;"><div style="font-family: Monaco, Lucida Console, Lucida, 'Courier New', Courier, monospace; font-weight: normal; "><span style="color: #F7De2D;">import</span> com.<span style="color: #71A1CE;">calypso88</span>.<span style="color: #71A1CE;">Pic</span>;</div></li><li style="font-family: Monaco, Lucida Console, Lucida, 'Courier New', Courier, monospace; color: white; font-weight: normal; font-style: normal;"><div style="font-family: Monaco, Lucida Console, Lucida, 'Courier New', Courier, monospace; font-weight: normal; ">&nbsp;</div></li><li style="font-family: Monaco, Lucida Console, Lucida, 'Courier New', Courier, monospace; color: white; font-weight: normal; font-style: normal;"><div style="font-family: Monaco, Lucida Console, Lucida, 'Courier New', Courier, monospace; font-weight: normal; "><span style="color: #F7De2D;">var</span> p:Pic = <span style="color: #FFFFFF;">new</span> Pic<span style="color: #FFFFFF;">&#40;</span><span style="color: #5FCE3C;">'http://make-some-noise.info/badges/88x31.gif'</span><span style="color: #FFFFFF;">&#41;</span>;</div></li><li style="font-family: Monaco, Lucida Console, Lucida, 'Courier New', Courier, monospace; color: white; font-weight: normal; font-style: normal;"><div style="font-family: Monaco, Lucida Console, Lucida, 'Courier New', Courier, monospace; font-weight: normal; ">addChild<span style="color: #FFFFFF;">&#40;</span>p<span style="color: #FFFFFF;">&#41;</span>;</div></li></ol></pre>
<p></code></p>
<p>And some advanced features:</p>
<p><code> </code></p>
<p><code></p>
<pre class="actionscript"><ol start="0"><li style="font-family: Monaco, Lucida Console, Lucida, 'Courier New', Courier, monospace; color: white; font-weight: normal; font-style: normal;"><div style="font-family: Monaco, Lucida Console, Lucida, 'Courier New', Courier, monospace; font-weight: normal; "><span style="color: #F7De2D;">import</span> com.<span style="color: #71A1CE;">calypso88</span>.<span style="color: #71A1CE;">Pic</span>;</div></li><li style="font-family: Monaco, Lucida Console, Lucida, 'Courier New', Courier, monospace; color: white; font-weight: normal; font-style: normal;"><div style="font-family: Monaco, Lucida Console, Lucida, 'Courier New', Courier, monospace; font-weight: normal; ">&nbsp;</div></li><li style="font-family: Monaco, Lucida Console, Lucida, 'Courier New', Courier, monospace; color: white; font-weight: normal; font-style: normal;"><div style="font-family: Monaco, Lucida Console, Lucida, 'Courier New', Courier, monospace; font-weight: normal; "><span style="color: #F7De2D;">var</span> p:Pic = <span style="color: #FFFFFF;">new</span> Pic<span style="color: #FFFFFF;">&#40;</span><span style="color: #5FCE3C;">'http://make-some-noise.info/badges/88x31.gif'</span>, <span style="color: #FFFFFF;">true</span>, <span style="color: #FFFFFF;">false</span><span style="color: #FFFFFF;">&#41;</span>;</div></li><li style="font-family: Monaco, Lucida Console, Lucida, 'Courier New', Courier, monospace; color: white; font-weight: normal; font-style: normal;"><div style="font-family: Monaco, Lucida Console, Lucida, 'Courier New', Courier, monospace; font-weight: normal; ">addChild<span style="color: #FFFFFF;">&#40;</span>p<span style="color: #FFFFFF;">&#41;</span>;</div></li><li style="font-family: Monaco, Lucida Console, Lucida, 'Courier New', Courier, monospace; color: white; font-weight: normal; font-style: normal;"><div style="font-family: Monaco, Lucida Console, Lucida, 'Courier New', Courier, monospace; font-weight: normal; ">p.<span style="color: #71A1CE;">x</span> = p.<span style="color: #71A1CE;">y</span> = <span style="color: #FFFFFF;">40</span>;</div></li><li style="font-family: Monaco, Lucida Console, Lucida, 'Courier New', Courier, monospace; color: white; font-weight: normal; font-style: normal;"><div style="font-family: Monaco, Lucida Console, Lucida, 'Courier New', Courier, monospace; font-weight: normal; ">p.<span style="color: #71A1CE;">rotation</span> = <span style="color: #FFFFFF;">10</span>;</div></li><li style="font-family: Monaco, Lucida Console, Lucida, 'Courier New', Courier, monospace; color: white; font-weight: normal; font-style: normal;"><div style="font-family: Monaco, Lucida Console, Lucida, 'Courier New', Courier, monospace; font-weight: normal; ">&nbsp;</div></li><li style="font-family: Monaco, Lucida Console, Lucida, 'Courier New', Courier, monospace; color: white; font-weight: normal; font-style: normal;"><div style="font-family: Monaco, Lucida Console, Lucida, 'Courier New', Courier, monospace; font-weight: normal; ">p.<span style="color: #71A1CE;">addEventListener</span><span style="color: #FFFFFF;">&#40;</span>Pic.<span style="color: #FFFFFF;">LOADED</span>, <span style="color: #FFFF00;">function</span><span style="color: #FFFFFF;">&#40;</span><span style="color: #FFFFFF;">e</span>:Event<span style="color: #FFFFFF;">&#41;</span>:<span style="color: #FFFFFF;">void</span><span style="color: #FFFFFF;">&#123;</span></div></li><li style="font-family: Monaco, Lucida Console, Lucida, 'Courier New', Courier, monospace; color: white; font-weight: normal; font-style: normal;"><div style="font-family: Monaco, Lucida Console, Lucida, 'Courier New', Courier, monospace; font-weight: normal; ">	<span style="color: #666666;">//  create thumbnail</span></div></li><li style="font-family: Monaco, Lucida Console, Lucida, 'Courier New', Courier, monospace; color: white; font-weight: normal; font-style: normal;"><div style="font-family: Monaco, Lucida Console, Lucida, 'Courier New', Courier, monospace; font-weight: normal; ">	<span style="color: #F7De2D;">var</span> thumb:Bitmap = p.<span style="color: #71A1CE;">cloneBitmap</span><span style="color: #FFFFFF;">&#40;</span><span style="color: #FFFFFF;">false</span><span style="color: #FFFFFF;">&#41;</span>;</div></li><li style="font-family: Monaco, Lucida Console, Lucida, 'Courier New', Courier, monospace; color: white; font-weight: normal; font-style: normal;"><div style="font-family: Monaco, Lucida Console, Lucida, 'Courier New', Courier, monospace; font-weight: normal; ">	thumb.<span style="color: #71A1CE;">scaleX</span> = thumb.<span style="color: #71A1CE;">scaleY</span> = .<span style="color: #FFFFFF;">5</span>;</div></li><li style="font-family: Monaco, Lucida Console, Lucida, 'Courier New', Courier, monospace; color: white; font-weight: normal; font-style: normal;"><div style="font-family: Monaco, Lucida Console, Lucida, 'Courier New', Courier, monospace; font-weight: normal; ">	thumb.<span style="color: #71A1CE;">rotation</span> = <span style="color: #FFFFFF;">10</span>;</div></li><li style="font-family: Monaco, Lucida Console, Lucida, 'Courier New', Courier, monospace; color: white; font-weight: normal; font-style: normal;"><div style="font-family: Monaco, Lucida Console, Lucida, 'Courier New', Courier, monospace; font-weight: normal; ">	addChild<span style="color: #FFFFFF;">&#40;</span>thumb<span style="color: #FFFFFF;">&#41;</span>;</div></li><li style="font-family: Monaco, Lucida Console, Lucida, 'Courier New', Courier, monospace; color: white; font-weight: normal; font-style: normal;"><div style="font-family: Monaco, Lucida Console, Lucida, 'Courier New', Courier, monospace; font-weight: normal; ">&nbsp;</div></li><li style="font-family: Monaco, Lucida Console, Lucida, 'Courier New', Courier, monospace; color: white; font-weight: normal; font-style: normal;"><div style="font-family: Monaco, Lucida Console, Lucida, 'Courier New', Courier, monospace; font-weight: normal; ">	<span style="color: #666666;">//  change the original</span></div></li><li style="font-family: Monaco, Lucida Console, Lucida, 'Courier New', Courier, monospace; color: white; font-weight: normal; font-style: normal;"><div style="font-family: Monaco, Lucida Console, Lucida, 'Courier New', Courier, monospace; font-weight: normal; ">	p.<span style="color: #71A1CE;">bitmapData</span>.<span style="color: #71A1CE;">floodFill</span><span style="color: #FFFFFF;">&#40;</span><span style="color: #FFFFFF;">10</span>, <span style="color: #FFFFFF;">10</span>, 0xFF6600<span style="color: #FFFFFF;">&#41;</span>;</div></li><li style="font-family: Monaco, Lucida Console, Lucida, 'Courier New', Courier, monospace; color: white; font-weight: normal; font-style: normal;"><div style="font-family: Monaco, Lucida Console, Lucida, 'Courier New', Courier, monospace; font-weight: normal; ">	p.<span style="color: #71A1CE;">bitmap</span>.<span style="color: #FFFFFF;">smoothing</span> = <span style="color: #FFFFFF;">false</span>;</div></li><li style="font-family: Monaco, Lucida Console, Lucida, 'Courier New', Courier, monospace; color: white; font-weight: normal; font-style: normal;"><div style="font-family: Monaco, Lucida Console, Lucida, 'Courier New', Courier, monospace; font-weight: normal; "><span style="color: #FFFFFF;">&#125;</span><span style="color: #FFFFFF;">&#41;</span>;</div></li><li style="font-family: Monaco, Lucida Console, Lucida, 'Courier New', Courier, monospace; color: white; font-weight: normal; font-style: normal;"><div style="font-family: Monaco, Lucida Console, Lucida, 'Courier New', Courier, monospace; font-weight: normal; ">&nbsp;</div></li><li style="font-family: Monaco, Lucida Console, Lucida, 'Courier New', Courier, monospace; color: white; font-weight: normal; font-style: normal;"><div style="font-family: Monaco, Lucida Console, Lucida, 'Courier New', Courier, monospace; font-weight: normal; ">p.<span style="color: #71A1CE;">go</span><span style="color: #FFFFFF;">&#40;</span><span style="color: #FFFFFF;">&#41;</span>;</div></li></ol></pre>
<p></code></p>
<p>And of course – it's <a href="http://www.calypso88.com/?page_id=94">Free-Documentation-Friday</a>!</p>
<p><span style="background:#EEE; display:block; color:#222; padding: 10px 10px 10px 10px; margin:10px 0px 0px 0px; border: 1px solid #CCD"><strong>UPDATE</strong>: I've posted a companion class for loading SWF content. It's not quite as seamless as I want yet, but it's still a lot faster and easier than writing out loaders all day. <a href="http://www.calypso88.com/?p=41">Check it out</a>.</span></p>
]]></content:encoded>
			<wfw:commentRss>http://www.calypso88.com/?feed=rss2&amp;p=34</wfw:commentRss>
		<slash:comments>9</slash:comments>
		</item>
		<item>
		<title>onChange &amp; The Local Accessors</title>
		<link>http://www.calypso88.com/?p=33</link>
		<comments>http://www.calypso88.com/?p=33#comments</comments>
		<pubDate>Fri, 08 Aug 2008 03:42:25 +0000</pubDate>
		<dc:creator>Rob</dc:creator>
				<category><![CDATA[Actionscript 3.0]]></category>

		<guid isPermaLink="false">http://www.calypso88.com/?p=33</guid>
		<description><![CDATA[I like that title! if I was more musical I'd start a punk band called The Local Accessors. Old Man Internet seems to be endlessly moaning for an onChange event to monitor variables. When I learned the following technique I was shocked by how simple and clever it is, but somehow it’s still fairly obscure. [...]]]></description>
			<content:encoded><![CDATA[<p><em>I like that title! if I was more musical I'd start a punk band called The Local Accessors.</em></p>
<p>Old Man Internet seems to be endlessly moaning for an onChange event to monitor variables. When I learned the following technique I was shocked by how simple and clever it is, but somehow it’s still fairly obscure. The trick is calling your own accessors from within a class. Here’s how:</p>
<p><code> </code></p>
<p><code></p>
<pre class="actionscript"><ol start="0"><li style="font-family: Monaco, Lucida Console, Lucida, 'Courier New', Courier, monospace; color: white; font-weight: normal; font-style: normal;"><div style="font-family: Monaco, Lucida Console, Lucida, 'Courier New', Courier, monospace; font-weight: normal; "><span style="color: #666666;">//--------------------------------------</span></div></li><li style="font-family: Monaco, Lucida Console, Lucida, 'Courier New', Courier, monospace; color: white; font-weight: normal; font-style: normal;"><div style="font-family: Monaco, Lucida Console, Lucida, 'Courier New', Courier, monospace; font-weight: normal; "><span style="color: #666666;">//  PRIVATE VARIABLES</span></div></li><li style="font-family: Monaco, Lucida Console, Lucida, 'Courier New', Courier, monospace; color: white; font-weight: normal; font-style: normal;"><div style="font-family: Monaco, Lucida Console, Lucida, 'Courier New', Courier, monospace; font-weight: normal; "><span style="color: #666666;">//--------------------------------------</span></div></li><li style="font-family: Monaco, Lucida Console, Lucida, 'Courier New', Courier, monospace; color: white; font-weight: normal; font-style: normal;"><div style="font-family: Monaco, Lucida Console, Lucida, 'Courier New', Courier, monospace; font-weight: normal; ">&nbsp;</div></li><li style="font-family: Monaco, Lucida Console, Lucida, 'Courier New', Courier, monospace; color: white; font-weight: normal; font-style: normal;"><div style="font-family: Monaco, Lucida Console, Lucida, 'Courier New', Courier, monospace; font-weight: normal; ">	<span style="color: #F7De2D;">private</span> <span style="color: #F7De2D;">var</span> _speed:<span style="color: #FFFFFF;">int</span> = <span style="color: #FFFFFF;">10</span>;</div></li><li style="font-family: Monaco, Lucida Console, Lucida, 'Courier New', Courier, monospace; color: white; font-weight: normal; font-style: normal;"><div style="font-family: Monaco, Lucida Console, Lucida, 'Courier New', Courier, monospace; font-weight: normal; ">&nbsp;</div></li><li style="font-family: Monaco, Lucida Console, Lucida, 'Courier New', Courier, monospace; color: white; font-weight: normal; font-style: normal;"><div style="font-family: Monaco, Lucida Console, Lucida, 'Courier New', Courier, monospace; font-weight: normal; "><span style="color: #666666;">//--------------------------------------</span></div></li><li style="font-family: Monaco, Lucida Console, Lucida, 'Courier New', Courier, monospace; color: white; font-weight: normal; font-style: normal;"><div style="font-family: Monaco, Lucida Console, Lucida, 'Courier New', Courier, monospace; font-weight: normal; "><span style="color: #666666;">//  GETTER/SETTERS</span></div></li><li style="font-family: Monaco, Lucida Console, Lucida, 'Courier New', Courier, monospace; color: white; font-weight: normal; font-style: normal;"><div style="font-family: Monaco, Lucida Console, Lucida, 'Courier New', Courier, monospace; font-weight: normal; "><span style="color: #666666;">//--------------------------------------</span></div></li><li style="font-family: Monaco, Lucida Console, Lucida, 'Courier New', Courier, monospace; color: white; font-weight: normal; font-style: normal;"><div style="font-family: Monaco, Lucida Console, Lucida, 'Courier New', Courier, monospace; font-weight: normal; ">&nbsp;</div></li><li style="font-family: Monaco, Lucida Console, Lucida, 'Courier New', Courier, monospace; color: white; font-weight: normal; font-style: normal;"><div style="font-family: Monaco, Lucida Console, Lucida, 'Courier New', Courier, monospace; font-weight: normal; ">	<span style="color: #F7De2D;">public</span> <span style="color: #FF5E00;"><span style="color: #FFFF00;">function</span> <span style="color: #F7De2D;">get</span> speed</span><span style="color: #FFFFFF;">&#40;</span><span style="color: #FFFFFF;">&#41;</span>:<span style="color: #FFFFFF;">int</span><span style="color: #FFFFFF;">&#123;</span> <span style="color: #F7De2D;">return</span> _speed; <span style="color: #FFFFFF;">&#125;</span></div></li><li style="font-family: Monaco, Lucida Console, Lucida, 'Courier New', Courier, monospace; color: white; font-weight: normal; font-style: normal;"><div style="font-family: Monaco, Lucida Console, Lucida, 'Courier New', Courier, monospace; font-weight: normal; ">&nbsp;</div></li><li style="font-family: Monaco, Lucida Console, Lucida, 'Courier New', Courier, monospace; color: white; font-weight: normal; font-style: normal;"><div style="font-family: Monaco, Lucida Console, Lucida, 'Courier New', Courier, monospace; font-weight: normal; ">	<span style="color: #F7De2D;">public</span> <span style="color: #FF5E00;"><span style="color: #FFFF00;">function</span> <span style="color: #F7De2D;">set</span> speed</span><span style="color: #FFFFFF;">&#40;</span>i:<span style="color: #FFFFFF;">int</span><span style="color: #FFFFFF;">&#41;</span><span style="color: #FFFFFF;">&#123;</span></div></li><li style="font-family: Monaco, Lucida Console, Lucida, 'Courier New', Courier, monospace; color: white; font-weight: normal; font-style: normal;"><div style="font-family: Monaco, Lucida Console, Lucida, 'Courier New', Courier, monospace; font-weight: normal; ">		_speed = i;</div></li><li style="font-family: Monaco, Lucida Console, Lucida, 'Courier New', Courier, monospace; color: white; font-weight: normal; font-style: normal;"><div style="font-family: Monaco, Lucida Console, Lucida, 'Courier New', Courier, monospace; font-weight: normal; ">		speedometer.<span style="color: #FFFFFF;">text</span> = <span style="color: #5FCE3C;">'Speed: '</span> + i + <span style="color: #5FCE3C;">'mph'</span>;</div></li><li style="font-family: Monaco, Lucida Console, Lucida, 'Courier New', Courier, monospace; color: white; font-weight: normal; font-style: normal;"><div style="font-family: Monaco, Lucida Console, Lucida, 'Courier New', Courier, monospace; font-weight: normal; ">	<span style="color: #FFFFFF;">&#125;</span></div></li><li style="font-family: Monaco, Lucida Console, Lucida, 'Courier New', Courier, monospace; color: white; font-weight: normal; font-style: normal;"><div style="font-family: Monaco, Lucida Console, Lucida, 'Courier New', Courier, monospace; font-weight: normal; ">&nbsp;</div></li><li style="font-family: Monaco, Lucida Console, Lucida, 'Courier New', Courier, monospace; color: white; font-weight: normal; font-style: normal;"><div style="font-family: Monaco, Lucida Console, Lucida, 'Courier New', Courier, monospace; font-weight: normal; "><span style="color: #666666;">//--------------------------------------</span></div></li><li style="font-family: Monaco, Lucida Console, Lucida, 'Courier New', Courier, monospace; color: white; font-weight: normal; font-style: normal;"><div style="font-family: Monaco, Lucida Console, Lucida, 'Courier New', Courier, monospace; font-weight: normal; "><span style="color: #666666;">//  PRIVATE &amp; PROTECTED INSTANCE METHODS</span></div></li><li style="font-family: Monaco, Lucida Console, Lucida, 'Courier New', Courier, monospace; color: white; font-weight: normal; font-style: normal;"><div style="font-family: Monaco, Lucida Console, Lucida, 'Courier New', Courier, monospace; font-weight: normal; "><span style="color: #666666;">//--------------------------------------</span></div></li><li style="font-family: Monaco, Lucida Console, Lucida, 'Courier New', Courier, monospace; color: white; font-weight: normal; font-style: normal;"><div style="font-family: Monaco, Lucida Console, Lucida, 'Courier New', Courier, monospace; font-weight: normal; ">&nbsp;</div></li><li style="font-family: Monaco, Lucida Console, Lucida, 'Courier New', Courier, monospace; color: white; font-weight: normal; font-style: normal;"><div style="font-family: Monaco, Lucida Console, Lucida, 'Courier New', Courier, monospace; font-weight: normal; ">	<span style="color: #F7De2D;">private</span> <span style="color: #FF5E00;"><span style="color: #FFFF00;">function</span> accelerate</span><span style="color: #FFFFFF;">&#40;</span><span style="color: #FFFFFF;">&#41;</span>:<span style="color: #FFFFFF;">void</span><span style="color: #FFFFFF;">&#123;</span></div></li><li style="font-family: Monaco, Lucida Console, Lucida, 'Courier New', Courier, monospace; color: white; font-weight: normal; font-style: normal;"><div style="font-family: Monaco, Lucida Console, Lucida, 'Courier New', Courier, monospace; font-weight: normal; ">		speed++;</div></li><li style="font-family: Monaco, Lucida Console, Lucida, 'Courier New', Courier, monospace; color: white; font-weight: normal; font-style: normal;"><div style="font-family: Monaco, Lucida Console, Lucida, 'Courier New', Courier, monospace; font-weight: normal; ">	<span style="color: #FFFFFF;">&#125;</span></div></li></ol></pre>
<p></code></p>
<p>As far as the rest of your code is concerned, you’re just accessing a public variable; The setter is then translating that into a private variable and updating a textfield (just like the Var linkage in ol’ AS2).</p>
<blockquote><p><strong>WARNING</strong>: I’m not an expert here, but calling one’s own accessors (there’s an auto-erotica joke to be made here) seems like it goes against OOP principles. In the example, any outside class can wander up and change the speed without permission from the class itself – and that’s not necessarily good – so keep privacy in mind when you use this code. Also, if anyone has a good way to limit access to a setter (perhaps something akin to the singleton pattern would do the trick?), please give a shout.</p></blockquote>
<p>So this is already some powerful mojo, but it’s linked up statically, so for now it’s kind of a one-trick pony. Let’s loosen it up and make this a bit more extensible.</p>
<p><code></p>
<pre class="actionscript"><ol start="11"><li style="font-family: Monaco, Lucida Console, Lucida, 'Courier New', Courier, monospace; color: white; font-weight: normal; font-style: normal;"><div style="font-family: Monaco, Lucida Console, Lucida, 'Courier New', Courier, monospace; font-weight: normal; "><span style="color: #666666;">// ...</span></div></li><li style="font-family: Monaco, Lucida Console, Lucida, 'Courier New', Courier, monospace; color: white; font-weight: normal; font-style: normal;"><div style="font-family: Monaco, Lucida Console, Lucida, 'Courier New', Courier, monospace; font-weight: normal; ">	<span style="color: #F7De2D;">public</span> <span style="color: #FF5E00;"><span style="color: #FFFF00;">function</span> <span style="color: #F7De2D;">set</span> speed</span><span style="color: #FFFFFF;">&#40;</span>i:<span style="color: #FFFFFF;">int</span><span style="color: #FFFFFF;">&#41;</span><span style="color: #FFFFFF;">&#123;</span></div></li><li style="font-family: Monaco, Lucida Console, Lucida, 'Courier New', Courier, monospace; color: white; font-weight: normal; font-style: normal;"><div style="font-family: Monaco, Lucida Console, Lucida, 'Courier New', Courier, monospace; font-weight: normal; ">		_speed = i;</div></li><li style="font-family: Monaco, Lucida Console, Lucida, 'Courier New', Courier, monospace; color: white; font-weight: normal; font-style: normal;"><div style="font-family: Monaco, Lucida Console, Lucida, 'Courier New', Courier, monospace; font-weight: normal; ">		dispatchEvent<span style="color: #FFFFFF;">&#40;</span><span style="color: #FFFFFF;">new</span> Event<span style="color: #FFFFFF;">&#40;</span><span style="color: #5FCE3C;">'speedChanged'</span><span style="color: #FFFFFF;">&#41;</span><span style="color: #FFFFFF;">&#41;</span>;</div></li><li style="font-family: Monaco, Lucida Console, Lucida, 'Courier New', Courier, monospace; color: white; font-weight: normal; font-style: normal;"><div style="font-family: Monaco, Lucida Console, Lucida, 'Courier New', Courier, monospace; font-weight: normal; ">	<span style="color: #FFFFFF;">&#125;</span></div></li><li style="font-family: Monaco, Lucida Console, Lucida, 'Courier New', Courier, monospace; color: white; font-weight: normal; font-style: normal;"><div style="font-family: Monaco, Lucida Console, Lucida, 'Courier New', Courier, monospace; font-weight: normal; ">&nbsp;</div></li><li style="font-family: Monaco, Lucida Console, Lucida, 'Courier New', Courier, monospace; color: white; font-weight: normal; font-style: normal;"><div style="font-family: Monaco, Lucida Console, Lucida, 'Courier New', Courier, monospace; font-weight: normal; "><span style="color: #666666;">//--------------------------------------</span></div></li><li style="font-family: Monaco, Lucida Console, Lucida, 'Courier New', Courier, monospace; color: white; font-weight: normal; font-style: normal;"><div style="font-family: Monaco, Lucida Console, Lucida, 'Courier New', Courier, monospace; font-weight: normal; "><span style="color: #666666;">//  PRIVATE &amp; PROTECTED INSTANCE METHODS</span></div></li><li style="font-family: Monaco, Lucida Console, Lucida, 'Courier New', Courier, monospace; color: white; font-weight: normal; font-style: normal;"><div style="font-family: Monaco, Lucida Console, Lucida, 'Courier New', Courier, monospace; font-weight: normal; "><span style="color: #666666;">//--------------------------------------</span></div></li><li style="font-family: Monaco, Lucida Console, Lucida, 'Courier New', Courier, monospace; color: white; font-weight: normal; font-style: normal;"><div style="font-family: Monaco, Lucida Console, Lucida, 'Courier New', Courier, monospace; font-weight: normal; ">&nbsp;</div></li><li style="font-family: Monaco, Lucida Console, Lucida, 'Courier New', Courier, monospace; color: white; font-weight: normal; font-style: normal;"><div style="font-family: Monaco, Lucida Console, Lucida, 'Courier New', Courier, monospace; font-weight: normal; ">	<span style="color: #F7De2D;">private</span> <span style="color: #FF5E00;"><span style="color: #FFFF00;">function</span> initialize</span><span style="color: #FFFFFF;">&#40;</span><span style="color: #FFFFFF;">&#41;</span>:<span style="color: #FFFFFF;">void</span><span style="color: #FFFFFF;">&#123;</span></div></li><li style="font-family: Monaco, Lucida Console, Lucida, 'Courier New', Courier, monospace; color: white; font-weight: normal; font-style: normal;"><div style="font-family: Monaco, Lucida Console, Lucida, 'Courier New', Courier, monospace; font-weight: normal; ">		addEventListener<span style="color: #FFFFFF;">&#40;</span><span style="color: #5FCE3C;">'speedChanged'</span>, onSpeedChange<span style="color: #FFFFFF;">&#41;</span>;</div></li><li style="font-family: Monaco, Lucida Console, Lucida, 'Courier New', Courier, monospace; color: white; font-weight: normal; font-style: normal;"><div style="font-family: Monaco, Lucida Console, Lucida, 'Courier New', Courier, monospace; font-weight: normal; ">		addEventListener<span style="color: #FFFFFF;">&#40;</span>Event.<span style="color: #71A1CE;">ENTER_FRAME</span>, accelerate<span style="color: #FFFFFF;">&#41;</span>;</div></li><li style="font-family: Monaco, Lucida Console, Lucida, 'Courier New', Courier, monospace; color: white; font-weight: normal; font-style: normal;"><div style="font-family: Monaco, Lucida Console, Lucida, 'Courier New', Courier, monospace; font-weight: normal; ">	<span style="color: #FFFFFF;">&#125;</span></div></li><li style="font-family: Monaco, Lucida Console, Lucida, 'Courier New', Courier, monospace; color: white; font-weight: normal; font-style: normal;"><div style="font-family: Monaco, Lucida Console, Lucida, 'Courier New', Courier, monospace; font-weight: normal; ">&nbsp;</div></li><li style="font-family: Monaco, Lucida Console, Lucida, 'Courier New', Courier, monospace; color: white; font-weight: normal; font-style: normal;"><div style="font-family: Monaco, Lucida Console, Lucida, 'Courier New', Courier, monospace; font-weight: normal; ">	<span style="color: #F7De2D;">private</span> <span style="color: #FF5E00;"><span style="color: #FFFF00;">function</span> accelerate</span><span style="color: #FFFFFF;">&#40;</span><span style="color: #FFFFFF;">e</span>:Event<span style="color: #FFFFFF;">&#41;</span>:<span style="color: #FFFFFF;">void</span><span style="color: #FFFFFF;">&#123;</span></div></li><li style="font-family: Monaco, Lucida Console, Lucida, 'Courier New', Courier, monospace; color: white; font-weight: normal; font-style: normal;"><div style="font-family: Monaco, Lucida Console, Lucida, 'Courier New', Courier, monospace; font-weight: normal; ">		speed++;</div></li><li style="font-family: Monaco, Lucida Console, Lucida, 'Courier New', Courier, monospace; color: white; font-weight: normal; font-style: normal;"><div style="font-family: Monaco, Lucida Console, Lucida, 'Courier New', Courier, monospace; font-weight: normal; ">	<span style="color: #FFFFFF;">&#125;</span></div></li><li style="font-family: Monaco, Lucida Console, Lucida, 'Courier New', Courier, monospace; color: white; font-weight: normal; font-style: normal;"><div style="font-family: Monaco, Lucida Console, Lucida, 'Courier New', Courier, monospace; font-weight: normal; ">&nbsp;</div></li><li style="font-family: Monaco, Lucida Console, Lucida, 'Courier New', Courier, monospace; color: white; font-weight: normal; font-style: normal;"><div style="font-family: Monaco, Lucida Console, Lucida, 'Courier New', Courier, monospace; font-weight: normal; ">	<span style="color: #F7De2D;">private</span> <span style="color: #FF5E00;"><span style="color: #FFFF00;">function</span> onSpeedChange</span><span style="color: #FFFFFF;">&#40;</span><span style="color: #FFFFFF;">e</span>:Event<span style="color: #FFFFFF;">&#41;</span>:<span style="color: #FFFFFF;">void</span><span style="color: #FFFFFF;">&#123;</span></div></li><li style="font-family: Monaco, Lucida Console, Lucida, 'Courier New', Courier, monospace; color: white; font-weight: normal; font-style: normal;"><div style="font-family: Monaco, Lucida Console, Lucida, 'Courier New', Courier, monospace; font-weight: normal; ">		speedometer.<span style="color: #FFFFFF;">text</span> = <span style="color: #5FCE3C;">'Speed: '</span> + i + <span style="color: #5FCE3C;">'mph'</span>;</div></li><li style="font-family: Monaco, Lucida Console, Lucida, 'Courier New', Courier, monospace; color: white; font-weight: normal; font-style: normal;"><div style="font-family: Monaco, Lucida Console, Lucida, 'Courier New', Courier, monospace; font-weight: normal; ">	<span style="color: #FFFFFF;">&#125;</span></div></li></ol></pre>
<p></code></p>
<p>Now we’ve got a good onChange thing going here. Admittedly it’s still a far cry from just tagging a listener onto any old random variable, but with a little clever use of the event class you can achieve the same results.</p>
<blockquote><p><strong>BONUS CODE!</strong> Here’s the little workaround that inspired this post:</p></blockquote>
<p><code> </code></p>
<p><code></p>
<pre class="actionscript"><ol start="0"><li style="font-family: Monaco, Lucida Console, Lucida, 'Courier New', Courier, monospace; color: white; font-weight: normal; font-style: normal;"><div style="font-family: Monaco, Lucida Console, Lucida, 'Courier New', Courier, monospace; font-weight: normal; "><span style="color: #F7De2D;">public</span> <span style="color: #FF5E00;"><span style="color: #FFFF00;">function</span> <span style="color: #F7De2D;">get</span> scale</span><span style="color: #FFFFFF;">&#40;</span><span style="color: #FFFFFF;">&#41;</span>:<span style="color: #FFFFFF;">Number</span><span style="color: #FFFFFF;">&#123;</span> <span style="color: #F7De2D;">return</span> scaleX; <span style="color: #FFFFFF;">&#125;</span></div></li><li style="font-family: Monaco, Lucida Console, Lucida, 'Courier New', Courier, monospace; color: white; font-weight: normal; font-style: normal;"><div style="font-family: Monaco, Lucida Console, Lucida, 'Courier New', Courier, monospace; font-weight: normal; ">&nbsp;</div></li><li style="font-family: Monaco, Lucida Console, Lucida, 'Courier New', Courier, monospace; color: white; font-weight: normal; font-style: normal;"><div style="font-family: Monaco, Lucida Console, Lucida, 'Courier New', Courier, monospace; font-weight: normal; "><span style="color: #F7De2D;">public</span> <span style="color: #FF5E00;"><span style="color: #FFFF00;">function</span> <span style="color: #F7De2D;">set</span> scale</span><span style="color: #FFFFFF;">&#40;</span>n:<span style="color: #FFFFFF;">Number</span><span style="color: #FFFFFF;">&#41;</span><span style="color: #FFFFFF;">&#123;</span></div></li><li style="font-family: Monaco, Lucida Console, Lucida, 'Courier New', Courier, monospace; color: white; font-weight: normal; font-style: normal;"><div style="font-family: Monaco, Lucida Console, Lucida, 'Courier New', Courier, monospace; font-weight: normal; ">	scaleX = scaleY = n;</div></li><li style="font-family: Monaco, Lucida Console, Lucida, 'Courier New', Courier, monospace; color: white; font-weight: normal; font-style: normal;"><div style="font-family: Monaco, Lucida Console, Lucida, 'Courier New', Courier, monospace; font-weight: normal; "><span style="color: #FFFFFF;">&#125;</span></div></li></ol></pre>
<p></code></p>
]]></content:encoded>
			<wfw:commentRss>http://www.calypso88.com/?feed=rss2&amp;p=33</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>16bit Gradients in Flash – Almost.</title>
		<link>http://www.calypso88.com/?p=32</link>
		<comments>http://www.calypso88.com/?p=32#comments</comments>
		<pubDate>Mon, 04 Aug 2008 00:04:20 +0000</pubDate>
		<dc:creator>Rob</dc:creator>
				<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://www.calypso88.com/?p=32</guid>
		<description><![CDATA[A forum thread recently challenged my knowledge (and preconceptions) of gradients in Flash. I’ve always worked under the assumption that Flash uses 8 bits per color channel – zero to 0xFF for R, G, and B – end of story. Although this is generally considered the shallow end of the color-depth pool, it’s always been [...]]]></description>
			<content:encoded><![CDATA[<p>A forum thread recently challenged my knowledge (and preconceptions) of gradients in Flash. I’ve always worked under the assumption that Flash uses 8 bits per color channel – zero to 0xFF for R, G, and B – end of story. Although this is generally considered the shallow end of the color-depth pool, it’s always been more or less sufficient. The shallow color depth has long been considered the sweet spot between passable (even realistic) color recreation, and the exponential processing lode of adding more data to each pixel in a display.</p>
<p>The point where 8-bit graphics break down is when it comes time to interpolate a gradient. If you want to draw a smooth fade from black to 10% grey, you want as many colors in-between as there are pixels. In an 8-bit environment, you’ve only got about 26 shades of grey to work with so anything bigger than 26 pixels across is going to have blocks of pixels, all colored the same – in the biz, this is called “banding.”</p>
<p><img src="http://www.calypso88.com/flash/gradient/banding.gif" alt="ugly!" /></p>
<p>Interestingly, while Flash is bound to 8-bit it will still import a 16-bit Tiff. When I realized this I figured there must be some trickery going on - either I could use 16-bit color in Flash or else the Tiff was getting the chop. Unfortunately, it turns out Flash downsamples the image into it's own color profile, but the importer is good enough to give us the courtesy of a good dithering first (provided you enabled it in Photoshop). Here’s a little demo to show the dithering - if you squint you can see the banding on the originals.</p>
<blockquote><p><strong>Edit</strong>: Per Ben’s comment, I’ve tweaked the colors below to make the banding a little more noticeable (if you still see flat-black bars, try cranking up your monitor’s brightness/contrast). For all the headaches I’ve had from gradients in the past, making a bad one is really hard to reproduce on command!</p></blockquote>

<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000"
			id="fm_bars_687139092"
			class="flashmovie"
			width="460"
			height="250">
	<param name="movie" value="http://www.calypso88.com/flash/gradient/bars.swf" />
	<!--[if !IE]>-->
	<object	type="application/x-shockwave-flash"
			data="http://www.calypso88.com/flash/gradient/bars.swf"
			name="fm_bars_687139092"
			width="460"
			height="250">
	<!--<![endif]-->
		
	<!--[if !IE]>-->
	</object>
	<!--<![endif]-->
</object>
]]></content:encoded>
			<wfw:commentRss>http://www.calypso88.com/?feed=rss2&amp;p=32</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Breadth first maze solution</title>
		<link>http://www.calypso88.com/?p=30</link>
		<comments>http://www.calypso88.com/?p=30#comments</comments>
		<pubDate>Tue, 22 Jul 2008 05:37:48 +0000</pubDate>
		<dc:creator>Rob</dc:creator>
				<category><![CDATA[Actionscript 3.0]]></category>
		<category><![CDATA[Pathfinding]]></category>
		<category><![CDATA[maze]]></category>

		<guid isPermaLink="false">http://www.calypso88.com/?p=30</guid>
		<description><![CDATA[I know, I know – back-to-back entries, the sky must be falling. I felt so guilty about posting that code yesterday that I was compelled to get this second version finished off tonight and optimized. And good news - I’m clocking it at 7 seconds! The big secret (ok, Bionic-Badger apparently already knew it in [...]]]></description>
			<content:encoded><![CDATA[<p>I know, I know – back-to-back entries, the sky must be falling.</p>
<p>I felt so guilty about posting that code yesterday that I was compelled to get this second version finished off tonight and optimized. And good news - I’m clocking it at 7 seconds! The big secret (ok, Bionic-Badger apparently already knew it in his comment a month ago) is to remove all the data constructs and just jam through the bitmap directly. So that’s what I did.</p>
<p>I had a brief notion that recursion was the way to go (I loves me some recursion!), the code was benchmarking extremely fast since there isn’t any storage, every child node just gets scoped into its own closure, however around fifteen thousand nested function calls is where Flash draws the line and throws in the towel (or stack overflow error, as the case may be). I’m still pretty sure I could get this algorithm down into the 2-3 second range if the recursion had worked...</p>
<p>Anyhow, my strategy was to color each explored pixel with an incremental number, so the first pixel becomes colored 1, the second 2, etc. Since we’re in hex color land, this gives the weird side effect of black to blue gradients that shift up into the green space as the color channels overflow. It’s bizarre to look at, but kind of cool to see where the breadth-first approach explores different areas. After that mapping has taken place, it’s a simple matter of tracing the path back from any given pixel by repeatedly finding its lowest-valued neighbor.</p>
<p>One final note; I’ve been noticing a strange discrepancy in the memory traces. About half the time I’m seeing 30-35mb and the rest of the time 2-3. I know this code is spinning off a lot of throw-away variables so I’m inclined to believe the higher numbers and speculate that the lower numbers are results of the Garbage Collector running at opportune times.</p>
<p><a href="http://calypso88.com/maze_03/">Maze pathfinder 2</a><br />
<a href="http://calypso88.com/maze_03/maze2.zip">source</a> [748k]</p>
]]></content:encoded>
			<wfw:commentRss>http://www.calypso88.com/?feed=rss2&amp;p=30</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>[sad excuse for not posting goes here]</title>
		<link>http://www.calypso88.com/?p=29</link>
		<comments>http://www.calypso88.com/?p=29#comments</comments>
		<pubDate>Mon, 21 Jul 2008 03:11:46 +0000</pubDate>
		<dc:creator>Rob</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[maze]]></category>

		<guid isPermaLink="false">http://www.calypso88.com/?p=29</guid>
		<description><![CDATA[A few weeks ago now, I got a comment on my last post asking for the source. The real (dirty little) reason I took so long on this, is that I was trying to find some time to rewrite this stuff and post a much better version alongside, but it just didn't happen. I’d still [...]]]></description>
			<content:encoded><![CDATA[<p>A few weeks ago now, I got a comment on my last post asking for the source. The real (dirty little) reason I took so long on this, is that I was trying to find some time to rewrite this stuff and post a much better version alongside, but it just didn't happen. I’d still like to get a new version of this thing put together – I’m confident I can beat that 11 second benchmark – but in the meantime, anyone reading can take a chuckle at my schlocky earlier version. And for the curious, <a href="http://www.calypso88.com/?p=24">here’s a link</a> back to what I originally developed that code for - which is a roundabout apology/defense of my (very) liberal memory hogging.</p>
<p><a href="http://www.calypso88.com/maze_02/maze.zip">Maze pathfinder</a> [1mb]</p>
]]></content:encoded>
			<wfw:commentRss>http://www.calypso88.com/?feed=rss2&amp;p=29</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>The long way around.</title>
		<link>http://www.calypso88.com/?p=27</link>
		<comments>http://www.calypso88.com/?p=27#comments</comments>
		<pubDate>Fri, 27 Jun 2008 01:39:55 +0000</pubDate>
		<dc:creator>Rob</dc:creator>
				<category><![CDATA[Actionscript 3.0]]></category>
		<category><![CDATA[Pathfinding]]></category>
		<category><![CDATA[maze]]></category>

		<guid isPermaLink="false">http://www.calypso88.com/?p=27</guid>
		<description><![CDATA[I've gutted my pathfinder code and thrown it at a devilishly complex problem – specifically 4 megapixels of eye-squintingly difficult maze. The big concern with this beast is managing resources; You can't simply jam the image into an array and go for broke, there has to be some sort of throttle to keep the code [...]]]></description>
			<content:encoded><![CDATA[<p><img src="http://www.calypso88.com/wp-content/uploads/2008/06/banner.gif" alt="maze banner" /></p>
<p>I've gutted my pathfinder code and thrown it at a devilishly complex problem – specifically <strong>4 megapixels</strong> of eye-squintingly difficult maze.</p>
<p>The big concern with this beast is managing resources; You can't simply jam the image into an array and go for broke, there has to be some sort of throttle to keep the code running in small, frame-sized chunks. The solution for that is to split my big loops up into loop-invariant code and run each iteration (or 20) on an EnterFrame event.</p>
<p>Next up is memory - my original engine was designed to run quickly so I could use it many times per frame without a noticeable slowdown. This means a lot of caching, specifically the <strong>entire map</strong> is put into memory as a 2-dimensional array, and then each node is given a link to it’s viable neighbors. This is obviously overkill for a simple pathfinder, but if you’re going to find a path on the same plane more than once, you’ve saved all the work from the first run into a crazy, multidimensional linked list (matrix? lattice?). If I were writing this from scratch I’d probably do away with the pre-caching step and do something tricky with byteArrays, but I’m not about to recode this whole thing just for a little stress-test. Consider this the official warning that this swf is a memory <a href="http://www.breitbart.com/article.php?id=D8PBKB5G0&amp;show_article=1&amp;image=large" target="_blank">hog</a> - running this swf may crash your browser/OS/hardware/whatever. Fair warning.</p>
<p>So the bottom line here is that this solution runs slowly…very slowly…like <a href="http://xkcd.com/120/" target="_blank">bring-a-tent</a> slow. It’s thinking about 80 nodes (pixels) every frame (currently slated at 60fps but it’s dropping), and there are just under four million pixels to go through so it takes some time. My first test completed in just over 65 minutes (although about a third of that time was spent drawing the path back to the start once it had been identified). The version below has some optimizations that bring the scanning and pathfinding time down to about 25 minutes and another eight to draw the final path. A screenshot of the solution is included for the impatient.</p>
<p><strong>Note</strong>: <em>Testing this thing was a nightmare...obviously the real problems all happen after the loading and parsing passes so it takes forever. I tried socking that data into a SharedObject but it crashed safari thrice in a row so I gave up on that idea. Also, I wasted an hour getting confusing results out of my parser only to figure out that I had left jpeg encoding on and the source image was no longer true black and white.</em></p>
<blockquote><p><a href="http://calypso88.com/maze_01/" target="_blank">pathfinder [344k]</a></p>
<p><a href="http://calypso88.com/maze_01/original.gif" target="_blank">original maze</a></p>
<p><a href="http://calypso88.com/maze_01/solution.gif" target="_blank">solution</a></p></blockquote>
<p>UPDATE: Per the comment below, I’ve pulled the limits off this baby and thrown caution (and smooth, steady framerates) to the wind. I benched this version at 51 seconds in XP. Not bad, considering it only required massaging a couple of variables.</p>
<blockquote><p><a href="http://calypso88.com/maze_02/" target="_blank">fast version</a></p></blockquote>
<p>UPDATE 2: This post has been getting a lot of direct traffic lately so I'm updating my progress here. Basically I recoded the solver to map out the solution in under 10 seconds. You can hit the pathfinding category below for the full saga or jump directly to the fastest attempt:</p>
<blockquote><p><a href="http://www.calypso88.com/flash/maze_03/">super-fast version</a></p></blockquote>
]]></content:encoded>
			<wfw:commentRss>http://www.calypso88.com/?feed=rss2&amp;p=27</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
		<item>
		<title>Unfucking the ExternalInterface (2 of 2)</title>
		<link>http://www.calypso88.com/?p=26</link>
		<comments>http://www.calypso88.com/?p=26#comments</comments>
		<pubDate>Sun, 11 May 2008 15:56:28 +0000</pubDate>
		<dc:creator>Rob</dc:creator>
				<category><![CDATA[Actionscript 3.0]]></category>

		<guid isPermaLink="false">http://www.calypso88.com/?p=26</guid>
		<description><![CDATA[&#8672; Unfucking the ExternalInterface (1 of 2) Step 2. Validate and Dispatch. As much as I hate to admit it, JS tends to run quite a bit faster than AS3; So when the two are communicating, the real lag happens on the Flash side. It’s not such a problem if you just need to twiddle [...]]]></description>
			<content:encoded><![CDATA[<p><em><a href="http://www.calypso88.com/?p=25">&#8672; Unfucking the ExternalInterface (1 of 2)</a><a href="http://www.calypso88.com/?p=25"></a></em></p>
<p><a href="http://www.calypso88.com/?p=25"></a></p>
<p><a href="http://www.calypso88.com/?p=25"></a></p>
<p><strong>Step 2. Validate and Dispatch.</strong><br />
As much as I hate to admit it, JS tends to run quite a bit faster than AS3; So when the two are communicating, the real lag happens on the Flash side. It’s not such a problem if you just need to twiddle a boolean flag or set a variable, but generally when JS fires off some data, thats your cue to run a pile of code on it.</p>
<p>Let's take a look at that last sentance:</p>
<blockquote><p><em>…when JS fires…data…your cue…pile of code</em></p></blockquote>
<p>Sounds a lot like the event model, no? Well Adobe™ didn't think so, and the ExternalInterface’s sphincter-tight coupling and lack of validation are a slap in the face to anyone who disagrees.</p>
<p>Before we get ahead of ourselves, it’s worth bringing up my second gripe: Data validation.</p>
<p>Anyone who’s written AS3 for more than five minutes has seen a swf lock up as the result of a function receiving too much, too little, or unexpected data. Luckily the compiler catches these bugs and won’t allow you to publish until they’re resolved. When that safety-net is removed, most methods dealing with external data will wrap the incoming content inside a wildcard object like LoaderInfo or URLLoader. However, the ExternalInterface breaks from the rest of the API again and removes that last line of defense. By adding an EI callback, you expose that function to anything JS can send without filter.</p>
<p><strong>Rest and relay.</strong><br />
Since there’s nothing to safeguard our inbound data, we need a small demilitarized zone where we can figure out what parameters we’re dealing with and cast them to a data type that Flash won’t choke on. It’s an ideal job for the <a href="http://livedocs.adobe.com/flash/9.0/ActionScriptLangRefV3/statements.html#..._(rest)_parameter">rest statement</a>:</p>
<p><code></p>
<pre class="actionscript"><ol start="0"><li style="font-family: Monaco, Lucida Console, Lucida, 'Courier New', Courier, monospace; color: white; font-weight: normal; font-style: normal;"><div style="font-family: Monaco, Lucida Console, Lucida, 'Courier New', Courier, monospace; font-weight: normal; ">ExternalInterface.<span style="color: #71A1CE;">addCallback</span><span style="color: #FFFFFF;">&#40;</span><span style="color: #5FCE3C;">'pieceOfAS'</span>, incomingJS<span style="color: #FFFFFF;">&#41;</span></div></li><li style="font-family: Monaco, Lucida Console, Lucida, 'Courier New', Courier, monospace; color: white; font-weight: normal; font-style: normal;"><div style="font-family: Monaco, Lucida Console, Lucida, 'Courier New', Courier, monospace; font-weight: normal; ">&nbsp;</div></li><li style="font-family: Monaco, Lucida Console, Lucida, 'Courier New', Courier, monospace; color: white; font-weight: normal; font-style: normal;"><div style="font-family: Monaco, Lucida Console, Lucida, 'Courier New', Courier, monospace; font-weight: normal; "><span style="color: #F7De2D;">private</span> <span style="color: #FF5E00;"><span style="color: #FFFF00;">function</span> incomingJS</span><span style="color: #FFFFFF;">&#40;</span>...<span style="color: #71A1CE;">args</span><span style="color: #FFFFFF;">&#41;</span>:<span style="color: #FFFFFF;">Boolean</span><span style="color: #FFFFFF;">&#123;</span></div></li><li style="font-family: Monaco, Lucida Console, Lucida, 'Courier New', Courier, monospace; color: white; font-weight: normal; font-style: normal;"><div style="font-family: Monaco, Lucida Console, Lucida, 'Courier New', Courier, monospace; font-weight: normal; ">&nbsp;</div></li><li style="font-family: Monaco, Lucida Console, Lucida, 'Courier New', Courier, monospace; color: white; font-weight: normal; font-style: normal;"><div style="font-family: Monaco, Lucida Console, Lucida, 'Courier New', Courier, monospace; font-weight: normal; ">	<span style="color: #666666;">//  lets say the real function requires an int and a string</span></div></li><li style="font-family: Monaco, Lucida Console, Lucida, 'Courier New', Courier, monospace; color: white; font-weight: normal; font-style: normal;"><div style="font-family: Monaco, Lucida Console, Lucida, 'Courier New', Courier, monospace; font-weight: normal; ">	<span style="color: #F7De2D;">if</span><span style="color: #FFFFFF;">&#40;</span>args.<span style="color: #FFFFFF;">length</span> &amp;lt; <span style="color: #FFFFFF;">2</span> || args.<span style="color: #FFFFFF;">length</span> &amp;gt; <span style="color: #FFFFFF;">2</span><span style="color: #FFFFFF;">&#41;</span><span style="color: #FFFFFF;">&#123;</span> <span style="color: #F7De2D;">return</span> <span style="color: #FFFFFF;">false</span>; <span style="color: #FFFFFF;">&#125;</span></div></li><li style="font-family: Monaco, Lucida Console, Lucida, 'Courier New', Courier, monospace; color: white; font-weight: normal; font-style: normal;"><div style="font-family: Monaco, Lucida Console, Lucida, 'Courier New', Courier, monospace; font-weight: normal; ">&nbsp;</div></li><li style="font-family: Monaco, Lucida Console, Lucida, 'Courier New', Courier, monospace; color: white; font-weight: normal; font-style: normal;"><div style="font-family: Monaco, Lucida Console, Lucida, 'Courier New', Courier, monospace; font-weight: normal; ">	<span style="color: #FFFFFF;">try</span><span style="color: #FFFFFF;">&#123;</span></div></li><li style="font-family: Monaco, Lucida Console, Lucida, 'Courier New', Courier, monospace; color: white; font-weight: normal; font-style: normal;"><div style="font-family: Monaco, Lucida Console, Lucida, 'Courier New', Courier, monospace; font-weight: normal; ">		<span style="color: #666666;">//  cast and validate the integer</span></div></li><li style="font-family: Monaco, Lucida Console, Lucida, 'Courier New', Courier, monospace; color: white; font-weight: normal; font-style: normal;"><div style="font-family: Monaco, Lucida Console, Lucida, 'Courier New', Courier, monospace; font-weight: normal; ">		<span style="color: #F7De2D;">var</span> i:<span style="color: #FFFFFF;">int</span> = <span style="color: #FFFFFF;">int</span><span style="color: #FFFFFF;">&#40;</span>args<span style="color: #FFFFFF;">&#91;</span><span style="color: #FFFFFF;">0</span><span style="color: #FFFFFF;">&#93;</span><span style="color: #FFFFFF;">&#41;</span>;</div></li><li style="font-family: Monaco, Lucida Console, Lucida, 'Courier New', Courier, monospace; color: white; font-weight: normal; font-style: normal;"><div style="font-family: Monaco, Lucida Console, Lucida, 'Courier New', Courier, monospace; font-weight: normal; ">		<span style="color: #F7De2D;">if</span><span style="color: #FFFFFF;">&#40;</span>i != args<span style="color: #FFFFFF;">&#91;</span><span style="color: #FFFFFF;">0</span><span style="color: #FFFFFF;">&#93;</span><span style="color: #FFFFFF;">&#41;</span><span style="color: #FFFFFF;">&#123;</span></div></li><li style="font-family: Monaco, Lucida Console, Lucida, 'Courier New', Courier, monospace; color: white; font-weight: normal; font-style: normal;"><div style="font-family: Monaco, Lucida Console, Lucida, 'Courier New', Courier, monospace; font-weight: normal; ">			<span style="color: #FFFFFF;">trace</span><span style="color: #FFFFFF;">&#40;</span><span style="color: #5FCE3C;">'float received, expecting int'</span><span style="color: #FFFFFF;">&#41;</span>;</div></li><li style="font-family: Monaco, Lucida Console, Lucida, 'Courier New', Courier, monospace; color: white; font-weight: normal; font-style: normal;"><div style="font-family: Monaco, Lucida Console, Lucida, 'Courier New', Courier, monospace; font-weight: normal; ">			<span style="color: #F7De2D;">return</span> <span style="color: #FFFFFF;">false</span>;</div></li><li style="font-family: Monaco, Lucida Console, Lucida, 'Courier New', Courier, monospace; color: white; font-weight: normal; font-style: normal;"><div style="font-family: Monaco, Lucida Console, Lucida, 'Courier New', Courier, monospace; font-weight: normal; ">		<span style="color: #FFFFFF;">&#125;</span></div></li><li style="font-family: Monaco, Lucida Console, Lucida, 'Courier New', Courier, monospace; color: white; font-weight: normal; font-style: normal;"><div style="font-family: Monaco, Lucida Console, Lucida, 'Courier New', Courier, monospace; font-weight: normal; ">&nbsp;</div></li><li style="font-family: Monaco, Lucida Console, Lucida, 'Courier New', Courier, monospace; color: white; font-weight: normal; font-style: normal;"><div style="font-family: Monaco, Lucida Console, Lucida, 'Courier New', Courier, monospace; font-weight: normal; ">		<span style="color: #666666;">//  cast the string</span></div></li><li style="font-family: Monaco, Lucida Console, Lucida, 'Courier New', Courier, monospace; color: white; font-weight: normal; font-style: normal;"><div style="font-family: Monaco, Lucida Console, Lucida, 'Courier New', Courier, monospace; font-weight: normal; ">		<span style="color: #F7De2D;">var</span> s:<span style="color: #FFFFFF;">String</span> = <span style="color: #FFFFFF;">String</span><span style="color: #FFFFFF;">&#40;</span>args<span style="color: #FFFFFF;">&#91;</span><span style="color: #FFFFFF;">1</span><span style="color: #FFFFFF;">&#93;</span><span style="color: #FFFFFF;">&#41;</span>;</div></li><li style="font-family: Monaco, Lucida Console, Lucida, 'Courier New', Courier, monospace; color: white; font-weight: normal; font-style: normal;"><div style="font-family: Monaco, Lucida Console, Lucida, 'Courier New', Courier, monospace; font-weight: normal; ">	<span style="color: #FFFFFF;">&#125;</span> <span style="color: #FFFFFF;">catch</span> <span style="color: #FFFFFF;">&#40;</span><span style="color: #FFFFFF;">e</span>:<span style="color: #FFFFFF;">Error</span><span style="color: #FFFFFF;">&#41;</span> <span style="color: #FFFFFF;">&#123;</span></div></li><li style="font-family: Monaco, Lucida Console, Lucida, 'Courier New', Courier, monospace; color: white; font-weight: normal; font-style: normal;"><div style="font-family: Monaco, Lucida Console, Lucida, 'Courier New', Courier, monospace; font-weight: normal; ">		<span style="color: #FFFFFF;">trace</span><span style="color: #FFFFFF;">&#40;</span><span style="color: #FFFFFF;">e</span><span style="color: #FFFFFF;">&#41;</span>;</div></li><li style="font-family: Monaco, Lucida Console, Lucida, 'Courier New', Courier, monospace; color: white; font-weight: normal; font-style: normal;"><div style="font-family: Monaco, Lucida Console, Lucida, 'Courier New', Courier, monospace; font-weight: normal; ">		<span style="color: #F7De2D;">return</span> <span style="color: #FFFFFF;">false</span>;</div></li><li style="font-family: Monaco, Lucida Console, Lucida, 'Courier New', Courier, monospace; color: white; font-weight: normal; font-style: normal;"><div style="font-family: Monaco, Lucida Console, Lucida, 'Courier New', Courier, monospace; font-weight: normal; ">	<span style="color: #FFFFFF;">&#125;</span></div></li><li style="font-family: Monaco, Lucida Console, Lucida, 'Courier New', Courier, monospace; color: white; font-weight: normal; font-style: normal;"><div style="font-family: Monaco, Lucida Console, Lucida, 'Courier New', Courier, monospace; font-weight: normal; ">&nbsp;</div></li><li style="font-family: Monaco, Lucida Console, Lucida, 'Courier New', Courier, monospace; color: white; font-weight: normal; font-style: normal;"><div style="font-family: Monaco, Lucida Console, Lucida, 'Courier New', Courier, monospace; font-weight: normal; ">	<span style="color: #FFFFFF;">trace</span><span style="color: #FFFFFF;">&#40;</span><span style="color: #5FCE3C;">'no errors encountered'</span><span style="color: #FFFFFF;">&#41;</span>;</div></li><li style="font-family: Monaco, Lucida Console, Lucida, 'Courier New', Courier, monospace; color: white; font-weight: normal; font-style: normal;"><div style="font-family: Monaco, Lucida Console, Lucida, 'Courier New', Courier, monospace; font-weight: normal; ">	<span style="color: #F7De2D;">return</span> <span style="color: #FFFFFF;">true</span>;</div></li><li style="font-family: Monaco, Lucida Console, Lucida, 'Courier New', Courier, monospace; color: white; font-weight: normal; font-style: normal;"><div style="font-family: Monaco, Lucida Console, Lucida, 'Courier New', Courier, monospace; font-weight: normal; ">&nbsp;</div></li><li style="font-family: Monaco, Lucida Console, Lucida, 'Courier New', Courier, monospace; color: white; font-weight: normal; font-style: normal;"><div style="font-family: Monaco, Lucida Console, Lucida, 'Courier New', Courier, monospace; font-weight: normal; "><span style="color: #FFFFFF;">&#125;</span></div></li></ol></pre>
<p></code></p>
<p>This is mainly a big system of rejecting any data that isn’t perfect. We start by counting the arguments passed (if there aren’t 2, we eject), then we hard-cast the values to the types we’re expecting to get and if all goes well, only then do we alert JS that we got the message and we’re going to start work on it. Unfortunately, this method of validation is pretty specific to whatever function you’re calling, but it’s still a lot better than getting an incorrect value and having your swf flip out without letting you know.</p>
<p>So we’ve got the right data and we’re ready to process it. The last hurdle is solved with a custom event to wrap that data and throw it outside of the currently-running function to be processed at the start of the next frame. Let’s throw that line in the bottom of the previous code:</p>
<p><code></p>
<pre class="actionscript"><ol start="21"><li style="font-family: Monaco, Lucida Console, Lucida, 'Courier New', Courier, monospace; color: white; font-weight: normal; font-style: normal;"><div style="font-family: Monaco, Lucida Console, Lucida, 'Courier New', Courier, monospace; font-weight: normal; "><span style="color: #666666;">//  ...</span></div></li><li style="font-family: Monaco, Lucida Console, Lucida, 'Courier New', Courier, monospace; color: white; font-weight: normal; font-style: normal;"><div style="font-family: Monaco, Lucida Console, Lucida, 'Courier New', Courier, monospace; font-weight: normal; "><span style="color: #FFFFFF;">trace</span><span style="color: #FFFFFF;">&#40;</span><span style="color: #5FCE3C;">'no errors encountered'</span><span style="color: #FFFFFF;">&#41;</span>;</div></li><li style="font-family: Monaco, Lucida Console, Lucida, 'Courier New', Courier, monospace; color: white; font-weight: normal; font-style: normal;"><div style="font-family: Monaco, Lucida Console, Lucida, 'Courier New', Courier, monospace; font-weight: normal; ">dispatchEvent<span style="color: #FFFFFF;">&#40;</span><span style="color: #FFFFFF;">new</span> JSEvent<span style="color: #FFFFFF;">&#40;</span><span style="color: #5FCE3C;">'pieceOfAS'</span>, i, s<span style="color: #FFFFFF;">&#41;</span><span style="color: #FFFFFF;">&#41;</span>;</div></li><li style="font-family: Monaco, Lucida Console, Lucida, 'Courier New', Courier, monospace; color: white; font-weight: normal; font-style: normal;"><div style="font-family: Monaco, Lucida Console, Lucida, 'Courier New', Courier, monospace; font-weight: normal; "><span style="color: #F7De2D;">return</span> <span style="color: #FFFFFF;">true</span>;</div></li><li style="font-family: Monaco, Lucida Console, Lucida, 'Courier New', Courier, monospace; color: white; font-weight: normal; font-style: normal;"><div style="font-family: Monaco, Lucida Console, Lucida, 'Courier New', Courier, monospace; font-weight: normal; "><span style="color: #666666;">//  ...</span></div></li></ol></pre>
<p></code></p>
<p>And of course outside the incomingJS function we’ll need to attach a listener for that event.</p>
<p><code></p>
<pre class="actionscript"><ol start="27"><li style="font-family: Monaco, Lucida Console, Lucida, 'Courier New', Courier, monospace; color: white; font-weight: normal; font-style: normal;"><div style="font-family: Monaco, Lucida Console, Lucida, 'Courier New', Courier, monospace; font-weight: normal; ">addEventListener<span style="color: #FFFFFF;">&#40;</span><span style="color: #5FCE3C;">'pieceOfAS'</span>, processJS<span style="color: #FFFFFF;">&#41;</span>;</div></li><li style="font-family: Monaco, Lucida Console, Lucida, 'Courier New', Courier, monospace; color: white; font-weight: normal; font-style: normal;"><div style="font-family: Monaco, Lucida Console, Lucida, 'Courier New', Courier, monospace; font-weight: normal; ">&nbsp;</div></li><li style="font-family: Monaco, Lucida Console, Lucida, 'Courier New', Courier, monospace; color: white; font-weight: normal; font-style: normal;"><div style="font-family: Monaco, Lucida Console, Lucida, 'Courier New', Courier, monospace; font-weight: normal; "><span style="color: #F7De2D;">private</span> <span style="color: #FF5E00;"><span style="color: #FFFF00;">function</span> processJS</span><span style="color: #FFFFFF;">&#40;</span><span style="color: #FFFFFF;">e</span>:JSEvent<span style="color: #FFFFFF;">&#41;</span>:<span style="color: #FFFFFF;">void</span><span style="color: #FFFFFF;">&#123;</span></div></li><li style="font-family: Monaco, Lucida Console, Lucida, 'Courier New', Courier, monospace; color: white; font-weight: normal; font-style: normal;"><div style="font-family: Monaco, Lucida Console, Lucida, 'Courier New', Courier, monospace; font-weight: normal; ">	<span style="color: #666666;">//  ...</span></div></li><li style="font-family: Monaco, Lucida Console, Lucida, 'Courier New', Courier, monospace; color: white; font-weight: normal; font-style: normal;"><div style="font-family: Monaco, Lucida Console, Lucida, 'Courier New', Courier, monospace; font-weight: normal; "><span style="color: #FFFFFF;">&#125;</span></div></li></ol></pre>
<p></code></p>
<p>Done! To recap, JavaScript target’s our swf and calls pieceOfAS(123, "werd"), that translates directly into a call on incomingJS(), which makes sure we’ve gotten exactly two variables, one integer and one string. The incomingJS function then puts those two arguments into an event (<a href="http://flexcomps.wordpress.com/2008/04/29/dispatching-custom-events-in-as3-with-data-or-object/" target="_blank">here's a tutorial</a> if you’ve never made custom events) and dispatches it, and then returns ‘true’ to JS – we now have both AS and JS running in tandem again. Lastly our eventListener catches the custom event and routes it into the processJS() function, who can now run all the heavy code it wants without bogging anything else down.</p>
<p><em><a href="http://www.calypso88.com/?p=25">&#8672; Unfucking the ExternalInterface (1 of 2)</a></em></p>
]]></content:encoded>
			<wfw:commentRss>http://www.calypso88.com/?feed=rss2&amp;p=26</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Unfucking the ExternalInterface (1 of 2)</title>
		<link>http://www.calypso88.com/?p=25</link>
		<comments>http://www.calypso88.com/?p=25#comments</comments>
		<pubDate>Mon, 05 May 2008 04:20:37 +0000</pubDate>
		<dc:creator>Rob</dc:creator>
				<category><![CDATA[Actionscript 3.0]]></category>

		<guid isPermaLink="false">http://www.calypso88.com/?p=25</guid>
		<description><![CDATA[or – Asynchronous Communication and the AS3 ExternalInterface I just deleted four paragraphs of this post, since they could be summed up as “I hate ExternalInterface because it's slow,” which isn’t even an accurate grievance. ExternalInterface is pretty quick. It's the function’s being called by it that are slow. My real frustration is that communication [...]]]></description>
			<content:encoded><![CDATA[<p>or – <em>Asynchronous Communication and the AS3 ExternalInterface</em></p>
<p>I just deleted four paragraphs of this post, since they could be summed up as “<em>I hate ExternalInterface because it's slow</em>,” which isn’t even an accurate grievance. ExternalInterface is pretty quick. It's the function’s being called by it that are slow. </p>
<p>My real frustration is that communication between Flash and JS is synchronous. That is, whenever Flash calls out to run a javascript function, all action inside Flash halts until the JS function is completed. This makes sense if you’re using getters and setters, but try anything bigger than that and you’ll start to see problems. At the very shallowest level, you’ll see your animation stutter every time you call out to a JS function that takes more than a couple milliseconds, at deeper levels you’ll enjoy long unexplained freezes and dropped calls.</p>
<blockquote><p>Before the good stuff, a couple caveats: I’m not a JavaScript guy. I rely on two devs who work wonders with JS – whereas I curl up and stop functioning, the second I lose strict data-typing and custom classes. A lot of the credit for this method goes to them.</p>
<p>Second, the point of this workaround is to decouple AS and JS and let them run at the same time. Doing this sacrifices the return value you get if you wait for a function to complete before jumping back to the other side of the EI.</p></blockquote>
<p><strong>Step 1. Fix the outbound calls.</strong><br />
The good news first: JS is multithreaded. So if we can get our JS function to run in a different thread than the one targeted by Flash, we can get back to running ActionScript while JS worries about the real work. The secret (thanks to my JS guys!) is JavaScript's setTimeout() function. Here's how it works:</p>
<p>Normally to call a JS function you'd write something like this:</p>
<p><code>
<pre class="actionscript"><ol start="0"><li style="font-family: Monaco, Lucida Console, Lucida, 'Courier New', Courier, monospace; color: white; font-weight: normal; font-style: normal;"><div style="font-family: Monaco, Lucida Console, Lucida, 'Courier New', Courier, monospace; font-weight: normal; "><span style="color: #F7De2D;">const</span> JS_FUNCTION:<span style="color: #FFFFFF;">String</span> = <span style="color: #5FCE3C;">'myJSFunction'</span>;</div></li><li style="font-family: Monaco, Lucida Console, Lucida, 'Courier New', Courier, monospace; color: white; font-weight: normal; font-style: normal;"><div style="font-family: Monaco, Lucida Console, Lucida, 'Courier New', Courier, monospace; font-weight: normal; "><span style="color: #F7De2D;">const</span> ARG:<span style="color: #FFFFFF;">String</span> = <span style="color: #5FCE3C;">'foo'</span>;</div></li><li style="font-family: Monaco, Lucida Console, Lucida, 'Courier New', Courier, monospace; color: white; font-weight: normal; font-style: normal;"><div style="font-family: Monaco, Lucida Console, Lucida, 'Courier New', Courier, monospace; font-weight: normal; ">&nbsp;</div></li><li style="font-family: Monaco, Lucida Console, Lucida, 'Courier New', Courier, monospace; color: white; font-weight: normal; font-style: normal;"><div style="font-family: Monaco, Lucida Console, Lucida, 'Courier New', Courier, monospace; font-weight: normal; "><span style="color: #666666;">//  myJSFunction('foo');</span></div></li><li style="font-family: Monaco, Lucida Console, Lucida, 'Courier New', Courier, monospace; color: white; font-weight: normal; font-style: normal;"><div style="font-family: Monaco, Lucida Console, Lucida, 'Courier New', Courier, monospace; font-weight: normal; ">ExternalInterface.<span style="color: #FFFFFF;">call</span><span style="color: #FFFFFF;">&#40;</span>JS_FUNCTION, ARG<span style="color: #FFFFFF;">&#41;</span>;</div></li></ol></pre>
<p></code></p>
<p>All we need to do is manually construct our JS function signature, and use that as setTimeout’s target:</p>
<p><code>
<pre class="actionscript"><ol start="0"><li style="font-family: Monaco, Lucida Console, Lucida, 'Courier New', Courier, monospace; color: white; font-weight: normal; font-style: normal;"><div style="font-family: Monaco, Lucida Console, Lucida, 'Courier New', Courier, monospace; font-weight: normal; "><span style="color: #F7De2D;">const</span> JS_FUNCTION:<span style="color: #FFFFFF;">String</span> = <span style="color: #5FCE3C;">'myJSFunction'</span>;</div></li><li style="font-family: Monaco, Lucida Console, Lucida, 'Courier New', Courier, monospace; color: white; font-weight: normal; font-style: normal;"><div style="font-family: Monaco, Lucida Console, Lucida, 'Courier New', Courier, monospace; font-weight: normal; "><span style="color: #F7De2D;">const</span> ARG:<span style="color: #FFFFFF;">String</span> = <span style="color: #5FCE3C;">'foo'</span>;</div></li><li style="font-family: Monaco, Lucida Console, Lucida, 'Courier New', Courier, monospace; color: white; font-weight: normal; font-style: normal;"><div style="font-family: Monaco, Lucida Console, Lucida, 'Courier New', Courier, monospace; font-weight: normal; "><span style="color: #F7De2D;">const</span> JS_CALL:<span style="color: #FFFFFF;">String</span> = JS_FUNCTION + <span style="color: #5FCE3C;">'(&quot;'</span> + ARG + <span style="color: #5FCE3C;">'&quot;)'</span>;</div></li><li style="font-family: Monaco, Lucida Console, Lucida, 'Courier New', Courier, monospace; color: white; font-weight: normal; font-style: normal;"><div style="font-family: Monaco, Lucida Console, Lucida, 'Courier New', Courier, monospace; font-weight: normal; ">&nbsp;</div></li><li style="font-family: Monaco, Lucida Console, Lucida, 'Courier New', Courier, monospace; color: white; font-weight: normal; font-style: normal;"><div style="font-family: Monaco, Lucida Console, Lucida, 'Courier New', Courier, monospace; font-weight: normal; "><span style="color: #666666;">//  setTimeout(myJSFunction('foo'), 0);</span></div></li><li style="font-family: Monaco, Lucida Console, Lucida, 'Courier New', Courier, monospace; color: white; font-weight: normal; font-style: normal;"><div style="font-family: Monaco, Lucida Console, Lucida, 'Courier New', Courier, monospace; font-weight: normal; ">ExternalInterface.<span style="color: #FFFFFF;">call</span><span style="color: #FFFFFF;">&#40;</span><span style="color: #5FCE3C;">'setTimeout'</span>, JSCALL, <span style="color: #FFFFFF;">0</span><span style="color: #FFFFFF;">&#41;</span>;</div></li></ol></pre>
<p></code></p>
<p>What does this accomplish? In the first example Flash stops running until foo runs its course. In the second example, Flash is waiting on setTimeout to complete instead. JavaScript will automatically call foo in another thread and return control to Flash, which allows AS to start running again while the foo function can run slowly on the JS side without gumming things up. To see this in action try calling a large empty loop or an alert in JS while you've got some animation going inside Flash.</p>
<p><em>Next post: Inbound calls, custom events, and data validation, oh my!</em></p>
<p><em>continued: <a href="http://www.calypso88.com/?p=26">Unfucking the ExternalInterface (2 of 2) &#8674;</a></em></p>
]]></content:encoded>
			<wfw:commentRss>http://www.calypso88.com/?feed=rss2&amp;p=25</wfw:commentRss>
		<slash:comments>8</slash:comments>
		</item>
		<item>
		<title>A -&gt; B</title>
		<link>http://www.calypso88.com/?p=24</link>
		<comments>http://www.calypso88.com/?p=24#comments</comments>
		<pubDate>Sun, 24 Feb 2008 07:13:00 +0000</pubDate>
		<dc:creator>Rob</dc:creator>
				<category><![CDATA[Actionscript 3.0]]></category>
		<category><![CDATA[Pathfinding]]></category>

		<guid isPermaLink="false">http://www.calypso88.com/?p=24</guid>
		<description><![CDATA[Using a number of better resources, I’ve cobbled together a very basic A* implementation. Currently the path-overlay is disrupting mouse-behavior, and the timer readout is in a weird place in the display-tree (hence the drop-shadow). Still, even though this is a remedial exercise and just the first building-block of something useful, I’m quite happy with [...]]]></description>
			<content:encoded><![CDATA[<p>Using a number of <a href="http://labs.zeh.com.br/blog/?p=8" target="_blank">better</a> <a href="http://www.policyalmanac.org/games/aStarTutorial.htm" target="_blank">resources</a>, I’ve cobbled together a very basic A* implementation. Currently the <del>path-overlay is disrupting mouse-behavior</del>, and the timer readout is in a weird place in the display-tree (hence the drop-shadow). Still, even though this is a remedial exercise and just the first building-block of something useful, I’m quite happy with it.</p>
<p>Click around to create barriers, and drag the start and end markers around the grid. Next step: diagonals!<br />

<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000"
			id="fm_astar_405501081"
			class="flashmovie"
			width="450"
			height="350">
	<param name="movie" value="http://www.calypso88.com/flash/iso_04/astar.swf" />
	<!--[if !IE]>-->
	<object	type="application/x-shockwave-flash"
			data="http://www.calypso88.com/flash/iso_04/astar.swf"
			name="fm_astar_405501081"
			width="450"
			height="350">
	<!--<![endif]-->
		
	<!--[if !IE]>-->
	</object>
	<!--<![endif]-->
</object>
]]></content:encoded>
			<wfw:commentRss>http://www.calypso88.com/?feed=rss2&amp;p=24</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Disaster Strikes</title>
		<link>http://www.calypso88.com/?p=23</link>
		<comments>http://www.calypso88.com/?p=23#comments</comments>
		<pubDate>Fri, 22 Feb 2008 14:59:38 +0000</pubDate>
		<dc:creator>Rob</dc:creator>
				<category><![CDATA[Actionscript 3.0]]></category>
		<category><![CDATA[Pathfinding]]></category>

		<guid isPermaLink="false">http://www.calypso88.com/?p=23</guid>
		<description><![CDATA[I’ve piddled away the better part of a year without touching this project. A few days ago I got motivated to rebuild my code and start implementing A*. The shot below is both an amusing oversight in my code as well as a visual metaphor of exactly how this project is progressing.]]></description>
			<content:encoded><![CDATA[<p>I’ve piddled away the better part of a year without touching this project. A few days ago I got motivated to rebuild my code and start implementing A*. The shot below is both an amusing oversight in my code as well as a visual metaphor of exactly how this project is progressing. <img src="http://www.calypso88.com/wp-content/uploads/2008/02/disaster.jpg" alt="disaster strikes" /></p>
]]></content:encoded>
			<wfw:commentRss>http://www.calypso88.com/?feed=rss2&amp;p=23</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>As the crow flies</title>
		<link>http://www.calypso88.com/?p=20</link>
		<comments>http://www.calypso88.com/?p=20#comments</comments>
		<pubDate>Mon, 28 May 2007 23:01:05 +0000</pubDate>
		<dc:creator>Rob</dc:creator>
				<category><![CDATA[Actionscript 3.0]]></category>
		<category><![CDATA[Pathfinding]]></category>

		<guid isPermaLink="false">http://www.calypso88.com/?p=20</guid>
		<description><![CDATA[The ultimate goal for this project is some sort of tile-based game. To that end I’m working to get a solid pathfinding algorithm in place before anything else. In this version of the isometric grid I have a departure point and a destination represented by a cube and an obelisk respectively. I’ve also made the [...]]]></description>
			<content:encoded><![CDATA[<p>The ultimate goal for this project is some sort of tile-based game. To that end I’m working to get a solid pathfinding algorithm in place before anything else. In this version of the isometric grid I have a departure point and a destination represented by a cube and an obelisk respectively. I’ve also made the grid tiles mutable, ie. clicking on a tile turns it grey and the terrain becomes untraversable.</p>

<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000"
			id="fm_crowflies_62002350"
			class="flashmovie"
			width="450"
			height="350">
	<param name="movie" value="http://www.calypso88.com/flash/iso_03/crowflies.swf" />
	<!--[if !IE]>-->
	<object	type="application/x-shockwave-flash"
			data="http://www.calypso88.com/flash/iso_03/crowflies.swf"
			name="fm_crowflies_62002350"
			width="450"
			height="350">
	<!--<![endif]-->
		
	<!--[if !IE]>-->
	</object>
	<!--<![endif]-->
</object>
<p>The two endpoints are draggable and have code to ‘snap’ them onto whatever tile they stop on. Currently the path is a direct line from A to B and untraversable tiles are ignored. Here's the code: <a href="http://www.calypso88.com/downloads/iso_grid_01.zip">iso_grid_01.zip</a>.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.calypso88.com/?feed=rss2&amp;p=20</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>2 methods, 2 problems</title>
		<link>http://www.calypso88.com/?p=17</link>
		<comments>http://www.calypso88.com/?p=17#comments</comments>
		<pubDate>Mon, 28 May 2007 05:00:56 +0000</pubDate>
		<dc:creator>Rob</dc:creator>
				<category><![CDATA[Actionscript 3.0]]></category>
		<category><![CDATA[Pathfinding]]></category>

		<guid isPermaLink="false">http://www.calypso88.com/?p=17</guid>
		<description><![CDATA[Alright…two takes on hitTest. AS3 has handily given us hitTestObject – true if bounding-boxes overlap – and hitTestPoint, which checks for overlap between one coordinate and the object. It will also take a third parameter to check against either the bounding-box area of the object, or the actual filled shape therein. First off, a test [...]]]></description>
			<content:encoded><![CDATA[<p>Alright…two takes on hitTest. AS3 has handily given us hitTestObject – true if bounding-boxes overlap – and hitTestPoint, which checks for overlap between one coordinate and the object. It will also take a third parameter to check against either the bounding-box area of the object, or the actual filled shape therein.</p>
<p>First off, a test using hitTestObject. Every tile who’s bounding box intersects my little draggable circle will highlight. This is the same issue I had before with AS2 hitTest.</p>

<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000"
			id="fm_busted_1300414157"
			class="flashmovie"
			width="450"
			height="350">
	<param name="movie" value="http://www.calypso88.com/flash/iso_02/busted.swf" />
	<!--[if !IE]>-->
	<object	type="application/x-shockwave-flash"
			data="http://www.calypso88.com/flash/iso_02/busted.swf"
			name="fm_busted_1300414157"
			width="450"
			height="350">
	<!--<![endif]-->
		
	<!--[if !IE]>-->
	</object>
	<!--<![endif]-->
</object>
<p>Now, a somewhat better version which uses the center point of the circle. This one gives much better results but still not quite perfect.</p>

<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000"
			id="fm_gridtest_1875315981"
			class="flashmovie"
			width="450"
			height="350">
	<param name="movie" value="http://www.calypso88.com/flash/iso_02/gridtest.swf" />
	<!--[if !IE]>-->
	<object	type="application/x-shockwave-flash"
			data="http://www.calypso88.com/flash/iso_02/gridtest.swf"
			name="fm_gridtest_1875315981"
			width="450"
			height="350">
	<!--<![endif]-->
		
	<!--[if !IE]>-->
	</object>
	<!--<![endif]-->
</object>
]]></content:encoded>
			<wfw:commentRss>http://www.calypso88.com/?feed=rss2&amp;p=17</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>The jump to AS3</title>
		<link>http://www.calypso88.com/?p=16</link>
		<comments>http://www.calypso88.com/?p=16#comments</comments>
		<pubDate>Sun, 27 May 2007 06:16:26 +0000</pubDate>
		<dc:creator>Rob</dc:creator>
				<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://www.calypso88.com/?p=16</guid>
		<description><![CDATA[From here on out I’m going to be working in ActionScript 3 and hopefully posting a lot more of my code tests.]]></description>
			<content:encoded><![CDATA[<p>From here on out I’m going to be working in ActionScript 3 and hopefully posting a lot more of my code tests.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.calypso88.com/?feed=rss2&amp;p=16</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Back on track</title>
		<link>http://www.calypso88.com/?p=15</link>
		<comments>http://www.calypso88.com/?p=15#comments</comments>
		<pubDate>Sun, 27 May 2007 06:12:37 +0000</pubDate>
		<dc:creator>Rob</dc:creator>
				<category><![CDATA[Pathfinding]]></category>

		<guid isPermaLink="false">http://www.calypso88.com/?p=15</guid>
		<description><![CDATA[After a little digging (and two months of neglect), I’ve got a solution to my hitTest woes. It turns out that hitTest is checking for overlap between the bounding-box of the ball and the bounding-boxes of…pretty much anything else on stage. Since my entire grid is skewed from the traditional cartesian, each tile gets a [...]]]></description>
			<content:encoded><![CDATA[<p>After a little digging (and  two months of neglect), I’ve got a solution to my hitTest woes. It turns out that hitTest is checking for overlap between the bounding-box of the ball and the bounding-boxes of…pretty much anything else on stage. Since my entire grid is skewed from the traditional cartesian, each tile gets a hitspace exactly twice the area of the graphic inside it. In the image below, the blue box shows anywhere that would give a positive hitTest result for the upper-left tile.</p>
<p><img src="http://www.calypso88.com/wp-content/uploads/2007/05/iso-plus.png" alt="Iso plus" /></p>
]]></content:encoded>
			<wfw:commentRss>http://www.calypso88.com/?feed=rss2&amp;p=15</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Isometrics &#8230;</title>
		<link>http://www.calypso88.com/?p=12</link>
		<comments>http://www.calypso88.com/?p=12#comments</comments>
		<pubDate>Sun, 18 Mar 2007 21:34:08 +0000</pubDate>
		<dc:creator>Rob</dc:creator>
				<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://www.calypso88.com/?p=12</guid>
		<description><![CDATA[Playing all the angles When I began I used tiles 100px by 50px. The benefit of this is that all my lines have a slope of ½ so they antialias quite nicely. The downside is that this screws all of my angles. In traditional orthogonal projection, all angles are multiples of 30°, however the 100x50 tiles [...]]]></description>
			<content:encoded><![CDATA[<p><strong>Playing all the angles</strong><br />
When I began I used tiles 100px by 50px. The benefit of this is that all my lines have a slope of ½ so they antialias quite nicely. The downside is that this screws all of my angles. In traditional orthogonal projection, all angles are multiples of 30°, however the 100x50 tiles give me angles somewhere close to 26½°. This will become a larger problem as I develop little geometric characters to roam around on my grid.</p>
<p><strong>Failing the hit test.</strong><br />
The angles have been bugging me for a little while but my real brick wall right now is the hitTest method. My hope was to let characters roam around of their own accord and just worry about whether anyone was on a tile in any given situation. All of these assumptions hinged on the use of the hitTest method. I’ve put a dot on the stage that I'm using to test and it should be giving me a ‘hit’ only for the square it’s over. What I’m actually getting is a positive hit on the tile the dot is overlapping as well as any tile that shares a border with that one. In the screenshot below, all the white tiles are reporting hits...</p>
<p><img src="http://www.calypso88.com/wp-content/uploads/2007/03/hittest-issues.jpg" alt="hittest-issues" /></p>
]]></content:encoded>
			<wfw:commentRss>http://www.calypso88.com/?feed=rss2&amp;p=12</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Isometrics continued</title>
		<link>http://www.calypso88.com/?p=10</link>
		<comments>http://www.calypso88.com/?p=10#comments</comments>
		<pubDate>Mon, 12 Mar 2007 00:02:44 +0000</pubDate>
		<dc:creator>Rob</dc:creator>
				<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://www.calypso88.com/?p=10</guid>
		<description><![CDATA[The best laid plans I’ve got a test case running perfectly. However I did have to alter my plans from yesterday for the ordering. To maintain the correct z-indexing, I generated each row in order, but the children of each row in reverse. Here’s a working sample, roll over each tile to see it’s position. [...]]]></description>
			<content:encoded><![CDATA[<p><strong>The best laid plans</strong><br />
I’ve got a test case running perfectly. However I did have to alter my plans from yesterday for the ordering. To maintain the correct z-indexing, I generated each row in order, but the children of each row in reverse. Here’s a working sample, roll over each tile to see it’s position. The code generated the tiles in this order: [(0,3)  (0,2)   (0,1)  (0,0)] [(1,3)  (1,2)  (1,1)  (1,0)] ...</p>

<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000"
			id="fm_test_615275788"
			class="flashmovie"
			width="450"
			height="250">
	<param name="movie" value="http://www.calypso88.com/flash/iso_01/test.swf" />
	<!--[if !IE]>-->
	<object	type="application/x-shockwave-flash"
			data="http://www.calypso88.com/flash/iso_01/test.swf"
			name="fm_test_615275788"
			width="450"
			height="250">
	<!--<![endif]-->
		
	<!--[if !IE]>-->
	</object>
	<!--<![endif]-->
</object>
]]></content:encoded>
			<wfw:commentRss>http://www.calypso88.com/?feed=rss2&amp;p=10</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Isometrics &#8211; 01</title>
		<link>http://www.calypso88.com/?p=5</link>
		<comments>http://www.calypso88.com/?p=5#comments</comments>
		<pubDate>Sat, 10 Mar 2007 19:23:24 +0000</pubDate>
		<dc:creator>Rob</dc:creator>
				<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://www.calypso88.com/?p=5</guid>
		<description><![CDATA[I’ve never worked with an isometric grid before so I’m shooting low. I’d like to knock together a simple iso field with some interactivity for testing. I just opened up Flash and TextMate and Im planning out two classes. IsoGrid Take grid dimensions (width, height) Generate IsoBlocks Place blocks IsoBlock Take block dimensions (width, height, [...]]]></description>
			<content:encoded><![CDATA[<p>I’ve never worked with an isometric grid before so I’m shooting low. I’d like to knock together a simple iso field with some interactivity for testing. I just opened up Flash and <a href="http://macromates.com/">TextMate</a> and Im planning out two classes.</p>
<blockquote><p><strong>IsoGrid</strong><br />
Take grid dimensions (width, height)<br />
Generate IsoBlocks<br />
Place blocks</p>
<p><strong>IsoBlock</strong><br />
Take block dimensions (width, height, depth(?))<br />
Draw fill<br />
Draw stroke<br />
Know it’s own position (x,y)<br />
Set mouseOver effects</p></blockquote>
<p><strong>Stumbling blocks already…</strong></p>
<p>To prevent later aggrevation, I’ll say that the northwest face on each block is the ‘top’, and the northeast face will be ‘right.’ With that in mind, I can say that an IsoGrid(50, 100) would generate 50 blocks to the northeast, and 100 blocks to the southeast of the initial block.</p>
<blockquote><p><img src="http://www.calypso88.com/wp-content/uploads/2007/03/iso_01.png" alt="iso_01" /></p></blockquote>
<p>Additionally, since it’s a little odd to have each block’s origin at the top-left of the movieClip, I’ll modify my drawing method so I can keep the origin at the center of each block.</p>
<p><img src="http://www.calypso88.com/wp-content/uploads/2007/03/iso_mc.png" alt="iso_02" /></p>
]]></content:encoded>
			<wfw:commentRss>http://www.calypso88.com/?feed=rss2&amp;p=5</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Day: the first</title>
		<link>http://www.calypso88.com/?p=3</link>
		<comments>http://www.calypso88.com/?p=3#comments</comments>
		<pubDate>Fri, 09 Mar 2007 16:50:21 +0000</pubDate>
		<dc:creator>Rob</dc:creator>
				<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://www.calypso88.com/?p=3</guid>
		<description><![CDATA[This space will be a collection of my ActionScript trials, successes, and (mostly) failures. I will use this space to document my code and processes. This site is for my own reference and tinkering, but if my work happens to help someone else out, so much the better.]]></description>
			<content:encoded><![CDATA[<p>This space will be a collection of my ActionScript trials, successes, and (mostly) failures. I will use this space to document my code and processes. This site is for my own reference and tinkering, but if my work happens to help someone else out, so much the better.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.calypso88.com/?feed=rss2&amp;p=3</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
