<?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; Programming</title>
	<atom:link href="http://destroytoday.com/blog/tag/programming/feed/" rel="self" type="application/rss+xml" />
	<link>http://destroytoday.com/blog</link>
	<description>Jonnie is back to work.</description>
	<lastBuildDate>Mon, 01 Mar 2010 02:00:08 +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>0</slash:comments>
		</item>
		<item>
		<title>Flex bug + Peter DeHaan = workaround + wheels in motion</title>
		<link>http://destroytoday.com/blog/2010/02/flex-bug-peter-dehaan-workaround-wheels-in-motion/</link>
		<comments>http://destroytoday.com/blog/2010/02/flex-bug-peter-dehaan-workaround-wheels-in-motion/#comments</comments>
		<pubDate>Thu, 11 Feb 2010 03:46:04 +0000</pubDate>
		<dc:creator>Jonnie</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[Flex]]></category>
		<category><![CDATA[Programming]]></category>
		<category><![CDATA[Quick Fix]]></category>

		<guid isPermaLink="false">http://destroytoday.com/blog/?p=1737</guid>
		<description><![CDATA[I know, I know—Flex post?! I have been &#8220;drinking the Koolaid&#8221; these past few months, but this post is for the greater good. I found a bug and it had me panicking for a few solid hours yesterday. I typically would&#8217;ve kept my cool, but with a deadline quickly approaching and the fact that I&#8217;m [...]]]></description>
			<content:encoded><![CDATA[<p>I know, I know—Flex post?! I have been &#8220;drinking the <a href="http://www.youtube.com/watch?v=Ar6xC8KM-jk" target="_blank">Koolaid</a>&#8221; these past few months, but this post is for the greater good. I found a bug and it had me panicking for a few solid hours yesterday. I typically would&#8217;ve kept my cool, but with a deadline quickly approaching and the fact that I&#8217;m still somewhat new to Flex, it was time to sound the alarms.</p>
<p>First, what&#8217;s the bug? It occurs when using multiple item renderers with the <em>List</em> component and changing the <em>dataProvider</em> property. The List should recycle the currently used renderers and choose ones that apply to the new data. Instead, the <em>List</em> tries to use the previous renderers on the new content, regardless of whether they match the data.</p>
<p>I resorted to using some internal resources at Adobe and within minutes had a workaround and bug report, courtesy of <a href="http://blog.flexexamples.com/" target="_blank">Peter DeHaan</a>. Simply, reset the <em>itemRendererFunction</em> each time you change the <em>dataProvider</em> property. I know it&#8217;s a bit redundant, but it works and is a temporary solution until the fix is in place. If you&#8217;re interested in following the bug, you can <a href="http://bugs.adobe.com/jira/browse/SDK-25412" target="_blank">watch it on JIRA</a>.</p>
]]></content:encoded>
			<wfw:commentRss>http://destroytoday.com/blog/2010/02/flex-bug-peter-dehaan-workaround-wheels-in-motion/feed/</wfw:commentRss>
		<slash:comments>0</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>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>
		<item>
		<title>Introducing the Scale9Bitmap class</title>
		<link>http://destroytoday.com/blog/2009/12/introducing-the-scale9bitmap-class/</link>
		<comments>http://destroytoday.com/blog/2009/12/introducing-the-scale9bitmap-class/#comments</comments>
		<pubDate>Sun, 20 Dec 2009 02:23:06 +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=1629</guid>
		<description><![CDATA[
The Scale9Bitmap class applies a scale9Grid to a Bitmap. It takes advantage of a technique I used for DestroyTwitter&#8217;s window drop shadow, scaling nine Bitmap instances. When developing the MAX Companion, I tried Didier Brun&#8217;s ScaleBitmap class, but discovered a costly memory leak in which it instantiates a new BitmapData instance with every resize call. [...]]]></description>
			<content:encoded><![CDATA[<p><img class="alignnone size-full wp-image-1630" title="scale9bitmap" src="http://destroytoday.com/blog/wp-content/uploads/2009/12/scale9bitmap.jpg" alt="scale9bitmap" width="645" height="429" /></p>
<p>The <a href="http://github.com/destroytoday/DestroyFramework/blob/master/src/com/destroytoday/display/Scale9Bitmap.as" target="_blank">Scale9Bitmap</a> class applies a <code>scale9Grid</code> to a <code>Bitmap</code>. It takes advantage of a technique I used for <a href="http://destroytwitter.com">DestroyTwitter&#8217;s</a> window drop shadow, scaling nine <code>Bitmap</code> instances. When developing the <a href="http://destroytoday.com/blog/2009/10/adobe-max-companion-launched/" target="_blank">MAX Companion</a>, I tried <a href="http://bytearray.org" target="_blank">Didier Brun&#8217;s</a> <a href="http://www.bytearray.org/?p=118" target="_blank">ScaleBitmap</a> class, but discovered a costly memory leak in which it instantiates a new <code>BitmapData</code> instance with every resize call. This wouldn&#8217;t be a big deal for a once-and-done resize, but as a window drop shadow, memory skyrockets.</p>
<p>I decided to start from scratch and develop a class that is super fast and slim as can be. The <code>Bitmaps</code> are only updated when the <code>BitmapData</code> is set. After that, the only process that takes place is the resizing of each <code>Bitmap</code>—no <code>BitmapData</code> manipulation needed. Setup requires a single method to set the <code>BitmapData</code> and the <code>Rectangle</code> that indicates the stretchable portion of the <code>Bitmap</code>. <code>BitmapData</code> can be changed on the fly and there is a <code>scale</code> property that sets both <code>scaleX</code> and <code>scaleY</code>.</p>
<p>The <a href="http://github.com/destroytoday/DestroyFramework/blob/master/src/com/destroytoday/display/Scale9Bitmap.as" target="_blank">source code</a> is on GitHub, so feel free to give it a whirl.</p>
]]></content:encoded>
			<wfw:commentRss>http://destroytoday.com/blog/2009/12/introducing-the-scale9bitmap-class/feed/</wfw:commentRss>
		<slash:comments>8</slash:comments>
		</item>
		<item>
		<title>Introducing the Console class and debug package</title>
		<link>http://destroytoday.com/blog/2009/12/introducing-the-console-class-and-debug-package/</link>
		<comments>http://destroytoday.com/blog/2009/12/introducing-the-console-class-and-debug-package/#comments</comments>
		<pubDate>Fri, 18 Dec 2009 05:33:36 +0000</pubDate>
		<dc:creator>Jonnie</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[AIR]]></category>
		<category><![CDATA[AS3]]></category>
		<category><![CDATA[Code]]></category>
		<category><![CDATA[Programming]]></category>

		<guid isPermaLink="false">http://destroytoday.com/blog/?p=1611</guid>
		<description><![CDATA[I realized I need a more&#8230;official&#8230;way of debugging my apps, so I wrote the Console class. It&#8217;s primary function is to record activity to a specified log file. So far, I have a few methods that write entries—success, error, cancel, and print. I definitely plan to add more, but these are the main ones I [...]]]></description>
			<content:encoded><![CDATA[<p>I realized I need a more&#8230;official&#8230;way of debugging my apps, so I wrote the <a href="http://github.com/destroytoday/DestroyFramework/blob/master/src/com/destroytoday/debug/Console.as" target="_blank">Console</a> class. It&#8217;s primary function is to record activity to a specified log file. So far, I have a few methods that write entries—<em>success</em>, <em>error</em>, <em>cancel</em>, and <em>print</em>. I definitely plan to add more, but these are the main ones I intend to use in the near future. Since the name &#8220;trace&#8221; is off limits in AS3, I referenced my PHP background and named the <em>trace</em> method, &#8220;print&#8221;.</p>
<p>The class also includes the ability to automatically trace entries to Eclipse&#8217;s console along with writing them to a file. Files are written asynchronously, but I also added a delay property that combines entries, so the writing process is less likely to slow down the app. Taking advantage of AIR 2.0&#8217;s UncaughtErrors feature, the Console automatically logs fatal errors and their stack traces, if possible. Here&#8217;s an example of its usage:</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
</pre></td><td class="code"><pre class="actionscript3" style="font-family:monospace;"><span style="color: #FF0000;">var</span> path<span style="color: #000000;">:</span><span style="color: #000000;">String</span> = File.applicationStorageDirectory.nativePath;
&nbsp;
<span style="color: #FF0099;">// params: log file path, LoaderInfo</span>
<span style="color: #FF0099;">// automatically writes a session start entry to the log</span>
Console.<span style="color: #FF0000;">init</span><span style="color: #000000;">&#40;</span>path, <span style="color: #FF0000;">loaderInfo</span><span style="color: #000000;">&#41;</span>;
&nbsp;
Console.<span style="color: #FF0000;">delay</span> = <span style="color: #000000;">1000</span>;
Console.traceError = <span style="color: #0000FF;">true</span>;
&nbsp;
<span style="color: #FF0099;">// params: id, message</span>
Console.success<span style="color: #000000;">&#40;</span><span style="color: #666666;">&quot;wp post&quot;</span>, <span style="color: #666666;">&quot;wrote blog post&quot;</span><span style="color: #000000;">&#41;</span>;
&nbsp;
<span style="color: #FF0099;">// params: id, message</span>
Console.<span style="color: #FF0000;">error</span><span style="color: #000000;">&#40;</span><span style="color: #666666;">&quot;wp post&quot;</span>, <span style="color: #666666;">&quot;previous post was depressing&quot;</span><span style="color: #000000;">&#41;</span>;
&nbsp;
<span style="color: #FF0099;">// params: id, message</span>
Console.<span style="color: #FF0000;">cancel</span><span style="color: #000000;">&#40;</span><span style="color: #666666;">&quot;Christmas&quot;</span>, <span style="color: #666666;">&quot;why would you want to do that?&quot;</span><span style="color: #000000;">&#41;</span>;
&nbsp;
<span style="color: #FF0099;">// params: message</span>
Console.<span style="color: #FF0000;">print</span><span style="color: #000000;">&#40;</span><span style="color: #666666;">&quot;this is a test&quot;</span><span style="color: #000000;">&#41;</span>;</pre></td></tr></table></div>


<div class="wp_syntax"><div class="code"><pre class="" style="font-family:monospace;"><span class="br0">&#91;</span>Fri Dec <span style="">18</span> 00:<span style="">31</span>:<span style="">31</span> GMT-0500 <span style="">2009</span><span class="br0">&#93;</span> Session Start
<span class="br0">&#91;</span>Fri Dec <span style="">18</span> 00:<span style="">31</span>:<span style="">31</span> GMT-0500 <span style="">2009</span><span class="br0">&#93;</span> <span class="br0">&#91;</span>success<span class="br0">&#93;</span> <span class="br0">&#91;</span>wp post<span class="br0">&#93;</span> wrote blog post
<span class="br0">&#91;</span>Fri Dec <span style="">18</span> 00:<span style="">31</span>:<span style="">31</span> GMT-0500 <span style="">2009</span><span class="br0">&#93;</span> <span class="br0">&#91;</span>error<span class="br0">&#93;</span> <span class="br0">&#91;</span>wp post<span class="br0">&#93;</span> previous post was depressing
<span class="br0">&#91;</span>Fri Dec <span style="">18</span> 00:<span style="">31</span>:<span style="">31</span> GMT-0500 <span style="">2009</span><span class="br0">&#93;</span> <span class="br0">&#91;</span>cancel<span class="br0">&#93;</span> <span class="br0">&#91;</span>Christmas<span class="br0">&#93;</span> why would you want to do that?
<span class="br0">&#91;</span>Fri Dec <span style="">18</span> 00:<span style="">31</span>:<span style="">31</span> GMT-0500 <span style="">2009</span><span class="br0">&#93;</span> <span class="br0">&#91;</span>print<span class="br0">&#93;</span> this is a test</pre></div></div>

<p>I do expect to build the class over time, eventually adding TextField support. In the meantime, the <a href="http://github.com/destroytoday/DestroyFramework/blob/master/src/com/destroytoday/debug/Console.as" target="_blank">source code</a> is available on GitHub.</p>
]]></content:encoded>
			<wfw:commentRss>http://destroytoday.com/blog/2009/12/introducing-the-console-class-and-debug-package/feed/</wfw:commentRss>
		<slash:comments>5</slash:comments>
		</item>
	</channel>
</rss>
