<?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>Charles @ Adobe</title>
	<atom:link href="http://blogs.adobe.com/charles/feed" rel="self" type="application/rss+xml" />
	<link>http://blogs.adobe.com/charles</link>
	<description>Working on the Internet</description>
	<lastBuildDate>Tue, 21 May 2013 00:28:34 +0000</lastBuildDate>
	<language>en-US</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.5.1</generator>
		<item>
		<title>JavaScript Puzzlers &#8211; Puzzles That Make You Think (presented at Adobe MAX 2013)</title>
		<link>http://blogs.adobe.com/charles/2013/05/javascript-puzzlers-puzzles-that-make-you-think-presented-at-adobe-max-2013.html</link>
		<comments>http://blogs.adobe.com/charles/2013/05/javascript-puzzlers-puzzles-that-make-you-think-presented-at-adobe-max-2013.html#comments</comments>
		<pubDate>Tue, 21 May 2013 00:28:34 +0000</pubDate>
		<dc:creator>Charles Bihis</dc:creator>
				<category><![CDATA[Adobe]]></category>
		<category><![CDATA[JavaScript]]></category>
		<category><![CDATA[JavaScript-Puzzler]]></category>
		<category><![CDATA[Presentation]]></category>
		<category><![CDATA[Programming]]></category>
		<category><![CDATA[Puzzler]]></category>
		<category><![CDATA[adobe]]></category>
		<category><![CDATA[adobetv]]></category>
		<category><![CDATA[javascript]]></category>
		<category><![CDATA[max]]></category>
		<category><![CDATA[max2013]]></category>
		<category><![CDATA[presentation]]></category>
		<category><![CDATA[programming]]></category>
		<category><![CDATA[puzzler]]></category>

		<guid isPermaLink="false">http://blogs.adobe.com/charles/?p=966</guid>
		<description><![CDATA[I&#8217;ve just recently returned from Adobe MAX 2013, Adobe&#8217;s annual &#8220;Creativity Conference&#8221;.  I had the opportunity to host a session this year.  I ended up doing a presentation called &#8220;JavaScript Puzzlers&#8221;.  In short, my presentation presents the audience with short, &#8230; <a href="http://blogs.adobe.com/charles/2013/05/javascript-puzzlers-puzzles-that-make-you-think-presented-at-adobe-max-2013.html">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
				<content:encoded><![CDATA[<p>I&#8217;ve just recently returned from Adobe MAX 2013, Adobe&#8217;s annual &#8220;Creativity Conference&#8221;.  I had the opportunity to host a session this year.  I ended up doing a presentation called &#8220;JavaScript Puzzlers&#8221;.  In short, my presentation presents the audience with short, code-based &#8220;puzzles&#8221; which the audience then has to solve.  The puzzles themselves are quite simple, anywhere from 2 to 20 lines of code.  The answers, however, more often than not, can be quite surprising.  Well, the video from the presentation has finally gone online and so here it is&#8230;</p>
<p><iframe title="AdobeTV Video Player" src="http://tv.adobe.com/embed/1217/18456/" height="367" width="640" allowfullscreen="" frameborder="0" scrolling="no"></iframe></p>
<p>I&#8217;ve also made the full set of slides available here&#8230;</p>
<p><iframe src="http://www.slideshare.net/slideshow/embed_code/21549109" width="597" height="486" frameborder="0" marginwidth="0" marginheight="0" scrolling="no" style="border:1px solid #CCC;border-width:1px 1px 0;margin-bottom:5px" allowfullscreen webkitallowfullscreen mozallowfullscreen> </iframe>
<div style="margin-bottom:5px"></div>
<p>We had a great turnout, and some fantastic discussions!  Thanks to everyone who was able to attend!  I had a blast!</p>
<p>&nbsp;</p>
<p>Charles</p>
<p>&nbsp;</p>
]]></content:encoded>
			<wfw:commentRss>http://blogs.adobe.com/charles/2013/05/javascript-puzzlers-puzzles-that-make-you-think-presented-at-adobe-max-2013.html/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Javascript Puzzlers at Adobe MAX 2013!</title>
		<link>http://blogs.adobe.com/charles/2013/05/javascript-puzzlers-at-adobe-max-2013.html</link>
		<comments>http://blogs.adobe.com/charles/2013/05/javascript-puzzlers-at-adobe-max-2013.html#comments</comments>
		<pubDate>Thu, 02 May 2013 23:40:28 +0000</pubDate>
		<dc:creator>Charles Bihis</dc:creator>
				<category><![CDATA[Adobe]]></category>
		<category><![CDATA[JavaScript]]></category>
		<category><![CDATA[JavaScript-Puzzler]]></category>
		<category><![CDATA[Presentation]]></category>
		<category><![CDATA[Programming]]></category>
		<category><![CDATA[Puzzler]]></category>
		<category><![CDATA[javascript]]></category>
		<category><![CDATA[max]]></category>
		<category><![CDATA[max2013]]></category>
		<category><![CDATA[presentation]]></category>
		<category><![CDATA[programming]]></category>
		<category><![CDATA[puzzler]]></category>

		<guid isPermaLink="false">http://blogs.adobe.com/charles/?p=948</guid>
		<description><![CDATA[Come one, come all! Adobe MAX 2013 is just around the corner! For those of you attending, I&#8217;ll be presenting a session on the last day based on my &#8220;Puzzler&#8221; series! The session will be geared towards Javascript developers, particularly, &#8230; <a href="http://blogs.adobe.com/charles/2013/05/javascript-puzzlers-at-adobe-max-2013.html">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
				<content:encoded><![CDATA[<p><a href="http://max.adobe.com/"><img class="aligncenter size-full wp-image-950" alt="Adobe MAX 2013 Banner" src="http://blogs.adobe.com/charles/files/2013/05/max2013banner.jpg" width="1024" height="550" /></a></p>
<p>Come one, come all! Adobe MAX 2013 is just around the corner! For those of you attending, I&#8217;ll be presenting a session on the last day based on my <a title="Puzzlers!" href="http://blogs.adobe.com/charles/category/puzzler">&#8220;Puzzler&#8221; series</a>! The session will be geared towards Javascript developers, particularly, helping you identify quirky behaviour and subtle nuances of the language. The goal of this presentation will be to give you some extra understanding around these scenarios to hopefully help you write better code, all presented in a series of fun &#8220;puzzles&#8221; :) The session is called &#8220;Javascript Puzzlers&#8221;, and here are the details&#8230;</p>
<p style="padding-left: 30px;"><strong>What</strong>: JavaScript Puzzlers: Puzzles to Make You Think (and write fewer bugs)<br />
<strong>When</strong>: Wednesday, May 8th from 3:30PM &#8211; 4:30PM<br />
<strong>Where</strong>: Los Angeles Convention Center, Room 504, 1201 South Figueroa Street, Los Angeles, CA<br />
<strong> Why</strong>: Because Javascript can be tricky!</p>
<p>For those of you who aren&#8217;t attending, that&#8217;s okay! You can register here to watch the keynotes and select featured sessions online live and for free!</p>
<p style="text-align: center;"><a title="Register to view keynotes online for FREE!" href="http://max.adobe.com/sessions/online/register.html?trackingid=KFNHJ">Register to view keynotes online for FREE!</a></p>
<p>Finally, for those who are interested in registering to attend in person, there are still spots available! Register here!</p>
<p style="padding-left: 30px; text-align: center;"><a title="Register to attend Adobe MAX 2013!" href="https://www.adobe-max.com/portal/newreg.ww">Register to attend Adobe MAX 2013!</a></p>
<p>Hope to see you there!</p>
<p>Charles</p>
]]></content:encoded>
			<wfw:commentRss>http://blogs.adobe.com/charles/2013/05/javascript-puzzlers-at-adobe-max-2013.html/feed</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
		<item>
		<title>Facebook Desktop!  Open-Sourced!</title>
		<link>http://blogs.adobe.com/charles/2012/10/facebook-desktop-open-sourced.html</link>
		<comments>http://blogs.adobe.com/charles/2012/10/facebook-desktop-open-sourced.html#comments</comments>
		<pubDate>Tue, 02 Oct 2012 00:32:32 +0000</pubDate>
		<dc:creator>Charles Bihis</dc:creator>
				<category><![CDATA[Actionscript]]></category>
		<category><![CDATA[AIR]]></category>
		<category><![CDATA[Facebook]]></category>
		<category><![CDATA[Facebook Desktop]]></category>
		<category><![CDATA[Open Source]]></category>
		<category><![CDATA[Programming]]></category>
		<category><![CDATA[Projects]]></category>
		<category><![CDATA[actionscript]]></category>
		<category><![CDATA[air]]></category>
		<category><![CDATA[facebook]]></category>
		<category><![CDATA[facebook desktop]]></category>
		<category><![CDATA[flash]]></category>
		<category><![CDATA[github]]></category>
		<category><![CDATA[opensource]]></category>
		<category><![CDATA[programming]]></category>
		<category><![CDATA[project]]></category>

		<guid isPermaLink="false">http://blogs.adobe.com/charles/?p=868</guid>
		<description><![CDATA[Last year, I wrote about a side project of mine that I was working on at the time called &#8220;Facebook Desktop&#8220;.  In short, it is a real-time notification engine built for Facebook! I built it because I felt it filled &#8230; <a href="http://blogs.adobe.com/charles/2012/10/facebook-desktop-open-sourced.html">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
				<content:encoded><![CDATA[<p><center><img class="aligncenter size-full wp-image-873" title="Facebook Desktop!  Open-Sourced!" src="http://blogs.adobe.com/charles/files/2012/09/facebook-desktop-open-sourced-notification.png" alt="" width="311" height="81" /></center></p>
<p>Last year, I wrote about a <a title="Introducing “Facebook Desktop” – A Lightweight, Unobtrusive Notification Engine for Facebook Built on Adobe AIR" href="http://blogs.adobe.com/charles/2011/01/introducing-facebook-desktop-a-lightweight-unobtrusive-notification-engine-for-facebook-built-on-adobe-air.html">side project</a> of mine that I was working on at the time called &#8220;<a title="Facebook Desktop - Bringing Facebook to your desktop, one notification at a time" href="http://www.facebookdesktop.com/">Facebook Desktop</a>&#8220;.  In short, it is a real-time notification engine built for Facebook!  I built it because I felt it filled a need that Facebook didn&#8217;t fill&#8230;</p>
<p style="text-align: center;"><em>It kept me connected to Facebook (and my friends) without having to<br />
keep a browser window opened to Facebook.com the entire time.</em></p>
<p>It ended up becoming quite a popular project, amassing over 500,000 downloads, over 2 million API calls PER DAY, written about by numerous blogs and publications around the world, used in over 30 countries, and localized into 20 different languages, all in the short 14 months since it was released!  Low-and-behold, Facebook had issue with my app (I think because I called it &#8220;Facebook Desktop&#8221;) and so they &#8220;asked&#8221; me to shut it down.  Rather than argue with the well-known <strike>startup</strike> company, I decided to comply.  It was a wild ride, and I learned a LOT (perhaps I&#8217;ll write another blog post about this), but as the saying goes, &#8220;All good things must come to an end&#8221;.</p>
<p>However, there is always a silver lining!  To build Facebook Desktop, I had to write a lot of custom code (obviously).  I&#8217;ve already open-sourced a lot of the individual components that I wrote, including&#8230;</p>
<ul>
<li><a href="http://charlesbihis.github.com/actionscript-oauth2/">ActionScript OAuth 2.0 Library</a><sup>*</sup></li>
<li><a href="http://charlesbihis.github.com/actionscript-notification-engine/">ActionScript Notification Engine</a></li>
<li><a href="http://charlesbihis.github.com/actionscript-relative-date/">ActionScript Relative Date Library</a><sup>*</sup></li>
<li><a href="http://charlesbihis.github.com/actionscript-diff/">ActionScript Diff Library</a><sup>*</sup></li>
</ul>
<p>But, now that I&#8217;m moving on to other things, I&#8217;ve decided to go ahead and open-source the entire project!  Just as I&#8217;ve done with all of my other open-source projects, I&#8217;ve made Facebook Desktop available on <a title="GitHub" href="https://github.com">GitHub</a>.  You can download it and run it out-of-the-box!</p>
<p><center><img class="aligncenter size-full wp-image-884" title="Facebook Desktop" src="http://blogs.adobe.com/charles/files/2012/09/facebook-desktop-windows-mac.png" alt="" width="740" height="261" /></center></p>
<p><strong>Features</strong></p>
<p>Facebook Desktop is a notification engine that provides real-time updates of your Facebook friends straight to your desktop, without requiring a browser!  Here is a short list of some of the features that I&#8217;ve built in&#8230;</p>
<ul>
<li>Real-time notification of Facebook activity</li>
<li>Language support for 20 different languages!</li>
<li>User-presence logic that detects when to display notifications</li>
<li>Operating-system detection that adapts interface to match native applications</li>
<li>Smart notification engine, including adaptive repositioning, individual notification settings, variable display length, and support for custom styling</li>
<li>Persistent user-settings, including preferred language, display length, appearance, and icon-click action</li>
<li>Ability to fully filter notifications by source and action</li>
<li>Support for updating status</li>
</ul>
<p><strong>Dependencies</strong></p>
<p>Facebook Desktop is written with <a href="www.adobe.com/go/flashbuilder">Adobe Flash Builder 4.5</a> using the <a href="http://www.adobe.com/go/flex">Adobe Flex 4.5 SDK</a> and the <a href="www.adobe.com/go/air">Adobe AIR 3.0 SDK</a>.  It makes use of the following open-source libraries&#8230;</p>
<ul>
<li><a href="http://charlesbihis.github.com/actionscript-notification-engine/">ActionScript Notification Engine</a></li>
<li><a href="https://github.com/mikechambers/as3corelib">ActionScript Core Library</a></li>
<li><a href="http://code.google.com/p/facebook-actionscript-api/">Facebook ActionScript API</a></li>
</ul>
<p><strong>Code, please!</strong></p>
<p>I’ve released the code under the <a href="http://www.apache.org/licenses/LICENSE-2.0.html">Apache License, Version 2.0</a> and made it all available on GitHub! Please, fork and extend!</p>
<p><center><a href="http://charlesbihis.github.com/facebook-desktop/">Facebook Desktop on GitHub</a></center></p>
<p>This marks the end of a fun-filled side-project for me, but perhaps the start for someone else :D  As always, I love hearing from you so let me know what you think! Until next time, happy coding =)</p>
<p>&nbsp;</p>
<p>Charles</p>
]]></content:encoded>
			<wfw:commentRss>http://blogs.adobe.com/charles/2012/10/facebook-desktop-open-sourced.html/feed</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
		<item>
		<title>ActionScript Puzzler &#8211; Block Party!</title>
		<link>http://blogs.adobe.com/charles/2012/06/actionscript-puzzler-block-party.html</link>
		<comments>http://blogs.adobe.com/charles/2012/06/actionscript-puzzler-block-party.html#comments</comments>
		<pubDate>Fri, 22 Jun 2012 23:39:14 +0000</pubDate>
		<dc:creator>Charles Bihis</dc:creator>
				<category><![CDATA[Actionscript]]></category>
		<category><![CDATA[ActionScript-Puzzler]]></category>
		<category><![CDATA[Programming]]></category>
		<category><![CDATA[Puzzler]]></category>
		<category><![CDATA[actionscript]]></category>
		<category><![CDATA[challenge]]></category>
		<category><![CDATA[problem]]></category>
		<category><![CDATA[programming]]></category>
		<category><![CDATA[puzzler]]></category>

		<guid isPermaLink="false">http://blogs.adobe.com/charles/?p=857</guid>
		<description><![CDATA[Hi, everyone! It&#8217;s been a while, but it&#8217;s time now for another Puzzler! This time, we&#8217;ll do another ActionScript Puzzler! For those of you that don&#8217;t know what a Puzzler is, let me quickly explain. A Puzzler is essentially a &#8230; <a href="http://blogs.adobe.com/charles/2012/06/actionscript-puzzler-block-party.html">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
				<content:encoded><![CDATA[<p>Hi, everyone! It&#8217;s been a while, but it&#8217;s time now for another <a href="http://blogs.adobe.com/charles/category/puzzler">Puzzler</a>! This time, we&#8217;ll do another <a href="http://blogs.adobe.com/charles/category/puzzler/actionscript-puzzler">ActionScript Puzzler</a>! For those of you that don&#8217;t know what a Puzzler is, let me quickly explain. A Puzzler is essentially a short and simple programming problem that is used to demonstrate special cases or &#8220;features&#8221; of a programming language. See some of my old ones <a title="ActionScript Puzzler - The Joy of Millisecs" href="http://blogs.adobe.com/charles/2011/03/actionscript-puzzler-the-joy-of-millisecs.html">here</a>, <a title="C Puzzler - Give Me A Float" href="http://blogs.adobe.com/charles/2011/02/c-puzzler-give-me-a-float.html">here</a>, and <a title="JavaScript Puzzler - Let's Print Some ZIP-Codes!" href="http://blogs.adobe.com/charles/2010/12/javascript-puzzler-lets-print-some-zip-codes.html">here</a>.</p>
<p>This time, I&#8217;ve decided to try something new. Rather than writing a blog post about it, I&#8217;ve made a video Puzzler instead! Watch below! And as always, feedback is always welcome!</p>
<p><iframe src="http://www.youtube.com/embed/bMin2gfuxJQ?rel=0" frameborder="0" width="640" height="360"></iframe></p>
<p>If you like these video Puzzlers, let me know and I can do more! Or, if you prefer the blog-post style, let me know too. Until next time, happy coding!</p>
<p>Charles</p>
]]></content:encoded>
			<wfw:commentRss>http://blogs.adobe.com/charles/2012/06/actionscript-puzzler-block-party.html/feed</wfw:commentRss>
		<slash:comments>7</slash:comments>
		</item>
		<item>
		<title>OAuth 2.0 Library for ActionScript</title>
		<link>http://blogs.adobe.com/charles/2012/05/oauth-2-0-library-for-actionscript.html</link>
		<comments>http://blogs.adobe.com/charles/2012/05/oauth-2-0-library-for-actionscript.html#comments</comments>
		<pubDate>Fri, 11 May 2012 22:34:09 +0000</pubDate>
		<dc:creator>Charles Bihis</dc:creator>
				<category><![CDATA[Actionscript]]></category>
		<category><![CDATA[Adobe]]></category>
		<category><![CDATA[AIR]]></category>
		<category><![CDATA[Open Source]]></category>
		<category><![CDATA[Programming]]></category>
		<category><![CDATA[actionscript]]></category>
		<category><![CDATA[air]]></category>
		<category><![CDATA[authentication]]></category>
		<category><![CDATA[authorization]]></category>
		<category><![CDATA[library]]></category>
		<category><![CDATA[mobile]]></category>
		<category><![CDATA[opensource]]></category>
		<category><![CDATA[programming]]></category>

		<guid isPermaLink="false">http://blogs.adobe.com/charles/?p=738</guid>
		<description><![CDATA[Here at Adobe, we&#8217;ve been working really hard recently on our latest big project: Adobe Creative Cloud. For anyone that is unfamiliar or wasn&#8217;t able to attend our latest MAX conference, here is how we describe the project, straight from &#8230; <a href="http://blogs.adobe.com/charles/2012/05/oauth-2-0-library-for-actionscript.html">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
				<content:encoded><![CDATA[<p>Here at Adobe, we&#8217;ve been working really hard recently on our latest big project: <a href="http://www.adobe.com/go/creativecloud" target="_blank">Adobe Creative Cloud</a>.  For anyone that is unfamiliar or wasn&#8217;t able to attend our latest MAX conference, here is how we describe the project, straight from our <a href="http://www.adobe.com/aboutadobe/pressroom/pressreleases/201110/100311AdobeCreativeCloud.html" target="_blank">press release</a>&#8230;</p>
<p style="text-align: center;"><em>&#8220;Adobe Creative Cloud reinvents creative expression by enabling a new generation of services for<br />
creativity and publishing, that embrace touch interaction to re-imagine how individuals interact with<br />
 creative tools and build deeper social connections between creatives around the world.&#8221;</em><br />
-Kevin Lynch, CTO, Adobe Systems</p>
<p>In a nutshell, Creative Cloud is really an ecosystem that includes a multitude of <a href="http://www.adobe.com/go/touchapps" target="_blank">applications</a> for various devices that facilitate creative workflows, all backed by a <a href="http://www.adobe.com/go/creativecloud" target="_blank">cloud storage solution</a>.  Now that I&#8217;m done with the marketing, I can get to the good stuff :)</p>
<p>One of the major tasks that we&#8217;ve decided to undertake while doing this project was to switch from our current authentication system to a standards-based OAuth 2.0 authentication and authorization system.  This was (is) a large undertaking and included building the likes of an OAuth 2.0 server, building and supporting new OAuth 2.0 compatible clients, as well as converting all existing systems to the new one.  As part of this project, I ended up creating some OAuth 2.0 libraries that our touch-tooling applications use to interact with our system.  While doing this, I realized that a lot of this work can easily be open-sourced and used with any OAuth 2.0 compliant service!  And so, here we are!</p>
<p>&nbsp;<br />
<strong>Out in the Open</strong><br />
What I&#8217;ve created is exactly how it sounds: an OAuth 2.0 library for ActionScript.  It abides by the OAuth 2.0 specification (<a href="http://tools.ietf.org/html/draft-ietf-oauth-v2-15" target="_blank">version 2.15</a>) and so is compatible with any OAuth 2.0 service!  That includes services like Facebook Platform, Google APIs, Foursquare APIs, and many many more.</p>
<p>&nbsp;<br />
<strong>What it Does</strong><br />
If you are unfamiliar with the OAuth 2.0 workflow, it is really quite simple&#8230;</p>
<ol>
<li>Your application makes a request to the server to get an access token.
<ul>
<li>An access token is what is used to access a protected resource, say, an API to post a status update.</li>
</ul>
</li>
<li>The user authenticates and authorizes the use of said protected resource by the application on behalf of the user.
<ul>
<li>For example, the user logs in and allows your application to post a status update on their behalf.</li>
</ul>
</li>
<li>An access token is granted and returned back to your application.
<ul>
<li>The access token will be restricted for use with only the specific permissions that were authorized in Step 2.</li>
</ul>
</li>
<li>You use the access token for whatever you want!
<ul>
<li>Using the same example, your application then uses this token to make a call to update your status.</li>
</ul>
</li>
</ol>
<p>The library is only in charge of steps 1-3.  It will just get you your access token.  What you do with it, and what API calls you make with it, are up to you.</p>
<p>&nbsp;<br />
<strong>How to Use It</strong><br />
This library is designed for use in mobile devices using AIR.  Because of that, it makes use of the StageWebView object to display the user consent page (the form that the user must log into and authorize your application in Step 2).  I&#8217;ve created a very simple mobile demo application that does exactly this.  Here is the important part of the code&#8230;</p>

<div class="wp_syntax"><table><tr><td class="code"><pre class="actionscript" style="font-family:monospace;"><span style="color: #808080; font-style: italic;">// set up our StageWebView object to use our visible stage</span>
stageWebView.<span style="color: #0066CC;">stage</span> = <span style="color: #0066CC;">stage</span>;
&nbsp;
<span style="color: #808080; font-style: italic;">// set up the call</span>
<span style="color: #000000; font-weight: bold;">var</span> oauth2:OAuth2 = <span style="color: #000000; font-weight: bold;">new</span> OAuth2<span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">&quot;https://accounts.google.com/o/oauth2/auth&quot;</span>, <span style="color: #ff0000;">&quot;https://accounts.google.com/o/oauth2/token&quot;</span>, LogSetupLevel.<span style="color: #006600;">ALL</span><span style="color: #66cc66;">&#41;</span>;
<span style="color: #000000; font-weight: bold;">var</span> grant:IGrantType = <span style="color: #000000; font-weight: bold;">new</span> AuthorizationCodeGrant<span style="color: #66cc66;">&#40;</span>stageWebView, <span style="color: #ff0000;">&quot;INSERT_CLIENT_ID_HERE&quot;</span>, <span style="color: #ff0000;">&quot;INSERT_CLIENT_SECRET_HERE&quot;</span>, <span style="color: #ff0000;">&quot;http://www.mysite.com&quot;</span>, <span style="color: #ff0000;">&quot;https://www.googleapis.com/auth/userinfo.profile&quot;</span><span style="color: #66cc66;">&#41;</span>;
&nbsp;
<span style="color: #808080; font-style: italic;">// make the call</span>
oauth2.<span style="color: #006600;">addEventListener</span><span style="color: #66cc66;">&#40;</span>GetAccessTokenEvent.<span style="color: #0066CC;">TYPE</span>, onGetAccessToken<span style="color: #66cc66;">&#41;</span>;
oauth2.<span style="color: #006600;">getAccessToken</span><span style="color: #66cc66;">&#40;</span>grant<span style="color: #66cc66;">&#41;</span>;
&nbsp;
<span style="color: #000000; font-weight: bold;">function</span> onGetAccessToken<span style="color: #66cc66;">&#40;</span>getAccessTokenEvent:GetAccessTokenEvent<span style="color: #66cc66;">&#41;</span>:<span style="color: #0066CC;">void</span>
<span style="color: #66cc66;">&#123;</span>
	<span style="color: #b1b100;">if</span> <span style="color: #66cc66;">&#40;</span>getAccessTokenEvent.<span style="color: #006600;">errorCode</span> == <span style="color: #000000; font-weight: bold;">null</span> <span style="color: #66cc66;">&amp;&amp;</span> getAccessTokenEvent.<span style="color: #006600;">errorMessage</span> == <span style="color: #000000; font-weight: bold;">null</span><span style="color: #66cc66;">&#41;</span>
	<span style="color: #66cc66;">&#123;</span>
		<span style="color: #808080; font-style: italic;">// success!</span>
		<span style="color: #0066CC;">trace</span><span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">&quot;Your access token value is: &quot;</span> + getAccessTokenEvent.<span style="color: #006600;">accessToken</span><span style="color: #66cc66;">&#41;</span>;
	<span style="color: #66cc66;">&#125;</span>
	<span style="color: #b1b100;">else</span>
	<span style="color: #66cc66;">&#123;</span>
		<span style="color: #808080; font-style: italic;">// fail :(</span>
	<span style="color: #66cc66;">&#125;</span>
<span style="color: #66cc66;">&#125;</span>  <span style="color: #808080; font-style: italic;">// onGetAccessToken</span></pre></td></tr></table></div>

<p>You&#8217;ll see that the code is quite simple.  First, we set up the StageWebView object.  Then, we prepare the OAuth2 object by invoking its constructor with the appropriate values.  In the third step, we attach an event-listener and make the call.  Finally, in the event handler function, we handle the response.  That&#8217;s it!</p>
<p>&nbsp;<br />
<strong>Demo</strong><br />
I&#8217;ve created a sample demo application that demonstrates the usage of this library.  Using the same sample code as above (with the appropriate values filled in), connecting to Google&#8217;s OAuth 2.0 APIs, the sample app looks like this&#8230;</p>
<p><a href="http://blogs.adobe.com/charles/files/2012/05/oauth-demo.png"><img src="http://blogs.adobe.com/charles/files/2012/05/oauth-demo-thumb.png" alt="" title="oauth-demo-thumb" width="900" height="437" class="aligncenter size-full wp-image-847" /></a></p>
<p>Take it for a spin and let me know what you think!</p>
<p><center><a href="https://github.com/charlesbihis/sandbox/tree/master/actionscript/actionscript-oauth2-mobile-demo">ActionScript OAuth 2.0 Mobile Demo Application</a></center></p>
<p>&nbsp;<br />
<strong>Code, please!</strong><br />
I&#8217;ve released the code under the <a href="http://www.apache.org/licenses/LICENSE-2.0.html">Apache License, Version 2.0</a> and made it all available on GitHub!  Please, fork and extend!</p>
<p><center><a href="https://github.com/charlesbihis/actionscript-oauth2">ActionScript OAuth 2.0 Library</a></center></p>
<p>That&#8217;s it!  Hopefully some of you will find this project useful.  And as always, I love hearing from you so let me know what you think!  Happy coding =)</p>
<p>&nbsp;<br />
<strong>Update</strong>: As requested, I&#8217;ve removed the dependencies on the Flex framework so this library is now a pure AS3 library.  Enjoy!</p>
<p>&nbsp;<br />
Charles</p>
]]></content:encoded>
			<wfw:commentRss>http://blogs.adobe.com/charles/2012/05/oauth-2-0-library-for-actionscript.html/feed</wfw:commentRss>
		<slash:comments>54</slash:comments>
		</item>
		<item>
		<title>ActionScript Notification Engine!  Open-Sourced!</title>
		<link>http://blogs.adobe.com/charles/2012/02/actionscript-notification-engine-open-sourced.html</link>
		<comments>http://blogs.adobe.com/charles/2012/02/actionscript-notification-engine-open-sourced.html#comments</comments>
		<pubDate>Mon, 20 Feb 2012 21:56:19 +0000</pubDate>
		<dc:creator>Charles Bihis</dc:creator>
				<category><![CDATA[Actionscript]]></category>
		<category><![CDATA[AIR]]></category>
		<category><![CDATA[Facebook Desktop]]></category>
		<category><![CDATA[Open Source]]></category>
		<category><![CDATA[Programming]]></category>
		<category><![CDATA[Projects]]></category>
		<category><![CDATA[actionscript]]></category>
		<category><![CDATA[engine]]></category>
		<category><![CDATA[library]]></category>
		<category><![CDATA[notification engine]]></category>
		<category><![CDATA[notifications]]></category>
		<category><![CDATA[opensource]]></category>
		<category><![CDATA[programming]]></category>

		<guid isPermaLink="false">http://blogs.adobe.com/charles/?p=769</guid>
		<description><![CDATA[Last year, I posted about a side project that I was working on. Dubbed &#8220;Facebook Desktop&#8220;, it is essentially a notification engine that I built that would give you updates about your Facebook friends in real time! It became quite &#8230; <a href="http://blogs.adobe.com/charles/2012/02/actionscript-notification-engine-open-sourced.html">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
				<content:encoded><![CDATA[<p>Last year, I posted about a <a href="http://blogs.adobe.com/charles/2011/01/introducing-facebook-desktop-a-lightweight-unobtrusive-notification-engine-for-facebook-built-on-adobe-air.html">side project</a> that I was working on. Dubbed &#8220;<a href="http://www.facebookdesktop.com/">Facebook Desktop</a>&#8220;, it is essentially a notification engine that I built that would give you updates about your Facebook friends in real time! It became quite popular and I ended up building it out over the next year, pushing out 6 new releases in that time (<a href="https://www.facebook.com/note.php?note_id=351993388163620">0.80</a>, <a href="https://www.facebook.com/note.php?note_id=351995958163363">0.81</a>, <a href="https://www.facebook.com/note.php?note_id=352003041495988">0.82</a>, <a href="https://www.facebook.com/note.php?note_id=352004718162487">0.83</a>, <a href="https://www.facebook.com/note.php?note_id=352007178162241">0.84</a>, and <a href="https://www.facebook.com/note.php?note_id=369152879781004">0.85</a>). Well, I&#8217;ve decided to contribute to the community and open-source the primary component in Facebook Desktop, the notification engine!</p>
<p><center><img class="aligncenter size-full wp-image-794" title="ActionScript Notification Engine Open Sourced!" src="http://blogs.adobe.com/charles/files/2012/02/actionscript-notification-engine-open-sourced-notification1.png" alt="" width="311" height="81" /></center></p>
<p><strong>Project M6D Magnum Sidearm</strong><br />
That&#8217;s right, I codenamed my notification engine project &#8220;Project M6D Magnum Sidearm&#8221; (I have a weird naming convention for projects :p). Anyways, it is exactly how it sounds. It is a cross-platform, notification engine built on top of Adobe AIR. With a very simple interface, you can drop it into any AIR project and allow it to deliver messenger-style notifications to your users! Think Growl, but for all platforms :)</p>
<p><em>Mac</em>:                                                                         <em>Windows</em>:<br />
<a href="http://blogs.adobe.com/charles/files/2012/02/notification-engine-on-mac.png"><img title="notification-engine-on-mac" src="http://blogs.adobe.com/charles/files/2012/02/notification-engine-on-mac-thumb.png" alt="" width="270" /></a><a href="http://blogs.adobe.com/charles/files/2012/02/notification-engine-on-windows.png"><img title="notification-engine-on-windows" src="http://blogs.adobe.com/charles/files/2012/02/notification-engine-on-windows-thumb.png" alt="" width="270" /></a></p>
<p><strong>What can it do?</strong><br />
If you&#8217;re familiar with the <a href="http://www.facebookdesktop.com/">Facebook Desktop</a> project that this engine was built for, it supports all of the features that you see being used in that project, including&#8230;</p>
<ul>
<li>Ability to display messenger-toast notifications as well as compact notifications.</li>
<li>Variable display length for notifications.</li>
<li>User-presence logic that detects when the user goes idle. If the user is away from the computer, notifications are held on-screen and queued for when the user returns.</li>
<li>Ability to replay the most five recent notifications.</li>
<li>Individual notification post settings, such as sticky, replayable, custom image, click URL, compact, etc.</li>
<li>Operating system detection to set logical default display locations for notifications for the various platforms (i.e. bottom-right on Windows, top-right on Mac).</li>
<li>Smart repositioning logic for extended length toasts.</li>
<li>Ability to see a summary notification when the user returns from idle after an extended period of time.</li>
<li>Support for changing notificaion images.</li>
<li>Custom styling which can be applied at run-time.</li>
<li>Optional notification sound.</li>
</ul>
<p>These are just a few of the really cool features that we&#8217;ve built into this engine.<br />
<strong>How can I use it?</strong><br />
Even though we&#8217;ve added a lot of powerful features to this library, using it is very easy! All you have to do is include the SWC (or source) into your project, and follow the patterns below&#8230;</p>

<div class="wp_syntax"><table><tr><td class="code"><pre class="actionscript" style="font-family:monospace;"><span style="color: #808080; font-style: italic;">// create engine with default settings</span>
<span style="color: #000000; font-weight: bold;">var</span> notificationManager:NotificationManager =
	<span style="color: #000000; font-weight: bold;">new</span> NotificationManager<span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">&quot;/assets/style/dark.swf&quot;</span>,		   <span style="color: #808080; font-style: italic;">// default style</span>
				<span style="color: #ff0000;">&quot;/assets/m6d-magnum-sidearm-50x50.png&quot;</span>,	   <span style="color: #808080; font-style: italic;">// default notification image</span>
				<span style="color: #ff0000;">&quot;/assets/m6d-magnum-sidearm-16x16.png&quot;</span>,	   <span style="color: #808080; font-style: italic;">// default compact notification image</span>
				<span style="color: #ff0000;">&quot;/assets/sounds/drop.mp3&quot;</span>		   <span style="color: #808080; font-style: italic;">// (optional) default notification sound</span>
				NotificationConst.<span style="color: #006600;">DISPLAY_LENGTH_DEFAULT</span>,  <span style="color: #808080; font-style: italic;">// (optional) default display length</span>
				NotificationConst.<span style="color: #006600;">DISPLAY_LOCATION_AUTO</span><span style="color: #66cc66;">&#41;</span>;  <span style="color: #808080; font-style: italic;">// (optional) default display location</span>
&nbsp;
<span style="color: #808080; font-style: italic;">// now that we have an engine, let's create a notification and show it</span>
<span style="color: #000000; font-weight: bold;">var</span> notification:Notification = <span style="color: #000000; font-weight: bold;">new</span> Notification<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;
notification.<span style="color: #006600;">title</span> = <span style="color: #ff0000;">&quot;Derek ► Jacobim&quot;</span>;
notification.<span style="color: #0066CC;">message</span> = <span style="color: #ff0000;">&quot;What is this?  A center for ANTS?!&quot;</span>;
notification.<span style="color: #006600;">image</span> = <span style="color: #ff0000;">&quot;/assets/images/profile/derek/avatar.png&quot;</span>;
notification.<span style="color: #006600;">link</span> = <span style="color: #ff0000;">&quot;http://www.youtube.com/watch?v=_6GqqIvfSVQ&quot;</span>;
notification.<span style="color: #006600;">isCompact</span> = <span style="color: #000000; font-weight: bold;">false</span>;
notification.<span style="color: #006600;">isSticky</span> = <span style="color: #000000; font-weight: bold;">false</span>;
notification.<span style="color: #006600;">isReplayable</span> = <span style="color: #000000; font-weight: bold;">true</span>;
notificationManager.<span style="color: #006600;">showNotification</span><span style="color: #66cc66;">&#40;</span>notification<span style="color: #66cc66;">&#41;</span>;
&nbsp;
<span style="color: #808080; font-style: italic;">// we can also show notifications quickly using this API too</span>
notificationManager.<span style="color: #0066CC;">show</span><span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">&quot;Derek Zoolander Foundation&quot;</span>, <span style="color: #ff0000;">&quot;Now open!&quot;</span>, <span style="color: #ff0000;">&quot;/assets/images/dzf-logo-50x50.png&quot;</span><span style="color: #66cc66;">&#41;</span>;</pre></td></tr></table></div>

<p>And that&#8217;s all it takes for you to add robust notifications to your application. You can even change many of the engines settings on the fly!</p>

<div class="wp_syntax"><table><tr><td class="code"><pre class="actionscript" style="font-family:monospace;"><span style="color: #808080; font-style: italic;">// let's change the default images, display length, and display location</span>
notificationManager.<span style="color: #006600;">defaultNotificationImage</span> = <span style="color: #ff0000;">&quot;/assets/images/dzf-logo-50x50.png&quot;</span>;
notificationManager.<span style="color: #006600;">defaultCompactNotificationImage</span> = <span style="color: #ff0000;">&quot;/assets/images/dzf-logo-16x16.png&quot;</span>;
notificationManager.<span style="color: #006600;">displayLength</span> = NotificationConst.<span style="color: #006600;">DISPLAY_LENGTH_SHORT</span>;
notificationManager.<span style="color: #006600;">displayLocation</span> = NotificationConst.<span style="color: #006600;">DISPLAY_LOCATION_TOP_RIGHT</span>;
&nbsp;
<span style="color: #808080; font-style: italic;">// we can even change the style and sound settings on the fly too!</span>
notificationManager.<span style="color: #006600;">loadStyle</span><span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">&quot;/assets/style/light.swf&quot;</span><span style="color: #66cc66;">&#41;</span>;
notificationManager.<span style="color: #0066CC;">loadSound</span><span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">&quot;/assets/sounds/bing.mp3&quot;</span><span style="color: #66cc66;">&#41;</span>;</pre></td></tr></table></div>

<p>For those of you that want <em>all</em> the details, you can check out the ASDocs <a href="http://charlesbihis.github.com/actionscript-notification-engine/docs/">here</a>.<br />
<strong>Demo</strong><br />
I&#8217;ve also created a sample demo application that you can install and see the engine work in real time! It has an interface like this&#8230;</p>
<p><center><a href="http://blogs.adobe.com/charles/files/2012/02/actionscript-notification-engine-test-console.png"><img class="aligncenter size-full wp-image-797" title="ActionScript Notification Engine Test Console" src="http://blogs.adobe.com/charles/files/2012/02/actionscript-notification-engine-test-console.png" alt="" width="500" /></a></center></p>
<p>&#8230;where you can quickly test out all of the features of the engine! Take it for a spin and let me know what you think!</p>
<p><center><a href="http://www.facebookdesktop.com/download/ActionScriptNotificationEngineTestConsole.air">Download Notification Engine Test Console</a></center></p>
<p><strong>Code, please!</strong><br />
I&#8217;ve released the code under the <a href="http://www.apache.org/licenses/LICENSE-2.0.html">Apache License, Version 2.0</a> and made it all available on GitHub! Please, fork and extend!</p>
<p><center><a href="http://charlesbihis.github.com/actionscript-notification-engine/">ActionScript Notification Engine on GitHub</a></center></p>
<p>That&#8217;s it for now! Hopefully some of you will find this project useful. And as always, I love hearing from you so let me know what you think! Until next time, happy coding =)</p>
<p>Charles</p>
]]></content:encoded>
			<wfw:commentRss>http://blogs.adobe.com/charles/2012/02/actionscript-notification-engine-open-sourced.html/feed</wfw:commentRss>
		<slash:comments>15</slash:comments>
		</item>
		<item>
		<title>Diff Library for ActionScript</title>
		<link>http://blogs.adobe.com/charles/2011/12/diff-library-for-actionscript.html</link>
		<comments>http://blogs.adobe.com/charles/2011/12/diff-library-for-actionscript.html#comments</comments>
		<pubDate>Fri, 16 Dec 2011 23:16:34 +0000</pubDate>
		<dc:creator>Charles Bihis</dc:creator>
				<category><![CDATA[Actionscript]]></category>
		<category><![CDATA[Open Source]]></category>
		<category><![CDATA[Programming]]></category>
		<category><![CDATA[actionscript]]></category>
		<category><![CDATA[algorithms]]></category>
		<category><![CDATA[diff]]></category>
		<category><![CDATA[library]]></category>
		<category><![CDATA[opensource]]></category>
		<category><![CDATA[programming]]></category>

		<guid isPermaLink="false">http://blogs.adobe.com/charles/?p=695</guid>
		<description><![CDATA[I was working on an interesting automation project here at Adobe recently. In short, we wanted to have a utility that shows a particular set of configurations and settings on our various servers and indicates to us if any of &#8230; <a href="http://blogs.adobe.com/charles/2011/12/diff-library-for-actionscript.html">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
				<content:encoded><![CDATA[<p>I was working on an interesting automation project here at Adobe recently.  In short, we wanted to have a utility that shows a particular set of configurations and settings on our various servers and indicates to us if any of the servers are different from the rest, configuration-wise.  Sounds simple, right?  Sure!  So, I thought it would be cool to enhance this a bit and instead of just indicating that yes, there is a difference, I would indicate exactly what that difference was.</p>
<p>Since I&#8217;m working predominately with text files, the first thing that came to mind was a diff algorithm. (D&#8217;uh!) The front-end for the tool that we use is built in Flex, and so I started looking for a diff algorithm implementation in ActionScript.  No luck.  Guess I&#8217;ll have to write my own :\  I started doing some research on the various approaches to diff algorithms and came to the consensus that the Myer&#8217;s diff algorithm<a href="#ref1"><sup>[1]</sup></a> is widely accepted as the best general-purpose diff algorithm around.  After about 6 pages into the research paper, though, I realized it would take too long to grok this all and implement it from scratch.  So, instead, I found an implementation of the Myer&#8217;s diff algorithm and ported it to ActionScript.  A few hours later, it was done!</p>
<p><center><object width="636" height="2281"><param name="src" value="http://blogs.adobe.com/charles/files/2011/12/actionscript-diff-demo.swf" /><embed type="application/x-shockwave-flash" width="636" height="281" src="http://blogs.adobe.com/charles/files/2011/12/actionscript-diff-demo.swf"></embed></object></center></p>
<p>As you can tell from the example above, text additions are green, and omissions are red.  Any text that is the same remains black.  And that&#8217;s it!</p>
<p>&nbsp;<br />
<strong>Usage</strong>:<br />
The usage is quite straightforward, too.  There is really only one API, diff(), and it takes two parameters, the before-text and after-text.  Done!</p>

<div class="wp_syntax"><table><tr><td class="code"><pre class="actionscript" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">var</span> diffs:<span style="color: #0066CC;">Array</span> = <span style="color: #000000; font-weight: bold;">new</span> Diff<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>.<span style="color: #006600;">diff</span><span style="color: #66cc66;">&#40;</span>beforeText.<span style="color: #0066CC;">text</span>, afterText.<span style="color: #0066CC;">text</span><span style="color: #66cc66;">&#41;</span>;</pre></td></tr></table></div>

<p>The result that you get back is an Array of the different operations that it took to go from the original string to the modified string.  You can easily use this to display the differences in whatever way you want!</p>
<p>&nbsp;<br />
<strong>Code</strong>:<br />
The code is too long to post here, but you can find it in my GitHub project -> <a href="https://github.com/charlesbihis/actionscript-diff">https://github.com/charlesbihis/actionscript-diff</a></p>
<p>&nbsp;<br />
Enjoy!</p>
<p>&nbsp;<br />
Charles</p>
<p><a name="ref1"><sup>[1]</sup></a> <a href="http://neil.fraser.name/software/diff_match_patch/myers.pdf">&#8220;An O(ND) Difference Algorithm and Its Variations&#8221; by Eugene W. Myers</a></p>
]]></content:encoded>
			<wfw:commentRss>http://blogs.adobe.com/charles/2011/12/diff-library-for-actionscript.html/feed</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>Facebook Desktop &#8211; We&#8217;re international, baby!</title>
		<link>http://blogs.adobe.com/charles/2011/05/facebook-desktop-were-international-baby.html</link>
		<comments>http://blogs.adobe.com/charles/2011/05/facebook-desktop-were-international-baby.html#comments</comments>
		<pubDate>Thu, 19 May 2011 05:18:06 +0000</pubDate>
		<dc:creator>Charles Bihis</dc:creator>
				<category><![CDATA[Adobe]]></category>
		<category><![CDATA[AIR]]></category>
		<category><![CDATA[Facebook Desktop]]></category>
		<category><![CDATA[Projects]]></category>
		<category><![CDATA[air]]></category>
		<category><![CDATA[crowd-sourcing]]></category>
		<category><![CDATA[facebook]]></category>
		<category><![CDATA[facebook desktop]]></category>
		<category><![CDATA[internationalization]]></category>
		<category><![CDATA[localization]]></category>

		<guid isPermaLink="false">http://blogs.adobe.com/charles/?p=665</guid>
		<description><![CDATA[Some of you might remember a side-project of mine that I announced here which I called Facebook Desktop.  In short, it was a small application that I initially wrote for myself to help me stay in touch with my friends &#8230; <a href="http://blogs.adobe.com/charles/2011/05/facebook-desktop-were-international-baby.html">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
				<content:encoded><![CDATA[<p>Some of you might remember a side-project of mine that I <a title="Introducing “Facebook Desktop” – A Lightweight, Unobtrusive Notification Engine for Facebook Built on Adobe AIR" href="http://blogs.adobe.com/charles/2011/01/introducing-facebook-desktop-a-lightweight-unobtrusive-notification-engine-for-facebook-built-on-adobe-air.html">announced here</a> which I called <a title="Facebook Desktop - Bringing Facebook to your desktop, one notification at a time." href="http://www.facebookdesktop.com">Facebook Desktop</a>.  In short, it was a small application that I initially wrote for myself to help me stay in touch with my friends and family through Facebook.  It would sit in my system tray or dock and quietly push messenger-style toast notifications to my screen whenever something happened in my Facebook stream.  Neat, huh?  I thought so.  So, I built it out and eventually released it as a free app for everyone to use!  Since then, it&#8217;s actually picked up quite a bit of steam and now enjoys thousands of users from all over the world!</p>
<p><strong>Pleasantly Surprised</strong><br />
I&#8217;ve had a couple of releases since I first announced it, but this latest release is special and so I wanted to mention it here.  The popularity of the app, especially overseas, took me by surprise.  Considering this started out as a small utility I built for myself over a weekend, I didn&#8217;t anticipate it being used overseas.  But now, it&#8217;s actually used in over 20 countries all around the globe!  In fact, the bulk of our users are overseas!  After noticing this, I made the decision to devote the entire next release into adding language support for all of our international users.</p>
<p><center><img title="What's on your mind?" src="http://www.facebookdesktop.com/images/whats-on-your-mind-german.png" width="510" height="124" /></center></p>
<p>Technically, localizing the application wasn&#8217;t a problem (I&#8217;ve had <a title="Localization in Flex – Part 1: Compiling resources into an application " href="http://www.adobe.com/devnet/flex/articles/flex_localization_pt1.html">some</a> <a title="Localization in Flex – Part 2: Loading resources at runtime " href="http://www.adobe.com/devnet/flex/articles/flex-localization-pt2.html">experience</a> in the area).  The bigger problem was actually getting all of the text I use in the app translated to all of the various languages I wanted to support.  Then, someone posted a beautiful message on our <a title="Facebook Desktop" href="https://www.facebook.com/apps/application.php?id=95615112563">Facebook application page</a>.</p>
<p style="text-align: center;"><em>&#8220;Are you adding support for German?  If so, I volunteer to translate!&#8221;</em></p>
<p>Shortly after, a comment: &#8220;Me too, for Italian!&#8221;.  And another: &#8220;I can do Hindi&#8221;.  That&#8217;s when it hit me&#8230;<em>crowdsourcing</em>!</p>
<p><strong>The Power of the Community</strong><br />
I&#8217;ve never done it before, and there are plenty of ways that it can blow up in my face, but it was obvious to me that our users wanted it, but more importantly, were willing to help make it happen!  So, I took advantage of it!  The next day, I posted a message to our page asking if there is anyone willing to help translate Facebook Desktop in their native language.  The response was amazing!  At the end of the day, we had over 30 responses with people volunteering to translate in over a dozen languages!</p>
<p>I couldn&#8217;t ignore this, and so I took everyone up on their offer and started getting all of the text translated.  A couple of months later, a bit of coding, and a lot testing, it&#8217;s released!  Facebook Desktop v0.84 <a title="Facebook Desktop v0.84 - We're international, baby!" href="https://www.facebook.com/notes/desktop/facebook-desktop-v084-were-international-baby/201676706541273">went live last night</a> at midnight with support for a whopping SIXTEEN languages.</p>
<p><center><img title="Settings" src="http://www.facebookdesktop.com/images/settings-language.png" width="510" height="273" /></center></p>
<p><strong>Together is Better</strong><br />
This version of Facebook Desktop could not have been accomplished without the help of the community.  Plain and simple.  On top of that, engaging with the users in this way made this release that much more fun too!  In the future, I&#8217;ll definitely be looking to involve our users more.  It&#8217;s better for them, it&#8217;s better for me, and it&#8217;s better for the app!  To infinity, and beyond!</p>
<p>&nbsp;</p>
<p>Charles</p>
]]></content:encoded>
			<wfw:commentRss>http://blogs.adobe.com/charles/2011/05/facebook-desktop-were-international-baby.html/feed</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>Relative Time Library for ActionScript</title>
		<link>http://blogs.adobe.com/charles/2011/05/relative-time-library-for-actionscript.html</link>
		<comments>http://blogs.adobe.com/charles/2011/05/relative-time-library-for-actionscript.html#comments</comments>
		<pubDate>Tue, 03 May 2011 18:03:51 +0000</pubDate>
		<dc:creator>Charles Bihis</dc:creator>
				<category><![CDATA[Actionscript]]></category>
		<category><![CDATA[Facebook Desktop]]></category>
		<category><![CDATA[Open Source]]></category>
		<category><![CDATA[Programming]]></category>
		<category><![CDATA[actionscript]]></category>
		<category><![CDATA[library]]></category>
		<category><![CDATA[opensource]]></category>
		<category><![CDATA[programming]]></category>
		<category><![CDATA[relative time]]></category>

		<guid isPermaLink="false">http://blogs.adobe.com/charles/?p=629</guid>
		<description><![CDATA[While working on a side-project of mine, I came across the need to display dates and times as relative instead of absolute. You know, saying &#8220;two hours ago&#8221; instead of &#8220;Mon Jan 5 17:24:33 GMT-0700 2011&#8243;. Since the web is &#8230; <a href="http://blogs.adobe.com/charles/2011/05/relative-time-library-for-actionscript.html">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
				<content:encoded><![CDATA[<p>While working on a <a title="Introducing Facebook Desktop - A Notification Engine for Facebook Built on Adobe AIR" href="http://blogs.adobe.com/charles/2011/01/introducing-facebook-desktop-a-lightweight-unobtrusive-notification-engine-for-facebook-built-on-adobe-air.html">side-project</a> of mine, I came across the need to display dates and times as relative instead of absolute.  You know, saying &#8220;two hours ago&#8221; instead of &#8220;Mon Jan 5 17:24:33 GMT-0700 2011&#8243;.  Since the web is going real-time these days, it just makes sense.  Besides, <a title="Facebook" href="http://www.facebook.com/">everyone&#8217;s</a> <a title="Twitter" href="http://www.twitter.com/">doing</a> <a title="FourSquare" href="http://www.foursquare.com/">it</a>, so it must be good!  Anyways, I wrote a library (really, just a simple class) that you can use to do this with ActionScript.  It&#8217;s really quite simple, but since I couldn&#8217;t find it anywhere else, I thought I&#8217;d contribute it here for everyone to use too.  Here it is in action&#8230;</p>
<p>&nbsp;</p>
<p><center><object width="500" height="250"><param name="src" value="http://blogs.adobe.com/charles/files/2011/05/relative-date-demo.swf" /><embed type="application/x-shockwave-flash" width="500" height="250" src="http://blogs.adobe.com/charles/files/2011/05/relative-date-demo.swf"></embed></object></center></p>
<p>If you&#8217;re wondering, I&#8217;ve tried to follow the convention that Facebook uses for what format to display and when.  Twitter has a very similar format, but I decided to go with Facebook&#8217;s.  Also, if you notice, my library can handle times in the future as well as times in the past.  Here&#8217;s how to use it&#8230;</p>
<p><strong>Usage</strong>:</p>
<p>Once you&#8217;ve added the library to your project, it&#8217;s really quite easy to use.  Just call any of the two available APIs and pass in a date or two and you&#8217;ll get back the relative time string.  Done!</p>

<div class="wp_syntax"><table><tr><td class="code"><pre class="actionscript" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">var</span> relativeTime:<span style="color: #0066CC;">String</span> = RelativeDate.<span style="color: #006600;">getRelativeDate</span><span style="color: #66cc66;">&#40;</span>firstDate, secondDate<span style="color: #66cc66;">&#41;</span>;
<span style="color: #000000; font-weight: bold;">var</span> relativeTime:<span style="color: #0066CC;">String</span> = RelativeDate.<span style="color: #006600;">getRelativeDateFromNow</span><span style="color: #66cc66;">&#40;</span>someDate<span style="color: #66cc66;">&#41;</span>;</pre></td></tr></table></div>

<p><strong>Code</strong>:<br />
Finally, here is the code in all it&#8217;s glory!</p>

<div class="wp_syntax"><table><tr><td class="code"><pre class="actionscript" style="font-family:monospace;">package com.<span style="color: #006600;">adobe</span>.<span style="color: #0066CC;">date</span>
<span style="color: #66cc66;">&#123;</span>
	<span style="color: #0066CC;">import</span> com.<span style="color: #006600;">adobe</span>.<span style="color: #006600;">utils</span>.<span style="color: #006600;">DateUtil</span>;
&nbsp;
	<span style="color: #808080; font-style: italic;">/**
	 * Utility class to help create human-readable Strings representing
	 * the difference in time from two different dates (e.g. &quot;just now&quot;
	 * or &quot;2 hours ago&quot; or &quot;13 minutes from now&quot;).
	 *
	 * @langversion ActionScript 3.0
	 * @playerversion Flash 10.0
	 */</span>
	<span style="color: #0066CC;">public</span> <span style="color: #000000; font-weight: bold;">class</span> RelativeDate
	<span style="color: #66cc66;">&#123;</span>
		<span style="color: #0066CC;">private</span> <span style="color: #0066CC;">static</span> const SECONDS_PER_MINUTE:uint = <span style="color: #cc66cc;">60</span>;
		<span style="color: #0066CC;">private</span> <span style="color: #0066CC;">static</span> const SECONDS_PER_TWO_MINUTES:uint = <span style="color: #cc66cc;">120</span>;
		<span style="color: #0066CC;">private</span> <span style="color: #0066CC;">static</span> const SECONDS_PER_HOUR:uint = <span style="color: #cc66cc;">3600</span>;
		<span style="color: #0066CC;">private</span> <span style="color: #0066CC;">static</span> const SECONDS_PER_TWO_HOURS:uint = <span style="color: #cc66cc;">7200</span>;
		<span style="color: #0066CC;">private</span> <span style="color: #0066CC;">static</span> const SECONDS_PER_DAY:uint = <span style="color: #cc66cc;">86400</span>;
		<span style="color: #0066CC;">private</span> <span style="color: #0066CC;">static</span> const SECONDS_PER_TWO_DAYS:uint = <span style="color: #cc66cc;">172800</span>;
		<span style="color: #0066CC;">private</span> <span style="color: #0066CC;">static</span> const SECONDS_PER_THREE_DAYS:uint = <span style="color: #cc66cc;">259200</span>;
&nbsp;
		<span style="color: #808080; font-style: italic;">/**
		 * Creates a human-readable String representing the difference
		 * in time from the date provided and now.  This method handles
		 * dates in both the past and the future (e.g. &quot;2 hours ago&quot;
		 * and &quot;2 hours from now&quot;.  For any date beyond 3 days difference
		 * from now, then a standard format is returned.
		 *
		 * @param date The date for which to compare against.
		 *
		 * @return Human-readable String representing the time elapsed.
		 */</span>
		<span style="color: #0066CC;">public</span> <span style="color: #0066CC;">static</span> <span style="color: #000000; font-weight: bold;">function</span> getRelativeDateFromNow<span style="color: #66cc66;">&#40;</span><span style="color: #0066CC;">date</span>:<span style="color: #0066CC;">Date</span>, capitalizeFirstLetter:<span style="color: #0066CC;">Boolean</span> = <span style="color: #000000; font-weight: bold;">false</span><span style="color: #66cc66;">&#41;</span>:<span style="color: #0066CC;">String</span>
		<span style="color: #66cc66;">&#123;</span>
			<span style="color: #b1b100;">return</span> getRelativeDate<span style="color: #66cc66;">&#40;</span><span style="color: #0066CC;">date</span>, <span style="color: #000000; font-weight: bold;">new</span> <span style="color: #0066CC;">Date</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>, capitalizeFirstLetter<span style="color: #66cc66;">&#41;</span>;
		<span style="color: #66cc66;">&#125;</span>
&nbsp;
		<span style="color: #808080; font-style: italic;">/**
		 * Creates a human-readable String representing the difference
		 * in time from the first date provided with respect to the
		 * second date provided.  If no second date is provided, then
		 * the relative date will be calcluated with respect to &quot;now&quot;.
		 * This method handles dates in both the past and the
		 * future (e.g. &quot;2 hours ago&quot; and &quot;2 hours from now&quot;.  For
		 * any date beyond 3 days difference from now, then a
		 * standard format is returned.
		 *
		 * @param firstDate The date for which to compare against.
		 * @param secondDate The date to use as &quot;present&quot; when comparing against firstDate.
		 *
		 * @return Human-readable String representing the time elapsed.
		 */</span>
		<span style="color: #0066CC;">public</span> <span style="color: #0066CC;">static</span> <span style="color: #000000; font-weight: bold;">function</span> getRelativeDate<span style="color: #66cc66;">&#40;</span>firstDate:<span style="color: #0066CC;">Date</span>, secondDate:<span style="color: #0066CC;">Date</span> = <span style="color: #000000; font-weight: bold;">null</span>, capitalizeFirstLetter:<span style="color: #0066CC;">Boolean</span> = <span style="color: #000000; font-weight: bold;">false</span><span style="color: #66cc66;">&#41;</span>:<span style="color: #0066CC;">String</span>
		<span style="color: #66cc66;">&#123;</span>
			<span style="color: #000000; font-weight: bold;">var</span> relativeDate:<span style="color: #0066CC;">String</span>;
			<span style="color: #000000; font-weight: bold;">var</span> isFuture:<span style="color: #0066CC;">Boolean</span> = <span style="color: #000000; font-weight: bold;">false</span>;
&nbsp;
			<span style="color: #b1b100;">if</span> <span style="color: #66cc66;">&#40;</span>secondDate == <span style="color: #000000; font-weight: bold;">null</span><span style="color: #66cc66;">&#41;</span>
			<span style="color: #66cc66;">&#123;</span>
				secondDate = <span style="color: #000000; font-weight: bold;">new</span> <span style="color: #0066CC;">Date</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;
			<span style="color: #66cc66;">&#125;</span>
&nbsp;
			<span style="color: #808080; font-style: italic;">// the difference between the passed-in date and now, in seconds</span>
			<span style="color: #000000; font-weight: bold;">var</span> secondsElapsed:<span style="color: #0066CC;">Number</span> = <span style="color: #66cc66;">&#40;</span>secondDate.<span style="color: #0066CC;">getTime</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span> - firstDate.<span style="color: #0066CC;">getTime</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">/</span> <span style="color: #cc66cc;">1000</span>;
&nbsp;
			<span style="color: #b1b100;">if</span> <span style="color: #66cc66;">&#40;</span>secondsElapsed <span style="color: #66cc66;">&lt;</span> <span style="color: #cc66cc;">0</span><span style="color: #66cc66;">&#41;</span>
			<span style="color: #66cc66;">&#123;</span>
				isFuture = <span style="color: #000000; font-weight: bold;">true</span>;
				secondsElapsed = <span style="color: #0066CC;">Math</span>.<span style="color: #0066CC;">abs</span><span style="color: #66cc66;">&#40;</span>secondsElapsed<span style="color: #66cc66;">&#41;</span>;
			<span style="color: #66cc66;">&#125;</span>
&nbsp;
			<span style="color: #b1b100;">switch</span><span style="color: #66cc66;">&#40;</span><span style="color: #000000; font-weight: bold;">true</span><span style="color: #66cc66;">&#41;</span>
			<span style="color: #66cc66;">&#123;</span>
				<span style="color: #b1b100;">case</span> secondsElapsed <span style="color: #66cc66;">&lt;</span> SECONDS_PER_MINUTE:
					relativeDate = <span style="color: #ff0000;">&quot;just now&quot;</span>;
					<span style="color: #b1b100;">break</span>;
				<span style="color: #b1b100;">case</span> secondsElapsed <span style="color: #66cc66;">&lt;</span> SECONDS_PER_TWO_MINUTES:
					relativeDate = <span style="color: #ff0000;">&quot;1 minute &quot;</span> + <span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#40;</span>isFuture<span style="color: #66cc66;">&#41;</span> ? <span style="color: #ff0000;">&quot;from now&quot;</span> : <span style="color: #ff0000;">&quot;ago&quot;</span><span style="color: #66cc66;">&#41;</span>;
					<span style="color: #b1b100;">break</span>;
				<span style="color: #b1b100;">case</span> secondsElapsed <span style="color: #66cc66;">&lt;</span> SECONDS_PER_HOUR:
					relativeDate = <span style="color: #0066CC;">int</span><span style="color: #66cc66;">&#40;</span>secondsElapsed <span style="color: #66cc66;">/</span> SECONDS_PER_MINUTE<span style="color: #66cc66;">&#41;</span> + <span style="color: #ff0000;">&quot; minutes &quot;</span> + <span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#40;</span>isFuture<span style="color: #66cc66;">&#41;</span> ? <span style="color: #ff0000;">&quot;from now&quot;</span> : <span style="color: #ff0000;">&quot;ago&quot;</span><span style="color: #66cc66;">&#41;</span>;
					<span style="color: #b1b100;">break</span>;
				<span style="color: #b1b100;">case</span> secondsElapsed <span style="color: #66cc66;">&lt;</span> SECONDS_PER_TWO_HOURS:
					relativeDate = <span style="color: #ff0000;">&quot;about an hour &quot;</span> + <span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#40;</span>isFuture<span style="color: #66cc66;">&#41;</span> ? <span style="color: #ff0000;">&quot;from now&quot;</span> : <span style="color: #ff0000;">&quot;ago&quot;</span><span style="color: #66cc66;">&#41;</span>;
					<span style="color: #b1b100;">break</span>;
				<span style="color: #b1b100;">case</span> secondsElapsed <span style="color: #66cc66;">&lt;</span> SECONDS_PER_DAY:
					relativeDate = <span style="color: #0066CC;">int</span><span style="color: #66cc66;">&#40;</span>secondsElapsed <span style="color: #66cc66;">/</span> SECONDS_PER_HOUR<span style="color: #66cc66;">&#41;</span> + <span style="color: #ff0000;">&quot; hours &quot;</span> + <span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#40;</span>isFuture<span style="color: #66cc66;">&#41;</span> ? <span style="color: #ff0000;">&quot;from now&quot;</span> : <span style="color: #ff0000;">&quot;ago&quot;</span><span style="color: #66cc66;">&#41;</span>;
					<span style="color: #b1b100;">break</span>;
				<span style="color: #b1b100;">case</span> secondsElapsed <span style="color: #66cc66;">&lt;</span> SECONDS_PER_TWO_DAYS:
					relativeDate = <span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#40;</span>isFuture<span style="color: #66cc66;">&#41;</span> ? <span style="color: #ff0000;">&quot;tomorrow&quot;</span> : <span style="color: #ff0000;">&quot;yesterday&quot;</span><span style="color: #66cc66;">&#41;</span> + <span style="color: #ff0000;">&quot; at &quot;</span> + DateUtil.<span style="color: #006600;">getShortHour</span><span style="color: #66cc66;">&#40;</span>firstDate<span style="color: #66cc66;">&#41;</span> + <span style="color: #ff0000;">&quot;:&quot;</span> + getMinutesString<span style="color: #66cc66;">&#40;</span>firstDate<span style="color: #66cc66;">&#41;</span> + DateUtil.<span style="color: #006600;">getAMPM</span><span style="color: #66cc66;">&#40;</span>firstDate<span style="color: #66cc66;">&#41;</span>.<span style="color: #0066CC;">toLowerCase</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;
					<span style="color: #b1b100;">break</span>;
				<span style="color: #b1b100;">case</span> secondsElapsed <span style="color: #66cc66;">&lt;</span> SECONDS_PER_THREE_DAYS:
					relativeDate = DateUtil.<span style="color: #006600;">getFullDayName</span><span style="color: #66cc66;">&#40;</span>firstDate<span style="color: #66cc66;">&#41;</span> + <span style="color: #ff0000;">&quot; at &quot;</span> + DateUtil.<span style="color: #006600;">getShortHour</span><span style="color: #66cc66;">&#40;</span>firstDate<span style="color: #66cc66;">&#41;</span> + <span style="color: #ff0000;">&quot;:&quot;</span> + getMinutesString<span style="color: #66cc66;">&#40;</span>firstDate<span style="color: #66cc66;">&#41;</span> + DateUtil.<span style="color: #006600;">getAMPM</span><span style="color: #66cc66;">&#40;</span>firstDate<span style="color: #66cc66;">&#41;</span>.<span style="color: #0066CC;">toLowerCase</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;
					<span style="color: #b1b100;">break</span>;
				<span style="color: #000000; font-weight: bold;">default</span>:
					relativeDate = DateUtil.<span style="color: #006600;">getFullMonthName</span><span style="color: #66cc66;">&#40;</span>firstDate<span style="color: #66cc66;">&#41;</span> + <span style="color: #ff0000;">&quot; &quot;</span> + firstDate.<span style="color: #0066CC;">getDate</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span> + <span style="color: #ff0000;">&quot; at &quot;</span> + DateUtil.<span style="color: #006600;">getShortHour</span><span style="color: #66cc66;">&#40;</span>firstDate<span style="color: #66cc66;">&#41;</span> + <span style="color: #ff0000;">&quot;:&quot;</span> + getMinutesString<span style="color: #66cc66;">&#40;</span>firstDate<span style="color: #66cc66;">&#41;</span> + DateUtil.<span style="color: #006600;">getAMPM</span><span style="color: #66cc66;">&#40;</span>firstDate<span style="color: #66cc66;">&#41;</span>.<span style="color: #0066CC;">toLowerCase</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>
					<span style="color: #b1b100;">break</span>;
			<span style="color: #66cc66;">&#125;</span>
&nbsp;
			<span style="color: #b1b100;">return</span> <span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#40;</span>capitalizeFirstLetter<span style="color: #66cc66;">&#41;</span> ? relativeDate.<span style="color: #0066CC;">substring</span><span style="color: #66cc66;">&#40;</span><span style="color: #cc66cc;">0</span>, <span style="color: #cc66cc;">1</span><span style="color: #66cc66;">&#41;</span>.<span style="color: #0066CC;">toUpperCase</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span> + relativeDate.<span style="color: #0066CC;">substring</span><span style="color: #66cc66;">&#40;</span><span style="color: #cc66cc;">1</span>, relativeDate.<span style="color: #0066CC;">length</span><span style="color: #66cc66;">&#41;</span> : relativeDate<span style="color: #66cc66;">&#41;</span>;
		<span style="color: #66cc66;">&#125;</span>
&nbsp;
		<span style="color: #808080; font-style: italic;">/**
		 * @private
		 */</span>
		<span style="color: #0066CC;">private</span> <span style="color: #0066CC;">static</span> <span style="color: #000000; font-weight: bold;">function</span> getMinutesString<span style="color: #66cc66;">&#40;</span><span style="color: #0066CC;">date</span>:<span style="color: #0066CC;">Date</span><span style="color: #66cc66;">&#41;</span>:<span style="color: #0066CC;">String</span>
		<span style="color: #66cc66;">&#123;</span>
			<span style="color: #b1b100;">return</span> <span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#40;</span><span style="color: #0066CC;">date</span>.<span style="color: #006600;">minutes</span> <span style="color: #66cc66;">&lt;</span> <span style="color: #cc66cc;">10</span><span style="color: #66cc66;">&#41;</span> ? <span style="color: #ff0000;">&quot;0&quot;</span> : <span style="color: #ff0000;">&quot;&quot;</span><span style="color: #66cc66;">&#41;</span> + <span style="color: #0066CC;">date</span>.<span style="color: #006600;">minutes</span>;
		<span style="color: #66cc66;">&#125;</span>
	<span style="color: #66cc66;">&#125;</span>
<span style="color: #66cc66;">&#125;</span></pre></td></tr></table></div>

<p>Hopefully, this can help someone out there looking to do the same!  Also, see the code in my <a href="https://github.com/charlesbihis/actionscript-relative-date">GitHub repo</a>!</p>
<p>Until next time, happy coding!</p>
<p>Charles</p>
<p><strong><sup>*</sup>Note</strong>: Shout-out to <a href="http://www.joelhooks.com/">Joel Hooks</a> for creating and sharing his awesome <a href="http://joelhooks.com/2008/10/11/flex-date-and-time-datetime-picker-control/">date-picker</a> component!</p>
]]></content:encoded>
			<wfw:commentRss>http://blogs.adobe.com/charles/2011/05/relative-time-library-for-actionscript.html/feed</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>ActionScript Puzzler &#8211; The Joy of Millisecs</title>
		<link>http://blogs.adobe.com/charles/2011/03/actionscript-puzzler-the-joy-of-millisecs.html</link>
		<comments>http://blogs.adobe.com/charles/2011/03/actionscript-puzzler-the-joy-of-millisecs.html#comments</comments>
		<pubDate>Thu, 24 Mar 2011 20:47:24 +0000</pubDate>
		<dc:creator>Charles Bihis</dc:creator>
				<category><![CDATA[Actionscript]]></category>
		<category><![CDATA[ActionScript-Puzzler]]></category>
		<category><![CDATA[Programming]]></category>
		<category><![CDATA[Puzzler]]></category>
		<category><![CDATA[actionscript]]></category>
		<category><![CDATA[challenge]]></category>
		<category><![CDATA[problem]]></category>
		<category><![CDATA[programming]]></category>
		<category><![CDATA[puzzler]]></category>

		<guid isPermaLink="false">http://blogs.adobe.com/charles/?p=587</guid>
		<description><![CDATA[Note: This is the same puzzler that was featured in the March issue of the Adobe Edge newsletter! It&#8217;s about that time again&#8230;time for another Puzzler! I&#8217;ve written a few before, in a couple of languages too, but this will &#8230; <a href="http://blogs.adobe.com/charles/2011/03/actionscript-puzzler-the-joy-of-millisecs.html">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
				<content:encoded><![CDATA[<style type="text/css">
.summarySection {
	margin-left: 20px;
	margin-right: 10px;
}
.summaryTableTitle {
	font-weight: bold;
	font-size: 18px;
	padding-top: 20px;
	padding-bottom: 5px;
}
* .summaryTable {
	margin-top: 10px;
	border: #999999 1px solid;
	width: 100%;
	margin-bottom: 20px;
}
html>body .summaryTable {
	margin-top: 10px;
	border: #999999 1px solid;
	width: 100%;
	margin-bottom: 20px;
	margin-right: 10px;
}
.summaryTable th {
	color: #FFFFFF;
	background-color: #627C9D;
	white-space: nowrap;
}
.summaryTable td {
	border-top: #999999 1px solid;
	vertical-align: top;
}
.summaryTablePaddingCol {
	width: 5px;
}
.summaryTableInheritanceCol {
	width: 14px;
}
.summaryTableSignatureCol {
	padding-right: 10px;
}
.summaryTableOperatorCol {
	padding-left: 10px;
	padding-right: 10px;
	font-weight: bold;
}
.summaryTableStatementCol {
	padding-left: 10px;
	padding-right: 10px;
	font-weight: bold;
	white-space: nowrap;
}
.summarySignature {
	text-indent: -20px;
	padding-left: 20px;
}
.summaryTableOwnerCol {
	padding-right: 10px;
	width: 10px;
}
.summaryTableCol, .summaryTableSecondCol {
}
.signatureLink {
	font-weight: bold;
}
.summaryTableDescription {
	color: #333333;
}
.summaryTableLastCol {
	padding-right: 10px;
}
.inheritedSummaryImage {
	width: 14px;
	height: 14px;
}
</style>
<p><strong>Note: This is the same puzzler that was <a href="http://www.adobe.com/newsletters/edge/march2011/articles/article7/index.html">featured</a> in the March issue of the <a href="http://www.adobe.com/newsletters/edge/">Adobe Edge newsletter</a>!</strong></p>
<p>It&#8217;s about that time again&#8230;time for another <a href="http://blogs.adobe.com/charles/category/puzzler">Puzzler</a>!  I&#8217;ve written a few before, in a couple of languages too, but this will be my first in ActionScript!  I know I have a lot of Flash readers, so hopefully this will be extra &#8216;puzzling&#8217; for you (see what I did there?).  For those that don&#8217;t know what a Puzzler is, it is essentially a short problem used to demonstrate special cases or &#8220;features&#8221; of a particular language.  Here is the format:</p>
<ol>
<li><strong>Code</strong> &#8211; I introduce the code</li>
<li><strong>Question</strong> &#8211; I pose a multiple-choice question and you guess what the outcome is&#8230;think hard!</li>
<li><strong>Walkthrough</strong> &#8211; I walk through a reasonable explanation</li>
<li><strong>Answer</strong> &#8211; I tell you the <em>real</em> outcome (it might surprise you), and explain why</li>
<li><strong>Moral</strong> &#8211; How can we avoid making mistakes like this in our own code</li>
</ol>
<p>Now that we all know what a Puzzler is, here is a simple ActionScript Puzzler:</p>
<p><strong>Code</strong>:</p>

<div class="wp_syntax"><table><tr><td class="code"><pre class="actionscript" style="font-family:monospace;"><span style="color: #808080; font-style: italic;">// declare key dates</span>
<span style="color: #000000; font-weight: bold;">var</span> now:<span style="color: #0066CC;">Date</span> = <span style="color: #000000; font-weight: bold;">new</span> <span style="color: #0066CC;">Date</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;
<span style="color: #000000; font-weight: bold;">var</span> birthday:<span style="color: #0066CC;">Date</span> = <span style="color: #000000; font-weight: bold;">new</span> <span style="color: #0066CC;">Date</span><span style="color: #66cc66;">&#40;</span><span style="color: #cc66cc;">1940</span>, 06, <span style="color: #cc66cc;">27</span><span style="color: #66cc66;">&#41;</span>; <span style="color: #808080; font-style: italic;">// Bugs Bunny’s birthday!</span>
&nbsp;
<span style="color: #808080; font-style: italic;">// save them as milliseconds since epoch</span>
<span style="color: #000000; font-weight: bold;">var</span> nowInMs:<span style="color: #0066CC;">int</span> = now.<span style="color: #0066CC;">getTime</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;
<span style="color: #000000; font-weight: bold;">var</span> birthdayInMs:<span style="color: #0066CC;">int</span> = birthday.<span style="color: #0066CC;">getTime</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;
&nbsp;
<span style="color: #808080; font-style: italic;">// get the difference to calculate Bugs’ age in milliseconds</span>
<span style="color: #000000; font-weight: bold;">var</span> millisecondsElapsed:<span style="color: #0066CC;">int</span> = nowInMs - birthdayInMs;
&nbsp;
<span style="color: #808080; font-style: italic;">// sanity check</span>
<span style="color: #b1b100;">if</span> <span style="color: #66cc66;">&#40;</span>millisecondsElapsed == now.<span style="color: #0066CC;">getTime</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span> - birthday.<span style="color: #0066CC;">getTime</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span>
<span style="color: #66cc66;">&#123;</span>
	<span style="color: #0066CC;">trace</span><span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">&quot;What’s up, Doc?&quot;</span><span style="color: #66cc66;">&#41;</span>;
<span style="color: #66cc66;">&#125;</span></pre></td></tr></table></div>

<p>What does this print?</p>
<ol style="list-style: lower-alpha;">
<li>Nothing</li>
<li>&#8220;What&#8217;s up, Doc?&#8221;</li>
<li>Throws an exception</li>
<li>None of the above</li>
</ol>
<p><strong>Walkthrough</strong>:</p>
<p>Alright, it looks like we are just trying to compute Bugs Bunny’s age in milliseconds, from the time he was “born” until now.  First, we create the key dates.  We have <em>now</em> initialized to the current date (as in the date this program is executed), and <em>birthday</em> initialized to Bug Bunny&#8217;s birthday.  We then go and save those times as milliseconds since epoch so that we can easily do some date math with these two dates.  Next, we calculate the difference of Bugs’ birthday (in ms) from now (also in ms) which should give us the total milliseconds elapsed since he was born.  Finally, we do a sanity check.  In the sanity check, we essentially duplicate the math we’ve done previously: calculate the difference from Bugs’ birthday until now, in milliseconds.  This should obviously be true, and so we trace “What’s up, Doc?” to the debug console.<br />
<br />&nbsp;<br />
<center><strong>*SPOILER ALERT &#8211; ANSWER BELOW*</strong></center><br />
<br />&nbsp;<br />
<br />&nbsp;<br />
<br />&nbsp;<br />
<br />&nbsp;<br />
<br />&nbsp;<br />
<br />&nbsp;<br />
<br />&nbsp;<br />
<br />&nbsp;<br />
<br />&nbsp;<br />
<br />&nbsp;<br />
<br />&nbsp;<br />
<br />&nbsp;<br />
<br />&nbsp;<br />
<br />&nbsp;<br />
<br />&nbsp; </p>
<p><strong>Answer</strong>:</p>
<p>The answer is a – nothing!  How does this happen?  Well, we must be skipping over the trace statement.  That would only occur if the sanity check fails.  But the sanity check does exactly what is done earlier on in the code&#8230;almost!  The key error in this code is that <strong>there is an implicit narrowing type-cast</strong>!  Where is it?  Let’s take a look at the description of the Date class in the ActionScript 3 LiveDocs.  In the documentation for the Date.getTime() method, we get the following function prototype:</p>
<table class="summaryTable " id="summaryTableMethod" cellpadding="3" cellspacing="0">
<tbody>
<tr>
<th>&nbsp;</th>
<th colspan="2">Method</th>
<th class="summaryTableOwnerCol">Defined By</th>
</tr>
<tr class="" bgcolor="#FFFFFF">
<td class="summaryTablePaddingCol">&nbsp;</td>
<td class="summaryTableInheritanceCol">&nbsp;</td>
<td class="summaryTableSignatureCol">
<div class="summarySignature">
					<a href="http://livedocs.adobe.com/flash/9.0/ActionScriptLangRefV3/Date.html#getTime()" class="signatureLink">getTime</a>():<a href="http://livedocs.adobe.com/flash/9.0/ActionScriptLangRefV3/Number.html">Number</a></div>
<div class="summaryTableDescription">
					Returns the number of milliseconds since midnight January 1, 1970, universal time, for a Date object.
				</div>
</td>
<td class="summaryTableOwnerCol">Date</td>
</tr>
</tbody>
</table>
<p>Date.getTime() returns a Number!  And we are storing that number in an int.  In ActionScript, a Number uses the IEEE-754 double-precision floating-point specification, and therefore can use 53 bits to represent integer values.  Comparing this to only 32 bits used by int and uint, we can see that Numbers can be used to represent values well beyond the range of the int and uint data types.  Because of this implicit type-cast, <strong>our millisecond time gets narrowed and loses precision!</strong>  Now, knowing this, it is easy to see why our sanity check fails.  Our int variable millisecondsElapsed does not, in fact, store the total milliseconds elapsed since Bug Bunny was born, but rather, it stores the total milliseconds elapsed since he was born, truncated to 32 bits.  Therefore, the sanity check fails, the if-statement falls through, and the trace statement never gets executed.</p>
<p><strong>Moral</strong>:</p>
<p>Although in some other languages, implicit narrowing type-casts cause warnings or even compilation errors, in ActionScript, they do not.  So, whenever you are storing or working with numbers, be aware of the size of the numbers as well as the data-types floating around.  Implicit casts do occur (and often, in any language), but implicit narrowing casts will go unnoticed by the compiler, and likely by you as well…until now :)</p>
<p>That&#8217;s it for this Puzzler!  Hope you enjoyed!  Happy coding!<br />
<br />&nbsp;<br />
<br />&nbsp;<br />
Charles</p>
<p><a href="http://blogs.adobe.com/charles/files/2011/03/actionscript-puzzler-the-joy-of-millisecs.zip"><img class="size-full wp-image-93" title="winzip_logo" src="http://blogs.adobe.com/charles/files/2010/11/winzip_logo-e1289008526983.gif" alt="" width="50" height="50" align="center" /></a> <strong><a href="http://blogs.adobe.com/charles/files/2011/03/actionscript-puzzler-the-joy-of-millisecs.zip">actionscript-puzzler-the-joy-of-millisecs.zip</a></strong> (source code)</p>
]]></content:encoded>
			<wfw:commentRss>http://blogs.adobe.com/charles/2011/03/actionscript-puzzler-the-joy-of-millisecs.html/feed</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
	</channel>
</rss>
