<?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>Destroy Today &#187; AS3</title>
	<atom:link href="http://destroytoday.com/blog/tag/as3/feed/" rel="self" type="application/rss+xml" />
	<link>http://destroytoday.com/blog</link>
	<description>Jonnie is back to work.</description>
	<lastBuildDate>Fri, 19 Mar 2010 16:48:38 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.8.4</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>Encoding for OAuth using AS3</title>
		<link>http://destroytoday.com/blog/2010/02/encoding-for-oauth-using-as3/</link>
		<comments>http://destroytoday.com/blog/2010/02/encoding-for-oauth-using-as3/#comments</comments>
		<pubDate>Mon, 01 Mar 2010 02:00:08 +0000</pubDate>
		<dc:creator>Jonnie</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[AS3]]></category>
		<category><![CDATA[Code]]></category>
		<category><![CDATA[Programming]]></category>

		<guid isPermaLink="false">http://destroytoday.com/blog/?p=1754</guid>
		<description><![CDATA[AS3 has a few useful URL-related methods, like escape/unescape and encodeURI/decodeURI, but it doesn&#8217;t have a plain-and-simple encodeUTF8 function. The encodeURIComponent method encodes a string to UTF-8, but URL-encodes it as well, requiring the unescape method to wrap the call. Many developers have resorted to writing their own encodeUTF8 method, looping through each character and [...]]]></description>
			<content:encoded><![CDATA[<p>AS3 has a few useful URL-related methods, like <em>escape</em>/<em>unescape</em> and <em>encodeURI</em>/<em>decodeURI</em>, but it doesn&#8217;t have a plain-and-simple <em>encodeUTF8</em> function. The <em>encodeURIComponent</em> method encodes a string to UTF-8, but URL-encodes it as well, requiring the <em>unescape</em> method to wrap the call. Many developers have resorted to writing their own <em>encodeUTF8</em> method, looping through each character and converting with bitwise. I&#8217;ve found this to be unreliable at times after pinpointing an issue with the OAuth lib I use(d) with <a href="http://github.com/destroytoday/TwitterAspirin" target="_blank">TwitterAspirin</a>. I came across a number of problems, specifically dealing with <em>POST</em> methods and incorrect signatures, so I decided to take a night to write my own OAuth request signer.</p>
<p>In a search to better understand the <a href="http://oauth.net/core/1.0/" target="_blank">OAuth spec</a>, I came across <a href="http://hueniverse.com/2008/10/beginners-guide-to-oauth-part-iv-signing-requests/" target="_blank">this terrific tutorial</a> on OAuth by <a href="http://hueniverse.com/author/eran/" target="_blank">Eran Hammer-Lahav</a> on <a href="http://hueniverse.com/" target="_blank">Hueniverse</a>. It is hands-down the most useful tutorial I have found on the subject, translating the OAuth spec for the &#8220;English-speaking&#8221; and providing a foolproof explanation for each step. The tutorial also provides input fields for each step, so you can manually input your keys, secrets, and tokens, and see if your result matches up.</p>
<p>The main reason this tutorial is so helpful is its emphasis on the UTF-8 encoding. Sure, the OAuth spec indicates the unreserved characters, but this tutorial stresses that most languages do not share the same unreserved characters—this is true for AS3. The following characters are listed as unreserved in the OAuth Core 1.0 spec:</p>

<div class="wp_syntax"><div class="code"><pre class="" style="font-family:monospace;">A B C D E F G H I J K L M N O P Q R S T U V W X Y Z
a b c d e f g h i j k l m n o p q r s t u v w x y z
<span style="">0</span> <span style="">1</span> <span style="">2</span> <span style="">3</span> <span style="">4</span> <span style="">5</span> <span style="">6</span> <span style="">7</span> <span style="">8</span> <span style="">9</span> - . _ ~</pre></div></div>

<p>Compare this with the unreserved characters of AS3&#8217;s escape method:</p>

<div class="wp_syntax"><div class="code"><pre class="" style="font-family:monospace;">A B C D E F G H I J K L M N O P Q R S T U V W X Y Z
a b c d e f g h i j k l m n o p q r s t u v w x y z
<span style="">0</span> <span style="">1</span> <span style="">2</span> <span style="">3</span> <span style="">4</span> <span style="">5</span> <span style="">6</span> <span style="">7</span> <span style="">8</span> <span style="">9</span> @ - _ . * + /</pre></div></div>

<p>And again with the unreserved characters of AS3&#8217;s encodeURIComponent method:</p>

<div class="wp_syntax"><div class="code"><pre class="" style="font-family:monospace;">A B C D E F G H I J K L M N O P Q R S T U V W X Y Z
a b c d e f g h i j k l m n o p q r s t u v w x y z
<span style="">0</span> <span style="">1</span> <span style="">2</span> <span style="">3</span> <span style="">4</span> <span style="">5</span> <span style="">6</span> <span style="">7</span> <span style="">8</span> <span style="">9</span> - _ . ! ~ * ' <span class="br0">&#40;</span> <span class="br0">&#41;</span></pre></div></div>

<p>As you can see, a solid amount of work is needed to match the unreserved characters listed in the OAuth spec. At the moment, this is the gargantuan series of method calls I use to properly encode the parameters used in an OAuth-related request:</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
</pre></td><td class="code"><pre class="actionscript3" style="font-family:monospace;"><span style="color: #0000FF;">protected</span> <span style="color: #FF0000;">function</span> encode<span style="color: #000000;">&#40;</span>str<span style="color: #000000;">:</span><span style="color: #000000;">String</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">:</span><span style="color: #000000;">String</span> <span style="color: #000000;">&#123;</span>
	<span style="color: #0000FF;">return</span> <span style="color: #FF0000;">escape</span><span style="color: #000000;">&#40;</span><span style="color: #FF0000;">unescape</span><span style="color: #000000;">&#40;</span><span style="color: #FF0000;">encodeURIComponent</span><span style="color: #000000;">&#40;</span>str<span style="color: #000000;">&#41;</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">&#41;</span>.<span style="color: #FF0000;">replace</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">/%</span>7E<span style="color: #000000;">/</span>g, <span style="color: #666666;">'~'</span><span style="color: #000000;">&#41;</span>.<span style="color: #FF0000;">replace</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">/</span>@<span style="color: #000000;">/</span>g, <span style="color: #666666;">'%40'</span><span style="color: #000000;">&#41;</span>.<span style="color: #FF0000;">replace</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">/</span>\<span style="color: #000000;">*/</span>g, <span style="color: #666666;">'%2A'</span><span style="color: #000000;">&#41;</span>.<span style="color: #FF0000;">replace</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">/</span>\<span style="color: #000000;">+/</span>g, <span style="color: #666666;">'%2B'</span><span style="color: #000000;">&#41;</span>.<span style="color: #FF0000;">replace</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">/</span>\<span style="color: #FF0099;">//g, '%2F');</span>
<span style="color: #000000;">&#125;</span></pre></td></tr></table></div>

<p>I know what you&#8217;re thinking—Jonnie has lost his marbles and the proof is that <em>unescape</em> method call wrapped in the <em>escape</em> method call. Believe me when I tell you it&#8217;s necessary. Why?—because of the additional unreserved characters in the <em>encodeURIComponent</em> method. The <em>unescape</em> method removes the URL encoding, so it&#8217;s just UTF-8 encoded at this point. Then, the <em>escape</em> method re-URL-encodes the string, but this time converts the additional unreserved characters as well. Now, I&#8217;m left with a half dozen replace method calls to convert the last few characters that aren&#8217;t in the OAuth spec. (If you know a way to combine all of these replace method calls into one, let me know! Regular expressions are slow in AS3)</p>
<p>I really hope this helps those venturing into the dark world of OAuth, and as always, my OAuth request signer can be found among the changes pushed to TwitterAspirin on GitHub. I also updated <a href="http://github.com/destroytoday/TwitterAspirinDemo" target="_blank">TwitterAspirinDemo</a> to show how to use the library. Feel free to watch or fork either repo—both will see a lot of activity over the next few weeks.</p>
]]></content:encoded>
			<wfw:commentRss>http://destroytoday.com/blog/2010/02/encoding-for-oauth-using-as3/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Dwarf adds unit types and tool position to its arsenal</title>
		<link>http://destroytoday.com/blog/2010/02/dwarf-adds-unit-types-and-tool-position-to-its-arsenal/</link>
		<comments>http://destroytoday.com/blog/2010/02/dwarf-adds-unit-types-and-tool-position-to-its-arsenal/#comments</comments>
		<pubDate>Sun, 14 Feb 2010 19:03:00 +0000</pubDate>
		<dc:creator>Jonnie</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[AIR]]></category>
		<category><![CDATA[Announcement]]></category>
		<category><![CDATA[AS3]]></category>
		<category><![CDATA[Dwarf]]></category>

		<guid isPermaLink="false">http://destroytoday.com/blog/?p=1739</guid>
		<description><![CDATA[
I&#8217;ve been working on Dwarf little by little and finally built one of the most requested features—unit types. The five available unit types are pixels, picas, centimeters, inches, and percent. Inches have dotted lines for quarter inches and percent always displays 100% on the ruler, but scales its grid to show ten columns and ten [...]]]></description>
			<content:encoded><![CDATA[<p><a href="http://github.com/destroytoday/Dwarf/downloads"><img class="alignnone size-full wp-image-1740" title="Dwarf unit types" src="http://destroytoday.com/blog/wp-content/uploads/2010/02/dwarf_units.gif" alt="Dwarf unit types" width="645" height="430" /></a></p>
<p>I&#8217;ve been working on <a href="http://github.com/destroytoday/Dwarf/downloads" target="_blank">Dwarf</a> little by little and finally built one of the most requested features—unit types. The five available unit types are pixels, picas, centimeters, inches, and percent. Inches have dotted lines for quarter inches and percent always displays 100% on the ruler, but scales its grid to show ten columns and ten rows. At the moment, the units are based on a 72 dpi screen, but I&#8217;ll be adding an option to change the dpi, since most screens aren&#8217;t 72. If anyone has suggestions for that other than using a list, let me know.</p>
<p><a href="http://github.com/destroytoday/Dwarf/downloads"><img class="alignnone size-full wp-image-1741" title="dwarf_units_toolbar" src="http://destroytoday.com/blog/wp-content/uploads/2010/02/dwarf_units_toolbar.jpg" alt="dwarf_units_toolbar" width="645" height="100" /></a></p>
<p>The unit type is selected by clicking the menu at the right of the toolbar. It prompts a context menu with the options. Dwarf remembers which unit type you used last, so it&#8217;ll remain the same next time you startup. Along with unit types, I included positions and dimensions in the toolbar. This is mostly for the position, but I thought dimensions look nice up there too. At the moment, the position is in relation to the main screen, but the next build improves multi-screen support. You will be able to specify which screen to relate the position to. This also comes in handy for moving guides from screen to screen.</p>
<p>If you&#8217;re already a Dwarf user, start up for the update, or <a href="http://github.com/destroytoday/Dwarf/downloads" target="_blank">download it</a> from GitHub. And, as always, let me know what you think in the comments.</p>
]]></content:encoded>
			<wfw:commentRss>http://destroytoday.com/blog/2010/02/dwarf-adds-unit-types-and-tool-position-to-its-arsenal/feed/</wfw:commentRss>
		<slash:comments>6</slash:comments>
		</item>
		<item>
		<title>Dwarf gets new life and is now open source</title>
		<link>http://destroytoday.com/blog/2010/01/dwarf-gets-new-life-and-is-now-open-source/</link>
		<comments>http://destroytoday.com/blog/2010/01/dwarf-gets-new-life-and-is-now-open-source/#comments</comments>
		<pubDate>Mon, 25 Jan 2010 16:18:30 +0000</pubDate>
		<dc:creator>Jonnie</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[AIR]]></category>
		<category><![CDATA[Announcement]]></category>
		<category><![CDATA[AS3]]></category>
		<category><![CDATA[Dwarf]]></category>
		<category><![CDATA[Programming]]></category>

		<guid isPermaLink="false">http://destroytoday.com/blog/?p=1716</guid>
		<description><![CDATA[
A recent AIR prerelease drop broke Dwarf. I&#8217;m actually not surprised, since it uses a pretty ghetto hack—displaying a transparent window fullscreen and using &#8216;virtual&#8217; windows. Because Dwarf is such an integral part of my everyday workflow and it&#8217;s such a small app, I figured I could easily rewrite it within a day or two. [...]]]></description>
			<content:encoded><![CDATA[<p><img class="alignnone size-full wp-image-1717" title="Dwarf on Git" src="http://destroytoday.com/blog/wp-content/uploads/2010/01/dwarf_on_git.gif" alt="Dwarf on Git" width="645" height="430" /></p>
<p>A recent AIR prerelease drop broke Dwarf. I&#8217;m actually not surprised, since it uses a pretty ghetto hack—displaying a transparent window fullscreen and using &#8216;virtual&#8217; windows. Because Dwarf is such an integral part of my everyday workflow and it&#8217;s such a small app, I figured I could easily rewrite it within a day or two. I&#8217;ve been on such a code-sharing high, that I started <a href="http://github.com/destroytoday/Dwarf" target="_blank">a new Git repository for it</a> where you can find my work in progress. So far, I have a single ruler working with a semi-functional Mac toolbar. Everything should be complete either tonight or tomorrow, so keep an eye out.</p>
<p>On a legal note, the source code is provided under the <a href="http://github.com/destroytoday/Dwarf/blob/master/README" target="_blank">GNU General Public License (GPL)</a>, so you can reuse and modify the code all you want as long as it&#8217;s still free. If you&#8217;d like to use it for commercial purposes, let&#8217;s talk.</p>
]]></content:encoded>
			<wfw:commentRss>http://destroytoday.com/blog/2010/01/dwarf-gets-new-life-and-is-now-open-source/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>EventMap.mapListener bug (and fix!) in RobotLegs</title>
		<link>http://destroytoday.com/blog/2010/01/eventmap-maplistener-bug-and-fix-in-robotlegs/</link>
		<comments>http://destroytoday.com/blog/2010/01/eventmap-maplistener-bug-and-fix-in-robotlegs/#comments</comments>
		<pubDate>Sun, 24 Jan 2010 02:38:31 +0000</pubDate>
		<dc:creator>Jonnie</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[AS3]]></category>
		<category><![CDATA[Code]]></category>
		<category><![CDATA[Programming]]></category>
		<category><![CDATA[Quick Fix]]></category>

		<guid isPermaLink="false">http://destroytoday.com/blog/?p=1708</guid>
		<description><![CDATA[This past week, I experienced a bug with RobotLegs where the EventMap.mapListener method would add the listener multiple times if called multiple times. Yesterday, I had some free time to dig a little deeper and managed to pinpoint the problematic code. It turns out the method didn&#8217;t check to see if the listener existed prior [...]]]></description>
			<content:encoded><![CDATA[<p>This past week, I experienced a bug with <a href="http://robotlegs.org/" target="_blank">RobotLegs</a> where the <em>EventMap.mapListener</em> method would add the listener multiple times if called multiple times. Yesterday, I had some free time to dig a little deeper and managed to pinpoint the problematic code. It turns out the method didn&#8217;t check to see if the listener existed prior to adding to the array. This explains why a button click handler in my code would respond twice.</p>
<p>Thanks to the oh-so-wonderful <a href="http://github.com" target="_blank">GitHub</a>, I was able to fork the repository, implement the fix, write a unit test to verify it&#8217;s safe, and find in the morning that it has been integrated into the actual <a href="http://github.com/robotlegs/robotlegs-framework" target="_blank">RobotLegs repository</a>—just like that. If you experienced the bug, be sure to pull the latest commit.</p>
<p>Now, if you&#8217;re not on GitHub, do yourself a favor and join today. In the few months I&#8217;ve been a member, I&#8217;ve met a handful of incredible developers and now feel compelled to share code when I can. Everyone benefits when you share what you know.</p>
]]></content:encoded>
			<wfw:commentRss>http://destroytoday.com/blog/2010/01/eventmap-maplistener-bug-and-fix-in-robotlegs/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Introducing TwitterAspirin: an AS3 Twitter API painkiller</title>
		<link>http://destroytoday.com/blog/2010/01/introducing-twitteraspirin-an-as3-twitter-api-painkiller/</link>
		<comments>http://destroytoday.com/blog/2010/01/introducing-twitteraspirin-an-as3-twitter-api-painkiller/#comments</comments>
		<pubDate>Thu, 21 Jan 2010 15:01:58 +0000</pubDate>
		<dc:creator>Jonnie</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[AIR]]></category>
		<category><![CDATA[Announcement]]></category>
		<category><![CDATA[AS3]]></category>
		<category><![CDATA[Code]]></category>
		<category><![CDATA[DestroyTwitter]]></category>
		<category><![CDATA[Programming]]></category>
		<category><![CDATA[Twitter]]></category>

		<guid isPermaLink="false">http://destroytoday.com/blog/?p=1704</guid>
		<description><![CDATA[A couple months ago, I started working on a Twitter component for my current project at Adobe. I went into this knowing I&#8217;d have to finally face the beast&#8230; OAuth. Just about every well-known Twitter client out there uses Basic Auth—and for a reason. It&#8217;s easy, what the user expects, and gives your app more [...]]]></description>
			<content:encoded><![CDATA[<p>A couple months ago, I started working on a Twitter component for my current project at Adobe. I went into this knowing I&#8217;d have to finally face the beast&#8230; OAuth. Just about every well-known Twitter client out there uses Basic Auth—and for a reason. It&#8217;s easy, what the user expects, and gives your app more credibility—there&#8217;s no requirement to leave to authenticate through the browser like with OAuth.</p>
<p>About five or six months ago, Twitter decided to enforce the transition. From then on, any application that uses the API must use OAuth in order to see &#8220;via [your app]&#8221; on tweets published with it—otherwise, it would display &#8220;via API.&#8221; Since &#8220;via&#8221; is where apps get probably 90% of their referrals, this was a big deal. Luckily for me, <a href="http://destroytwitter.com" target="_blank">DestroyTwitter</a> existed before that time and Twitter decided not to push the change on the veteran apps. Recently, however, the bad news spread that Basic Auth would be deprecated in June. This means every Twitter app must transition to the pain that is OAuth.</p>
<p>After developing the <a href="http://destroytoday.com/blog/2009/10/adobe-max-companion-launched/" target="_blank">MAX Companion</a> this past fall and now the more generalized version, I found myself rewriting the Twitter component each time. After a while, the Twitter API code I wrote for DestroyTwitter began to merge with the actual implementation, so it was no longer a standalone library that could easily be used by other projects. These past few months, I&#8217;ve been learning a great deal about framework architecture and design patterns. It has led me to realize I need to start fresh.</p>
<p>With all that being said, I&#8217;d like introduce a library I started working on two days ago. I call it <a href="http://github.com/destroytoday/TwitterAspirin" target="_blank">TwitterAspirin</a>. It&#8217;s an AS3 Twitter API library that eases the pain, providing developers with a very powerful tool for communicating with Twitter. Though it&#8217;s still a newborn at the moment, I see potential already. The library is built on <a href="http://robotlegs.org/" target="_blank">RobotLegs</a> and uses <a href="http://github.com/robertpenner/as3-signals" target="_blank">AS3 Signals</a> instead of events. It&#8217;s hosted on <a href="http://github.com" target="_blank">GitHub</a>, so the source code will always be available to the public. And, after last night&#8217;s commit, its OAuth functionality is complete. Here&#8217;s how to use it:</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
</pre></td><td class="code"><pre class="actionscript3" style="font-family:monospace;"><span style="color: #0000FF;">package</span> <span style="color: #000000;">&#123;</span>
	<span style="color: #0000FF;">import</span> com.destroytoday.twitteraspirin.Twitter;
&nbsp;
	<span style="color: #0000FF;">import</span> <span style="color: #000000;">flash.display</span>.<span style="color: #000000;">Sprite</span>;
&nbsp;
	<span style="color: #0000FF;">public</span> <span style="color: #0000FF;">class</span> Test extends <span style="color: #000000;">Sprite</span> <span style="color: #000000;">&#123;</span>
		<span style="color: #FF0099;">// set application consumer key and secret</span>
		<span style="color: #0000FF;">public</span> <span style="color: #FF0000;">var</span> twitter<span style="color: #000000;">:</span>Twitter = <span style="color: #0000FF;">new</span> Twitter<span style="color: #000000;">&#40;</span>consumerKey, consumerSecret<span style="color: #000000;">&#41;</span>;
&nbsp;
		<span style="color: #0000FF;">public</span> <span style="color: #FF0000;">function</span> Test<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span> <span style="color: #000000;">&#123;</span>
			<span style="color: #FF0099;">// add signal listeners</span>
			twitter.oauth.requestTokenSignal.<span style="color: #FF0000;">add</span><span style="color: #000000;">&#40;</span>requestTokenHandler<span style="color: #000000;">&#41;</span>;
			twitter.oauth.accessTokenSignal.<span style="color: #FF0000;">add</span><span style="color: #000000;">&#40;</span>accessTokenHandler<span style="color: #000000;">&#41;</span>;
			twitter.oauth.verifyAccessTokenSignal.<span style="color: #FF0000;">add</span><span style="color: #000000;">&#40;</span>verifyAccessTokenHandler<span style="color: #000000;">&#41;</span>;
		<span style="color: #000000;">&#125;</span>
&nbsp;
		<span style="color: #FF0099;">// click the 'Authorize' button to get the request token</span>
		<span style="color: #0000FF;">protected</span> <span style="color: #FF0000;">function</span> authorizeClickHandler<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">:</span><span style="color: #0000FF;">void</span> <span style="color: #000000;">&#123;</span>
			twitter.oauth.getRequestToken<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>;
		<span style="color: #000000;">&#125;</span>
&nbsp;
		<span style="color: #FF0099;">// upon receiving the request token, open Twitter in the browser to authorize</span>
		<span style="color: #0000FF;">protected</span> <span style="color: #FF0000;">function</span> requestTokenHandler<span style="color: #000000;">&#40;</span>oauth<span style="color: #000000;">:</span>OAuth, token<span style="color: #000000;">:</span>OAuthToken<span style="color: #000000;">&#41;</span><span style="color: #000000;">:</span><span style="color: #0000FF;">void</span> <span style="color: #000000;">&#123;</span>
			<span style="color: #FF0000;">navigateToURL</span><span style="color: #000000;">&#40;</span><span style="color: #0000FF;">new</span> <span style="color: #000000;">URLRequest</span><span style="color: #000000;">&#40;</span>oauth.getAuthorizeURL<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">&#41;</span>;
		<span style="color: #000000;">&#125;</span>
&nbsp;
		<span style="color: #FF0099;">// return with the provided pin and click the 'Activate' button to get the access token</span>
		<span style="color: #0000FF;">protected</span> <span style="color: #FF0000;">function</span> activateClickHandler<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">:</span><span style="color: #0000FF;">void</span> <span style="color: #000000;">&#123;</span>
			twitter.oauth.getAccessToken<span style="color: #000000;">&#40;</span>pin<span style="color: #000000;">&#41;</span>;
		<span style="color: #000000;">&#125;</span>
&nbsp;
		<span style="color: #FF0099;">// upon receiving the access token, verify it</span>
		<span style="color: #0000FF;">protected</span> <span style="color: #FF0000;">function</span> accessTokenHandler<span style="color: #000000;">&#40;</span>oauth<span style="color: #000000;">:</span>OAuth, token<span style="color: #000000;">:</span>OAuthToken<span style="color: #000000;">&#41;</span><span style="color: #000000;">:</span><span style="color: #0000FF;">void</span> <span style="color: #000000;">&#123;</span>
			oauth.verifyAccessToken<span style="color: #000000;">&#40;</span>token<span style="color: #000000;">&#41;</span>;
		<span style="color: #000000;">&#125;</span>
&nbsp;
		<span style="color: #FF0099;">// done</span>
		<span style="color: #0000FF;">protected</span> <span style="color: #FF0000;">function</span> verifyAccessTokenHandler<span style="color: #000000;">&#40;</span>oauth<span style="color: #000000;">:</span>OAuth, token<span style="color: #000000;">:</span>OAuthToken<span style="color: #000000;">&#41;</span><span style="color: #000000;">:</span><span style="color: #0000FF;">void</span> <span style="color: #000000;">&#123;</span>
		<span style="color: #000000;">&#125;</span>
	<span style="color: #000000;">&#125;</span>
<span style="color: #000000;">&#125;</span></pre></td></tr></table></div>

<p>As you can see, it&#8217;s extremely easy to use. Not only that, it provides great flexibility. Many libraries are simple to implement, but don&#8217;t allow the developer access to certain aspects of the process. With TwitterAspirin, each method returns the loader involved with the operation, giving developers the ability to listen for errors, cancel the operation, or attain the raw API data. The library also uses loader pools to recycle instances, so you can submit a tweet and, while it&#8217;s loading, submit another—you don&#8217;t have to wait for the first operation to finish. Then, once the operation is complete, the loader is disposed and returned to the pool, which optimizes performance and memory usage.</p>
<p>I&#8217;m really excited to see where TwitterAspirin goes and I have nothing but great expectations. Be sure to follow along with development and fork whenever you like.</p>
]]></content:encoded>
			<wfw:commentRss>http://destroytoday.com/blog/2010/01/introducing-twitteraspirin-an-as3-twitter-api-painkiller/feed/</wfw:commentRss>
		<slash:comments>14</slash:comments>
		</item>
		<item>
		<title>Introducing the XMLLoader class</title>
		<link>http://destroytoday.com/blog/2010/01/introducing-the-xmlloader-class/</link>
		<comments>http://destroytoday.com/blog/2010/01/introducing-the-xmlloader-class/#comments</comments>
		<pubDate>Tue, 19 Jan 2010 14:43:45 +0000</pubDate>
		<dc:creator>Jonnie</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[AIR]]></category>
		<category><![CDATA[Announcement]]></category>
		<category><![CDATA[AS3]]></category>
		<category><![CDATA[Code]]></category>
		<category><![CDATA[Programming]]></category>

		<guid isPermaLink="false">http://destroytoday.com/blog/?p=1700</guid>
		<description><![CDATA[I started the XMLLoader class a few months back, but didn&#8217;t post right away because it needed a lot of cleanup. Not cleanup in the sense of performance improvement or refactoring—it simply used my old programming style, full of dollar signs and underscores. If anyone remembers seeing my code in that form, I deeply apologize [...]]]></description>
			<content:encoded><![CDATA[<p>I started the <a href="http://github.com/destroytoday/DestroyFramework/blob/master/src/com/destroytoday/net/XMLLoader.as" target="_blank">XMLLoader</a> class a few months back, but didn&#8217;t post right away because it needed a lot of cleanup. Not cleanup in the sense of performance improvement or refactoring—it simply used my old programming style, full of dollar signs and underscores. If anyone remembers seeing my code in that form, I deeply apologize for the pain it must have caused your eyes.</p>
<p>So why an <em>XMLLoader</em> class?—because 99% of the data I load with AS3/AIR is in XML format. I stay far from JSON when possible because in AS3 it&#8217;s slower than a slug on its day off. XML is native and uses E4X, which lets developers navigate its information just like you would an AS3 tree. I load XML so often, I found myself copying and pasting the same code each time I&#8217;d need it—this is the clearest indicator that a class must be written.</p>
<p>Parsing String data to XML poses an issue that many don&#8217;t know about. I only discovered it because of the Twitter API. The API is so janked, it sometimes returns the HTML error page instead of the XML response. It wouldn&#8217;t be so bad if it weren&#8217;t for an image tag in the HTML that isn&#8217;t closed. This immediately throws an &#8220;XML parser failure: element is malformed&#8221; error. Using try/catch is the only way to avoid this. That&#8217;s why I wrote it into <em>XMLLoader</em>. It automatically handles the data, attempts to parse it, and, if there are any errors, the load stops and dispatches an error signal.</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
</pre></td><td class="code"><pre class="actionscript3" style="font-family:monospace;"><span style="color: #0000FF;">package</span> <span style="color: #000000;">&#123;</span>
	<span style="color: #0000FF;">import</span> com.destroytoday.net.XMLLoader;
&nbsp;
	<span style="color: #0000FF;">import</span> <span style="color: #000000;">flash.display</span>.<span style="color: #000000;">Sprite</span>;
&nbsp;
	<span style="color: #0000FF;">public</span> <span style="color: #0000FF;">class</span> Test extends <span style="color: #000000;">Sprite</span> <span style="color: #000000;">&#123;</span>
		<span style="color: #0000FF;">public</span> <span style="color: #FF0000;">var</span> <span style="color: #FF0000;">loader</span><span style="color: #000000;">:</span>XMLLoader;
&nbsp;
		<span style="color: #0000FF;">public</span> <span style="color: #FF0000;">function</span> Test<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span> <span style="color: #000000;">&#123;</span>
			<span style="color: #FF0000;">loader</span> = <span style="color: #0000FF;">new</span> XMLLoader<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>;
&nbsp;
			<span style="color: #FF0000;">loader</span>.retryCount = <span style="color: #000000;">2</span>;
			<span style="color: #FF0000;">loader</span>.includeResponseInfo = <span style="color: #0000FF;">true</span>;
&nbsp;
			<span style="color: #FF0000;">loader</span>.openSignal.<span style="color: #FF0000;">add</span><span style="color: #000000;">&#40;</span>loaderOpenHandler<span style="color: #000000;">&#41;</span>;
			<span style="color: #FF0000;">loader</span>.completeSignal.<span style="color: #FF0000;">add</span><span style="color: #000000;">&#40;</span>loaderCompleteHandler<span style="color: #000000;">&#41;</span>;
			<span style="color: #FF0000;">loader</span>.errorSignal.<span style="color: #FF0000;">add</span><span style="color: #000000;">&#40;</span>loaderErrorHandler<span style="color: #000000;">&#41;</span>;
&nbsp;
			<span style="color: #FF0000;">loader</span>.<span style="color: #FF0000;">load</span><span style="color: #000000;">&#40;</span><span style="color: #666666;">&quot;http://search.twitter.com/search.atom?q=destroytoday&quot;</span><span style="color: #000000;">&#41;</span>;
		<span style="color: #000000;">&#125;</span>
&nbsp;
		<span style="color: #0000FF;">protected</span> <span style="color: #FF0000;">function</span> loaderOpenHandler<span style="color: #000000;">&#40;</span><span style="color: #FF0000;">loader</span><span style="color: #000000;">:</span>XMLLoader<span style="color: #000000;">&#41;</span><span style="color: #000000;">:</span><span style="color: #0000FF;">void</span> <span style="color: #000000;">&#123;</span>
			<span style="color: #FF0000;">trace</span><span style="color: #000000;">&#40;</span><span style="color: #FF0000;">loader</span><span style="color: #000000;">&#41;</span>;
		<span style="color: #000000;">&#125;</span>
&nbsp;
		<span style="color: #0000FF;">protected</span> <span style="color: #FF0000;">function</span> loaderCompleteHandler<span style="color: #000000;">&#40;</span><span style="color: #FF0000;">loader</span><span style="color: #000000;">:</span>XMLLoader, <span style="color: #FF0000;">data</span><span style="color: #000000;">:</span><span style="color: #000000;">XML</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">:</span><span style="color: #0000FF;">void</span> <span style="color: #000000;">&#123;</span>
			<span style="color: #FF0000;">trace</span><span style="color: #000000;">&#40;</span><span style="color: #FF0000;">loader</span>, <span style="color: #FF0000;">data</span><span style="color: #000000;">&#41;</span>;
		<span style="color: #000000;">&#125;</span>
&nbsp;
		<span style="color: #0000FF;">protected</span> <span style="color: #FF0000;">function</span> loaderErrorHandler<span style="color: #000000;">&#40;</span><span style="color: #FF0000;">loader</span><span style="color: #000000;">:</span>XMLLoader, <span style="color: #FF0000;">error</span><span style="color: #000000;">:</span><span style="color: #000000;">String</span>, <span style="color: #FF0000;">message</span><span style="color: #000000;">:</span><span style="color: #000000;">String</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">:</span><span style="color: #0000FF;">void</span> <span style="color: #000000;">&#123;</span>
			<span style="color: #FF0000;">trace</span><span style="color: #000000;">&#40;</span><span style="color: #FF0000;">loader</span>, <span style="color: #FF0000;">error</span>, <span style="color: #FF0000;">message</span><span style="color: #000000;">&#41;</span>;
			<span style="color: #FF0000;">trace</span><span style="color: #000000;">&#40;</span><span style="color: #FF0000;">loader</span>.responseStatus<span style="color: #000000;">&#41;</span>;
		<span style="color: #000000;">&#125;</span>
	<span style="color: #000000;">&#125;</span>
<span style="color: #000000;">&#125;</span></pre></td></tr></table></div>

<p>Speaking of signals, <em>XMLLoader</em> is the first class in <a href="http://github.com/destroytoday/DestroyFramework" target="_blank">DestroyFramework</a> to use <a href="http://robertpenner.com/flashblog/" target="_blank">Robert Penner&#8217;s</a> <a href="http://github.com/robertpenner/as3-signals" target="_blank">AS3 Signals</a> instead of events. If you have to ask why, you haven&#8217;t been programming in AS3 long enough. Each <em>XMLLoader</em> instance has signals for <em>open</em>, <em>complete</em>, <em>error</em>, and <em>cancel</em>. The class also includes a <em>retryCount</em> property that indicates how many times to attempt to load a URL before calling it quits. Since some APIs can be down one second, then up the next, this feature really comes in handy. It&#8217;s mainly intended for handling the beloved fail whale.</p>
<p>The last two features include a <em>cancel</em> method and an <em>includeResponseInfo</em> property. Sure, <em>URLLoader</em> has a cancel method, <em>close</em>, but an exception is thrown if you call <em>close</em> when no operation is in progress. This makes sense, but the runtime shouldn&#8217;t close down shop when it happens. <em>XMLLoader</em> instead cancels and dispatches the <em>cancel</em> signal when the cancel method is called, and if no operations are in progress, it simply does nothing.</p>
<p>The <em>includeResponseInfo</em> property is an incredibly easy way to tell the loader to return the response status code and headers upon success or fail. Without <em>XMLLoader</em>, you could get this information with an event listener and the appropriate handler, but it&#8217;s far easier to flick a switch. In all honesty, I&#8217;ve neglected to retrieve this info using <em>URLLoader</em> in the past simply because it&#8217;s such a verbose process. Now that it only requires setting the property to <em>true</em>, I know I&#8217;ll use it more often than not.</p>
<p>As always, the <a href="http://github.com/destroytoday/DestroyFramework/blob/master/src/com/destroytoday/net/XMLLoader.as" target="_blank">source code</a> is available on <a href="http://github.com" target="_blank">GitHub</a>. Be sure to keep watch—my account will be pretty active these next few weeks.</p>
]]></content:encoded>
			<wfw:commentRss>http://destroytoday.com/blog/2010/01/introducing-the-xmlloader-class/feed/</wfw:commentRss>
		<slash:comments>10</slash:comments>
		</item>
		<item>
		<title>&#8216;Undocumented feature&#8217; in Rob Penner&#8217;s AS3 Signals</title>
		<link>http://destroytoday.com/blog/2010/01/undocumented-feature-in-rob-penners-as3-signals/</link>
		<comments>http://destroytoday.com/blog/2010/01/undocumented-feature-in-rob-penners-as3-signals/#comments</comments>
		<pubDate>Mon, 18 Jan 2010 01:00:51 +0000</pubDate>
		<dc:creator>Jonnie</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[AS3]]></category>
		<category><![CDATA[Git]]></category>
		<category><![CDATA[Quick Fix]]></category>

		<guid isPermaLink="false">http://destroytoday.com/blog/?p=1695</guid>
		<description><![CDATA[
Last week, I started replacing events in DestroyFramework with Rob Penner&#8217;s AS3 Signals. They&#8217;re faster, shorter, and include a few methods that developers have been dying for. Unfortunately, the first implementation, into my new Group class, didn&#8217;t work. I was puzzled to say the least. After literally hours of testing and debugging, I discovered the [...]]]></description>
			<content:encoded><![CDATA[<p><a href="http://github.com/destroytoday/as3-signals/commit/7112fd8da90205ec3a36642dcfef4293df94629f"><img class="alignnone size-full wp-image-1696" title="bug_feature" src="http://destroytoday.com/blog/wp-content/uploads/2010/01/bug_feature.jpg" alt="bug_feature" width="645" height="385" /></a></p>
<p>Last week, I started replacing events in <a href="http://github.com/destroytoday/DestroyFramework" target="_blank">DestroyFramework</a> with <a href="http://robertpenner.com/flashblog/" target="_blank">Rob Penner&#8217;s</a> <a href="http://github.com/robertpenner/as3-signals" target="_blank">AS3 Signals</a>. They&#8217;re faster, shorter, and include a few methods that developers have been dying for. Unfortunately, the first implementation, into my new Group class, didn&#8217;t work. I was puzzled to say the least. After literally hours of testing and debugging, I discovered the culprit.</p>
<p>It turns out, the <em>remove(listener)</em> method lacks a check for listener existence in the listeners array. When the method is called, if the index of the listener returns -1, the array splices the first listener. I forked the Git repository and <a href="http://github.com/destroytoday/as3-signals/commit/7112fd8da90205ec3a36642dcfef4293df94629f" target="_blank">implemented the fix</a> on the <em>Signal</em>, <em>NativeSignal</em>, and <em>DeluxeSignal</em> classes. And because a fix isn&#8217;t a fix without proper unit testing (says <a href="http://joelhooks.com/" target="_blank">Joel Hooks</a>), I <a href="http://github.com/destroytoday/as3-signals/commit/22bdeb2c629b6c1af25f9bb76a64d37893fbc362" target="_blank">added the unit tests</a> as well.</p>
]]></content:encoded>
			<wfw:commentRss>http://destroytoday.com/blog/2010/01/undocumented-feature-in-rob-penners-as3-signals/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>Where to find the right fontName</title>
		<link>http://destroytoday.com/blog/2009/12/where-to-find-the-right-fontname/</link>
		<comments>http://destroytoday.com/blog/2009/12/where-to-find-the-right-fontname/#comments</comments>
		<pubDate>Thu, 31 Dec 2009 01:54:11 +0000</pubDate>
		<dc:creator>Jonnie</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[AS3]]></category>
		<category><![CDATA[Quick Fix]]></category>
		<category><![CDATA[Tip]]></category>

		<guid isPermaLink="false">http://destroytoday.com/blog/?p=1669</guid>
		<description><![CDATA[To preface, I embed fonts using the Embed metatag and fontName parameter with an SWF as the source. If you&#8217;re unfamiliar with this method, it looks like this:

1
2
&#91;Embed&#40;source=&#34;assets/fonts.swf&#34;, fontName=&#34;Helvetica&#34;&#41;&#93;
protected static const HELVETICA:String;

This past week, I came across the same issue twice. Up until now, I only worked with fonts that used the fontName as it [...]]]></description>
			<content:encoded><![CDATA[<p>To preface, I embed fonts using the <em>Embed</em> metatag and <em>fontName</em> parameter with an SWF as the source. If you&#8217;re unfamiliar with this method, it looks like this:</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
</pre></td><td class="code"><pre class="actionscript3" style="font-family:monospace;"><span style="color: #000000;">&#91;</span>Embed<span style="color: #000000;">&#40;</span><span style="color: #FF0000;">source</span>=<span style="color: #666666;">&quot;assets/fonts.swf&quot;</span>, <span style="color: #FF0000;">fontName</span>=<span style="color: #666666;">&quot;Helvetica&quot;</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">&#93;</span>
<span style="color: #0000FF;">protected</span> static const HELVETICA<span style="color: #000000;">:</span><span style="color: #000000;">String</span>;</pre></td></tr></table></div>

<p>This past week, I came across the same issue twice. Up until now, I only worked with fonts that used the <em>fontName</em> as it appears in Flash&#8217;s properties panel. Sure, this works for fonts with simple names, but when you start getting fancy, things get messy. I needed to embed Alternate Gothic No. 2 and Flash labeled it as &#8220;AlternateGothic&#8221; with &#8220;No2&#8243; as the style. I set the <em>fontName</em> as &#8220;AlternateGothic No2&#8243; and was presented with this familiar gem:</p>
<p><img src="http://destroytoday.com/blog/wp-content/uploads/2009/12/fontname_error.gif" alt="fontname_error" title="fontname_error" width="645" height="236" class="alignnone size-full wp-image-1670" /></p>
<p>I get shivers each time I see it. After a few minutes of failed guess and check, I set out for a solution. I opened FontExplorer X and discovered that the font is labeled as &#8220;AlternateGothic-No2&#8243;.I gave it a shot and boom went the dynamite. From then on, I thought that would be the correct fontName—the font&#8217;s label in Font Explorer X.</p>
<p><img src="http://destroytoday.com/blog/wp-content/uploads/2009/12/fontname_fontexplorer.gif" alt="fontname_fontexplorer" title="fontname_fontexplorer" width="645" height="113" class="alignnone size-full wp-image-1676" /></p>
<p>I was wrong. This week, I needed to embed Helvetica Neue Roman, which is labeled as &#8220;12 pt Helvetica* 55 Roman 05472&#8243; in FontExplorer X—freaky, eh? I tried it out and the error returned. At first, I was bummed because I thought I had a foolproof solution. I was close, but no cigar. I opened Font Book to get a second opinion. Apparently, the font&#8217;s true name is &#8220;12 pt Helvetica* 55 Roman   05472&#8243;, which means FontExplorer X removes redundant whitespace, found in our example between &#8220;Roman&#8221; and &#8220;05472.&#8221; I tried it out and, sweet sassy molassy, it worked.</p>
<p><img src="http://destroytoday.com/blog/wp-content/uploads/2009/12/fontname_fontbook.gif" alt="fontname_fontbook" title="fontname_fontbook" width="645" height="188" class="alignnone size-full wp-image-1673" /></p>
<p>From now on, I&#8217;ll consult Font Book when embedding a new font.</p>
]]></content:encoded>
			<wfw:commentRss>http://destroytoday.com/blog/2009/12/where-to-find-the-right-fontname/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Introducing the AsyncLoop class</title>
		<link>http://destroytoday.com/blog/2009/12/introducing-the-asyncloop-class/</link>
		<comments>http://destroytoday.com/blog/2009/12/introducing-the-asyncloop-class/#comments</comments>
		<pubDate>Wed, 23 Dec 2009 06:17:02 +0000</pubDate>
		<dc:creator>Jonnie</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[Announcement]]></category>
		<category><![CDATA[AS3]]></category>
		<category><![CDATA[Code]]></category>
		<category><![CDATA[Programming]]></category>

		<guid isPermaLink="false">http://destroytoday.com/blog/?p=1645</guid>
		<description><![CDATA[Out of my recent work, I&#8217;m especially proud of and excited about the AsyncLoop class. It&#8217;s a serious performance enhancer that takes heavy processes and spreads them out over time, preventing stalls and possible lockups. I originally wrote it to deal with a for loop that contained a complex process and iterated 1000 times. Needless [...]]]></description>
			<content:encoded><![CDATA[<p>Out of my recent work, I&#8217;m especially proud of and excited about the <a href="http://github.com/destroytoday/DestroyFramework/blob/master/src/com/destroytoday/timer/AsyncLoop.as" target="_blank">AsyncLoop</a> class. It&#8217;s a serious performance enhancer that takes heavy processes and spreads them out over time, preventing stalls and possible lockups. I originally wrote it to deal with a <code>for</code> loop that contained a complex process and iterated 1000 times. Needless to say, the beach ball made an extended stay each time the loop ran. After implementing <code>AsyncLoop</code>, the beach ball disappeared and animations played smooth throughout.</p>
<p><code>AsyncLoop</code> works around a timer limit. The developer sets the maximum number of milliseconds to loop through the process function. Once the timer exceeds that limit, it carries over to the next frame and repeats. The loop can be ended a number of ways, providing great flexibility. A limit can be placed on the loop count, mimicking common <code>for</code> loop usage. The loop can return the <code>AsyncLoopAction.BREAK</code> constant. When using that method, <code>AsyncLoopAction.CONTINUE</code> is used to tell the loop to continue to the next tick. Each loop provides analytics, keeping track of its duration, loop count, and frame count. Here are two ways you can use it:</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
</pre></td><td class="code"><pre class="actionscript3" style="font-family:monospace;"><span style="color: #FF0099;">// new AsyncLoop(callback:Function, countLimit:int = -1, timerLimit:int = 20);</span>
<span style="color: #FF0000;">var</span> <span style="color: #FF0000;">loop</span><span style="color: #000000;">:</span>AsyncLoop = <span style="color: #0000FF;">new</span> AsyncLoop<span style="color: #000000;">&#40;</span>tick, <span style="color: #000000;">1000</span><span style="color: #000000;">&#41;</span>;
&nbsp;
<span style="color: #FF0000;">loop</span>.<span style="color: #FF0000;">addEventListener</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">Event</span>.<span style="color: #000000;">OPEN</span>, loopOpenHandler<span style="color: #000000;">&#41;</span>;
<span style="color: #FF0000;">loop</span>.<span style="color: #FF0000;">addEventListener</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">Event</span>.<span style="color: #000000;">CHANGE</span>, loopChangeHandler<span style="color: #000000;">&#41;</span>;
<span style="color: #FF0000;">loop</span>.<span style="color: #FF0000;">addEventListener</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">Event</span>.<span style="color: #000000;">COMPLETE</span>, loopCompleteHandler<span style="color: #000000;">&#41;</span>;
&nbsp;
<span style="color: #FF0000;">loop</span>.<span style="color: #FF0000;">start</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>;
&nbsp;
<span style="color: #FF0000;">function</span> tick<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">:</span><span style="color: #0000FF;">void</span> <span style="color: #000000;">&#123;</span>
	<span style="color: #FF0099;">// heavy process</span>
<span style="color: #000000;">&#125;</span>
&nbsp;
<span style="color: #FF0000;">function</span> loopOpenHandler<span style="color: #000000;">&#40;</span>event<span style="color: #000000;">:</span><span style="color: #000000;">Event</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">:</span><span style="color: #0000FF;">void</span> <span style="color: #000000;">&#123;</span>
	<span style="color: #FF0099;">// loop started</span>
<span style="color: #000000;">&#125;</span>
<span style="color: #FF0000;">function</span> loopChangeHandler<span style="color: #000000;">&#40;</span>event<span style="color: #000000;">:</span><span style="color: #000000;">Event</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">:</span><span style="color: #0000FF;">void</span> <span style="color: #000000;">&#123;</span>
	<span style="color: #FF0099;">// loop carries over to next frame</span>
&nbsp;
	<span style="color: #FF0000;">trace</span><span style="color: #000000;">&#40;</span><span style="color: #FF0000;">loop</span>.duration<span style="color: #000000;">&#41;</span>; <span style="color: #FF0099;">// incomplete loop running time</span>
	<span style="color: #FF0000;">trace</span><span style="color: #000000;">&#40;</span><span style="color: #FF0000;">loop</span>.<span style="color: #FF0000;">currentCount</span><span style="color: #000000;">&#41;</span>; <span style="color: #FF0099;">// number of callback calls</span>
<span style="color: #000000;">&#125;</span>
<span style="color: #FF0000;">function</span> loopCompleteHandler<span style="color: #000000;">&#40;</span>event<span style="color: #000000;">:</span><span style="color: #000000;">Event</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">:</span><span style="color: #0000FF;">void</span> <span style="color: #000000;">&#123;</span>
	<span style="color: #FF0099;">// loop complete</span>
&nbsp;
	<span style="color: #FF0000;">trace</span><span style="color: #000000;">&#40;</span><span style="color: #FF0000;">loop</span>.duration<span style="color: #000000;">&#41;</span>; <span style="color: #FF0099;">// completed loop duration</span>
	<span style="color: #FF0000;">trace</span><span style="color: #000000;">&#40;</span><span style="color: #FF0000;">loop</span>.frameCount<span style="color: #000000;">&#41;</span>; <span style="color: #FF0099;">// frames needed to complete</span>
<span style="color: #000000;">&#125;</span></pre></td></tr></table></div>


<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
</pre></td><td class="code"><pre class="actionscript3" style="font-family:monospace;"><span style="color: #FF0000;">var</span> <span style="color: #FF0000;">loop</span><span style="color: #000000;">:</span>AsyncLoop = <span style="color: #0000FF;">new</span> AsyncLoop<span style="color: #000000;">&#40;</span>tick<span style="color: #000000;">&#41;</span>;
&nbsp;
<span style="color: #FF0000;">loop</span>.<span style="color: #FF0000;">start</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>;
&nbsp;
<span style="color: #FF0000;">stage</span>.<span style="color: #FF0000;">addEventListener</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">MouseEvent</span>.<span style="color: #000000;">CLICK</span>, clickHandler<span style="color: #000000;">&#41;</span>;
<span style="color: #FF0000;">stage</span>.<span style="color: #FF0000;">addEventListener</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">MouseEvent</span>.<span style="color: #000000;">DOUBLE_CLICK</span>, doubleClickHandler<span style="color: #000000;">&#41;</span>;
&nbsp;
<span style="color: #FF0000;">function</span> tick<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">:</span><span style="color: #000000;">String</span> <span style="color: #000000;">&#123;</span>
	<span style="color: #FF0099;">// heavy process</span>
&nbsp;
	<span style="color: #0000FF;">if</span> <span style="color: #000000;">&#40;</span>loopShouldEnd<span style="color: #000000;">&#41;</span> <span style="color: #000000;">&#123;</span>
		<span style="color: #0000FF;">return</span> AsyncLoopAction.BREAK;
	<span style="color: #000000;">&#125;</span>
&nbsp;
	<span style="color: #0000FF;">return</span> AsyncLoopAction.CONTINUE;
<span style="color: #000000;">&#125;</span>
&nbsp;
<span style="color: #FF0000;">function</span> clickHandler<span style="color: #000000;">&#40;</span>event<span style="color: #000000;">:</span><span style="color: #000000;">MouseEvent</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">:</span><span style="color: #0000FF;">void</span> <span style="color: #000000;">&#123;</span>
	<span style="color: #0000FF;">if</span> <span style="color: #000000;">&#40;</span><span style="color: #FF0000;">loop</span>.<span style="color: #FF0000;">running</span><span style="color: #000000;">&#41;</span> <span style="color: #000000;">&#123;</span>
		<span style="color: #FF0000;">loop</span>.<span style="color: #FF0000;">pause</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>;
	<span style="color: #000000;">&#125;</span> <span style="color: #0000FF;">else</span> <span style="color: #000000;">&#123;</span>
		<span style="color: #FF0000;">loop</span>.<span style="color: #FF0000;">start</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>;
	<span style="color: #000000;">&#125;</span>
<span style="color: #000000;">&#125;</span>
<span style="color: #FF0000;">function</span> doubleClickHandler<span style="color: #000000;">&#40;</span>event<span style="color: #000000;">:</span><span style="color: #000000;">MouseEvent</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">:</span><span style="color: #0000FF;">void</span> <span style="color: #000000;">&#123;</span>
	<span style="color: #FF0000;">loop</span>.<span style="color: #FF0000;">cancel</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>;
<span style="color: #000000;">&#125;</span></pre></td></tr></table></div>

<p>I&#8217;m really happy with the class and how far it has come since its original form as <code>fLoop</code>. As always, the <a href="http://github.com/destroytoday/DestroyFramework/blob/master/src/com/destroytoday/timer/AsyncLoop.as" target="_blank">source code</a> is on GitHub, so take it and run! If you find it useful, feel free to share how you used it, or simply let me know what you think.</p>
]]></content:encoded>
			<wfw:commentRss>http://destroytoday.com/blog/2009/12/introducing-the-asyncloop-class/feed/</wfw:commentRss>
		<slash:comments>10</slash:comments>
		</item>
		<item>
		<title>Introducing the ApplicationUtil class</title>
		<link>http://destroytoday.com/blog/2009/12/introducing-the-applicationutil-class/</link>
		<comments>http://destroytoday.com/blog/2009/12/introducing-the-applicationutil-class/#comments</comments>
		<pubDate>Mon, 21 Dec 2009 14:23:05 +0000</pubDate>
		<dc:creator>Jonnie</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[AIR]]></category>
		<category><![CDATA[Announcement]]></category>
		<category><![CDATA[AS3]]></category>
		<category><![CDATA[Code]]></category>
		<category><![CDATA[Programming]]></category>

		<guid isPermaLink="false">http://destroytoday.com/blog/?p=1639</guid>
		<description><![CDATA[Yesterday, during my weekly football &#8220;service&#8221;, I spent a few minutes starting the ApplicationUtil class. So far, it consists of only two methods, getVersion and closeOpenWindows. The first accesses the application descriptor and returns the application&#8217;s version. closeOpenWindows is a necessity I learned in the Apollo days from Christian Cantrell. I had issues with my [...]]]></description>
			<content:encoded><![CDATA[<p>Yesterday, during my weekly football &#8220;service&#8221;, I spent a few minutes starting the <a href="http://github.com/destroytoday/DestroyFramework/blob/master/src/com/destroytoday/util/ApplicationUtil.as" target="_blank">ApplicationUtil</a> class. So far, it consists of only two methods, <code>getVersion</code> and <code>closeOpenWindows</code>. The first accesses the application descriptor and returns the application&#8217;s version. <code>closeOpenWindows</code> is a necessity I learned in the Apollo days from <a href="http://blogs.adobe.com/cantrell/" target="_blank">Christian Cantrell</a>. I had issues with my first AIR app, <a href="http://destroytoday.com/releases/DestroyFlickr108B.zip" target="_blank">DestroyFlickr</a>, where it wouldn&#8217;t quit, even if all of the visible windows were closed. I commonly use window visibility to show/hide utility windows, so the invisible ones were hanging around, keeping the app open. This method runs a quick loop to close all open windows, visible or not. It also includes an <code>andQuit</code> argument that, when true, sets <code>autoExit</code> to true, which quits the app upon close of the windows. Here&#8217;s some unnecessary example code to give this post more character:</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
</pre></td><td class="code"><pre class="actionscript3" style="font-family:monospace;"><span style="color: #FF0000;">var</span> <span style="color: #FF0000;">version</span><span style="color: #000000;">:</span><span style="color: #000000;">String</span> = ApplicationUtil.getVersion<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>;
<span style="color: #FF0000;">trace</span><span style="color: #000000;">&#40;</span><span style="color: #FF0000;">version</span><span style="color: #000000;">&#41;</span>; <span style="color: #FF0099;">// v1</span>
&nbsp;
<span style="color: #FF0000;">trace</span><span style="color: #000000;">&#40;</span>NativeApplication.nativeApplication.openedWindows.<span style="color: #FF0000;">length</span><span style="color: #000000;">&#41;</span>; <span style="color: #FF0099;">// 3</span>
ApplicationUtil.closeOpenWindows<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>;
<span style="color: #FF0000;">trace</span><span style="color: #000000;">&#40;</span>NativeApplication.nativeApplication.openedWindows.<span style="color: #FF0000;">length</span><span style="color: #000000;">&#41;</span>; <span style="color: #FF0099;">// 0</span>
&nbsp;
<span style="color: #FF0099;">// suppose three windows are open again</span>
ApplicationUtil.closeOpenWindows<span style="color: #000000;">&#40;</span><span style="color: #0000FF;">true</span><span style="color: #000000;">&#41;</span>; <span style="color: #FF0099;">// closes windows and quits before trace is called</span>
<span style="color: #FF0000;">trace</span><span style="color: #000000;">&#40;</span>NativeApplication.nativeApplication.openedWindows.<span style="color: #FF0000;">length</span><span style="color: #000000;">&#41;</span>;</pre></td></tr></table></div>

]]></content:encoded>
			<wfw:commentRss>http://destroytoday.com/blog/2009/12/introducing-the-applicationutil-class/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
	</channel>
</rss>
