<?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>The bAS3 Class &#187; ActionScript</title>
	<atom:link href="http://www.brandondement.com/blog/category/actionscript/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.brandondement.com/blog</link>
	<description>Adventures in software development</description>
	<lastBuildDate>Thu, 02 Sep 2010 05:56:30 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.8.5</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>FITC San Francisco</title>
		<link>http://www.brandondement.com/blog/2010/08/21/fitc-san-francisco/</link>
		<comments>http://www.brandondement.com/blog/2010/08/21/fitc-san-francisco/#comments</comments>
		<pubDate>Sat, 21 Aug 2010 22:40:40 +0000</pubDate>
		<dc:creator>Brandon</dc:creator>
				<category><![CDATA[ActionScript]]></category>
		<category><![CDATA[Flash Player]]></category>
		<category><![CDATA[Flex]]></category>
		<category><![CDATA[conference]]></category>
		<category><![CDATA[flash]]></category>
		<category><![CDATA[performance]]></category>

		<guid isPermaLink="false">http://www.brandondement.com/blog/?p=118</guid>
		<description><![CDATA[FITC held it&#8217;s first ever event in San Francisco last week where they brought together some of the most creative and innovative minds from Flash&#8217;s design and development communities.  I had heard about previous FITC events and their increasing reputation for great speakers, educational sessions, and never-before-seen demos experiments, so when I heard they were [...]]]></description>
			<content:encoded><![CDATA[<div><a href="http://www.fitc.ca/" target="_blank">FITC</a> held it&#8217;s first ever event in San Francisco last week where they brought together some of the most creative and innovative minds from Flash&#8217;s design and development communities.  I had heard about previous FITC events and their increasing reputation for great speakers, educational sessions, and never-before-seen demos experiments, so when I heard they were coming to my new home, San Francisco, I have to admit I got a little giddy.</div>
<div>They sent out an early call for volunteers which I jumped on in a heartbeat.  Being a volunteer was a no-brainer for me, it saved a ton of money and for just a little bit of my time I got access to most of the sessions as well as an inside look into how FITC works and what it takes to put it together.  I met several of the FITC staff and chatted with them about their jobs of putting on these events all across the world.  It&#8217;s an impressive feat for them to orchestrate so many moving parts remotely, fly to a new city and have them all fall into place, then turn and do it all over again just a couple months later in another new city!  I also thought it was really funny how all these Canadians were caught totally by surprise by San Francisco&#8217;s chilly Summer weather, it was warmer in most parts of Canada than it was in SF!</div>
<div>I went to several sessions including the <a href="http://www.fitc.ca/events/presentations/presentation.cfm?event=110&amp;presentation_id=1219" target="_blank">Adobe Keynote</a> with Kevin Lynch, <a href="http://www.fitc.ca/events/presentations/presentation.cfm?event=110&amp;presentation_id=1290">Flex 4 Lifecycle Best Practices</a> with Aaron Pedersen &amp; James Polanco, and <a href="http://www.fitc.ca/events/presentations/presentation.cfm?event=110&amp;presentation_id=1230">High Performance Mobile Content with Flash</a> with Mike Chambers</div>
<div>The Adobe Keynote was great and renewed my confidence that Flash is and will be an integral part of the Internet for a long time to come.  For example, cell handset makers are starting to advertise that their devices support Flash, even putting the Flash Player logo on their packaging.  I also asked Kevin Lynch a question that has been burning in my mind for a while about the capabilities of CS5&#8217;s Device Central.  His answer was really, really impressive.  Normally you would expect the first iteration of a major feature like Device Central to be somewhat underwhelming, but not so in this case, just a few of the features are:</div>
<div>
<ul>
<li><strong>Simulation of all input types and layouts</strong> &#8211; In Device Central you can see a little picture of the actual device your testing and play with each and every one of the buttons and input controls it suppors</li>
<li><strong>Memory and CPU Simulation</strong> &#8211; What&#8217;s more important on a mobile device than performance?  (See below!)  Device Central actually simulates the capabilities of the device you&#8217;re testing to let you know how your content will do.</li>
<li><strong>Radio interference</strong> &#8211; Kevin told a story about how some developers were actually taking test devices into elevators to test how their application performs with degraded reception, so they built this into Device Central!</li>
<li><strong>Screen glare</strong> &#8211; <a href="http://images.icanhascheezburger.com/completestore/2009/1/18/128767576807958566.jpg" target="_blank">Whaaaat?</a> Does your application have enough contrast to be seen when the device is being used outdoors?  Device Central can help you find out.</li>
</ul>
<p>Device Central is powerful, but no tool can guarantee that your app will work as designed in real world scenarios, so don&#8217;t forget to test yourself, on a real device, because as we all know: <a href="http://www.youtube.com/watch?v=svAs-6MiqxE" target="_blank">ain&#8217;t nothing like the real thing, baby</a>.</div>
<div>And finally, I attended Mike Chambers&#8217; session on mobile application performance.  I was going in hopes of picking up tips to apply to my day job as a game developer, and I wasn&#8217;t disappointed, as most of Mike&#8217;s tips could be applied to virtually any application, but is especially important when running in under-powered mobile environments.  Here are my Cliff&#8217;s notes:</div>
<div>
<ul>
<li><a href="https://prerelease.adobe.com/callout/default.html?callid={AEF64EB4-A977-4317-909A-14AD8014BA21}" target="_blank">Air 2.5 beta open</a> &#8211; Open to anyone who registers.   Repurposes most of the work done for iPhone development and applies it  to Android.</li>
<li><a href="http://Bit.ly/as3performance" target="_blank">Bit.ly/as3performance</a> &#8211; Grant Skinner&#8217;s performance testing framework</li>
<li><a href="http://github.com/MikeChambers" target="_blank">Github.com/MikeChambers</a> &#8211;  Mike Chambers&#8217; Simple Game Framework, a set of utility  classes to perform various game related functions like a Centralized  Game Loop, Object Pooling, Caching, etc.</li>
<li>Mobile support coming to next version of Flash Builder (don&#8217;t know any details of what this means)</li>
<li>ALL  vector rendering in AIR 2.5 is done via the GPU, which improves  performance on all devices and improves battery life on mobile devices</li>
<li>All  vectors on stage are rendered, regardless of screen position.  i.e. If  you move an object off-screen, it is still iterated over in the  rendering phase, wasting resources.  To improve this, set visible =  false.</li>
<li>A new property called &#8220;cacheAsBitmapMatrix&#8221; is now  available in AIR 2.5, and will be available in the Flash Player in a  near release.  Right now when you set cacheAsBitmap=true, and then scale  or rotate the bitmap, it has to be redrawn.  By setting the  cacheAsBitmapMatrix to a matrix (usually just the identity matrix), you  enable bitmap caching and greatly increase the performance of any redraws  that occur.</li>
<li>Performance  tip:  Do anything you can to prevent redraws (check the redraw regions  to figure out what&#8217;s being redrawn).  Things that force redraws are:  Using the drawing API, changing/moving an object or it&#8217;s children,  removing an object/child, or occluding non-cached objects.</li>
<li>Setting Array/vector.length = 0 is faster than setting array/vector = new Array/Vector</li>
<li>Object instantiation is very expensive, so instead of disposing objects, you can put them back in the pool and reuse them later.</li>
<li>Mouse  events are cheaper than touch events on mobile devices, and single  finger touch events are automatically translated to mouse events.  You  should use these mouse events instead of the touch events to improve  performance.</li>
<li>Avoid using mouse move which is fired really,  REALLY fast, and can cause lots of extra calculations that are made but go unused between frames.  Instead, do your  updates at the framerate by using ENTER_FRAME</li>
<li>In certain  areas where performance is super-important, consider using callbacks  rather than events. Event objects have to be created and propagated, which is expensive.</li>
<li>If you&#8217;re listening to an object that is deeply-nested in the display list, stop its propagation</li>
<li><a href="http://bytearray.org/?p=1363" target="_blank">Bytearray.org/?p=1363</a> &#8211;  A whitepaper called &#8220;Optimizing Performance for the ADOBE® FLASH®  PLATFORM&#8221; (attached), this is the single greatest resource for  performance tweaks I&#8217;ve ever come across.  It validates a lot of the techniques I&#8217;m already applying for game development, and points out a few others to  consider.</li>
</ul>
<p>All in all, the 1st annual FITC SF was a resounding success, and you can bet I&#8217;ll be back next year!</p></div>
]]></content:encoded>
			<wfw:commentRss>http://www.brandondement.com/blog/2010/08/21/fitc-san-francisco/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Flex Formatter Plugin</title>
		<link>http://www.brandondement.com/blog/2010/01/02/flex-formatter-plugin/</link>
		<comments>http://www.brandondement.com/blog/2010/01/02/flex-formatter-plugin/#comments</comments>
		<pubDate>Sat, 02 Jan 2010 23:05:50 +0000</pubDate>
		<dc:creator>Brandon</dc:creator>
				<category><![CDATA[ActionScript]]></category>
		<category><![CDATA[Flex]]></category>
		<category><![CDATA[flash builder]]></category>
		<category><![CDATA[flex builder]]></category>
		<category><![CDATA[plugin]]></category>

		<guid isPermaLink="false">http://www.brandondement.com/blog/?p=90</guid>
		<description><![CDATA[Code formatting is the reason for many a jihad between developers all over, and spending any time at all discussing it is a waste of time.  (So should I stop writing here?  No!  There is an answer!  Press on&#8230;)  Unfortunately this is one issue where it&#8217;s impossible to make everyone happy, so you have to [...]]]></description>
			<content:encoded><![CDATA[<p>Code formatting is the reason for many a jihad between developers all over, and spending any time at all discussing it is a <strong>waste</strong> of time.  (So should I stop writing here?  No!  There is an answer!  Press on&#8230;)  Unfortunately this is one issue where it&#8217;s impossible to make everyone happy, so you have to settle for making everyone equally <strong>UN</strong>happy.</p>
<p>A really painless way to do make everyone equally unhappy is to automate the formatting, and that&#8217;s where the amazing little gadget, the Flex Formatter plugin for Flex and Flash Builder comes in.</p>
<p>The plugin adds a few buttons to the toolbar area of Flex Builder.  These buttons are:</p>
<ul>
<li><strong>Generate ASDoc Comments</strong> &#8211; For your whole file!  In one click!</li>
<li><strong>Generate ASDoc Comment</strong> &#8211; For one item (also in one click!)</li>
<li><strong>Format Flex Code</strong> &#8211; Formats your entire MXML file (or selected lines) &#8230;.with one click</li>
<li><strong>Indent Flex Code</strong> &#8211; Not sure why you&#8217;d use this and not just the previous button, it seems to do the same thing</li>
<li><strong>Rearrange AS Code</strong> &#8211; Same as Format Flex Code, but for your AS files</li>
</ul>
<p>To install it, go to &#8220;Help, Software Updates, Find and Install&#8221; and install from the new remote site:</p>
<p>http://flexformatter.googlecode.com/svn/trunk/FlexFormatter/FlexPrettyPrintCommandUpdateSite/</p>
<p>Grant Skinner has a nice post on this, as well as a settings file that he has exported for use: <a href="http://www.gskinner.com/blog/archives/2009/12/indispensable_p.html" target="_blank">http://www.gskinner.com/blog/archives/2009/12/indispensable_p.html</a></p>
]]></content:encoded>
			<wfw:commentRss>http://www.brandondement.com/blog/2010/01/02/flex-formatter-plugin/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Love Thy Flex Builder Keyboard Shortcuts</title>
		<link>http://www.brandondement.com/blog/2009/11/24/love-thy-flex-builder-keyboard-shortcuts/</link>
		<comments>http://www.brandondement.com/blog/2009/11/24/love-thy-flex-builder-keyboard-shortcuts/#comments</comments>
		<pubDate>Wed, 25 Nov 2009 01:42:25 +0000</pubDate>
		<dc:creator>Brandon</dc:creator>
				<category><![CDATA[ActionScript]]></category>
		<category><![CDATA[Programming]]></category>
		<category><![CDATA[flash builder]]></category>
		<category><![CDATA[flex builder]]></category>

		<guid isPermaLink="false">http://www.brandondement.com/blog/?p=84</guid>
		<description><![CDATA[It never ceases to amaze me how after all the time I spend using Adobe’s tools, they always have a few more features that I’m not using but should be. So every now and then I go brush up on the keyboard shortcuts in Flex Builder, so here are a few highlights (Command = CTRL [...]]]></description>
			<content:encoded><![CDATA[<p><!--StartFragment--><span style="font-family: Calibri,Verdana,Helvetica,Arial;"><span style="font-size: 11pt;">It never ceases to amaze me how after all the time I spend using Adobe’s tools, they always have a few more features that I’m not using but should be. So every now and then I go brush up on the keyboard shortcuts in Flex Builder, so here are a few highlights (Command = CTRL if you’re on Windows):<br />
</span></span></p>
<ul>
<li><span style="font-family: Calibri,Verdana,Helvetica,Arial;"><span style="font-size: 11pt;"><strong>CTRL + 0 (even on Mac)</strong> &#8211; Quick Outline.  Hit this, then start typing to jump right to any variable or method definition in the class </span></span></li>
<li><span style="font-family: Calibri,Verdana,Helvetica,Arial;"><span style="font-size: 11pt;"><strong>Shift + Command + R</strong> – Open Resource.  Hit this, then start typing any file name to open it.  Works on all file types in your project </span></span></li>
<li><span style="font-family: Calibri,Verdana,Helvetica,Arial;"><span style="font-size: 11pt;"><strong>Command + L </strong>– Go To Line.  Opens a dialog where you type in a line number </span></span></li>
<li><span style="font-family: Calibri,Verdana,Helvetica,Arial;"><span style="font-size: 11pt;"><strong>Shift + Command + C</strong> – Puts a block comment around the selected text<br />
</span></span></li>
</ul>
<p><span style="font-family: Calibri,Verdana,Helvetica,Arial;"><span style="font-size: 11pt;">Strangely there doesn’t seem to be a definitive guide to shortcuts in FB, even the LiveDocs look rather incomplete:</span></span></p>
<p><a href="http://livedocs.adobe.com/flex/3/html/help.html?content=code_editor_9.html">http://livedocs.adobe.com/flex/3/html/help.html?content=code_editor_9.html</a></p>
<p>But a search for “flex builder keyboard shortcuts” returns results from tons of blogs.  Here are a few more gems that weren’t in the LiveDocs:</p>
<ul>
<li><span style="font-family: Calibri,Verdana,Helvetica,Arial;"><span style="font-size: 11pt;"><strong>Command + D</strong> – Deletes a line </span></span></li>
<li><span style="font-family: Calibri,Verdana,Helvetica,Arial;"><span style="font-size: 11pt;"><strong>Command + /</strong> &#8211; Comment/Uncomment a line </span></span></li>
<li><span style="font-family: Calibri,Verdana,Helvetica,Arial;"><span style="font-size: 11pt;"><strong>Shift + Command + D</strong> – Inserts an ASDoc-style comment, including parameter and return declarations! </span></span></li>
<li><span style="font-family: Calibri,Verdana,Helvetica,Arial;"><span style="font-size: 11pt;"><strong>Shift + Command + L</strong> – Opens an outline of all the keyboard shortcuts available<br />
</span></span></li>
</ul>
<p><span style="font-family: Calibri,Verdana,Helvetica,Arial;"><span style="font-size: 11pt;">Also, if any of these don’t suit you, you can always go change them!  In the main menu, click Flex Builder -&gt; Preferences -&gt; General -&gt; Keys (or just type “Keys” in the filter).  Coincidentally, <strong>this </strong>is the most definitive list I could find.</span></span></p>
<p>What keyboard shortcuts do you use that you can&#8217;t live without?</p>
<p><!--EndFragment--></p>
]]></content:encoded>
			<wfw:commentRss>http://www.brandondement.com/blog/2009/11/24/love-thy-flex-builder-keyboard-shortcuts/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>#FollowFriday Flash Edition</title>
		<link>http://www.brandondement.com/blog/2009/11/20/followfriday-flash-edition/</link>
		<comments>http://www.brandondement.com/blog/2009/11/20/followfriday-flash-edition/#comments</comments>
		<pubDate>Fri, 20 Nov 2009 18:57:53 +0000</pubDate>
		<dc:creator>Brandon</dc:creator>
				<category><![CDATA[ActionScript]]></category>
		<category><![CDATA[Twitter]]></category>

		<guid isPermaLink="false">http://www.brandondement.com/blog/?p=80</guid>
		<description><![CDATA[Twitter has quickly become the best source of up to date information about our beloved technology, Flash.  If you’re on Twitter already, here are a few things you might be interested in.  If you’re not on Twitter, here are a few links that should be enough to convince you why you should be!
If [...]]]></description>
			<content:encoded><![CDATA[<p>Twitter has quickly become the best source of up to date information about our beloved technology, Flash.  If you’re on Twitter already, here are a few things you might be interested in.  If you’re <strong>not</strong> on Twitter, here are a few links that should be enough to convince you why you <strong>should</strong> be!</p>
<p>If you have any more suggestions, please share in the comments!</p>
<p><a href="https://twitter.com/InsideRIA" target="_blank">https://twitter.com/InsideRIA</a><br />
InsideRIA.com is a community site from O&#8217;Reilly and Adobe for Rich Internet Application development and design.</p>
<p><a href="https://twitter.com/CreativeTweet" target="_blank">https://twitter.com/CreativeTweet</a><br />
A prolific tweeter who posts random but useful tips, tutorials, and links relevant to Flash and the rest of the Adobe Creative Suite</p>
<p><a href="http://listorious.com/Adobe/adobe-evangelists" target="_blank">http://listorious.com/Adobe/adobe-evangelists</a><br />
A list of Adobe Flash Platform Evangelists, most post great links and info</p>
<p><a href="http://listorious.com/pixelhandler/flash" target="_blank">http://listorious.com/pixelhandler/flash</a><br />
A hand-picked list of people who post about Flash, overlaps somewhat with the evangelists list</p>
<p><a href="https://twitter.com/adobeflash" target="_blank">https://twitter.com/adobeflash</a><br />
The PR face of Flash.  Rarely posts about tech stuff, but if you want to ask a question or have a comment, they’re a good starting place</p>
<p><a href="https://twitter.com/gskinner" target="_blank">https://twitter.com/gskinner</a><br />
Probably the most well known Flash developer in the world.  Ranked “Most Influential” in the ActionScript category by http://wefollow.com/twitter/actionscript</p>
<p><a href="https://twitter.com/fwa" target="_blank">https://twitter.com/fwa</a><br />
Cutting edge website award news, inspiration, latest trends and more from FWA (Favourite Website Awards) founder, Rob Ford.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.brandondement.com/blog/2009/11/20/followfriday-flash-edition/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Enforcing Abstract Classes in AS3</title>
		<link>http://www.brandondement.com/blog/2009/10/27/enforcing-abstract-classes-in-as3/</link>
		<comments>http://www.brandondement.com/blog/2009/10/27/enforcing-abstract-classes-in-as3/#comments</comments>
		<pubDate>Tue, 27 Oct 2009 19:18:40 +0000</pubDate>
		<dc:creator>Brandon</dc:creator>
				<category><![CDATA[ActionScript]]></category>
		<category><![CDATA[Design Patterns]]></category>

		<guid isPermaLink="false">http://www.brandondement.com/blog/?p=52</guid>
		<description><![CDATA[One of the most common criticisms of ActionScript is that it doesn&#8217;t include some of the more advance features of other object-oriented languages.  For example, Abstract classes.  Abstract classes are similar to Interfaces in that they provide a common API for: implementers of the interface or subclasses of the Abstract class.  At [...]]]></description>
			<content:encoded><![CDATA[<p>One of the most common criticisms of ActionScript is that it doesn&#8217;t include some of the more advance features of other object-oriented languages.  For example, Abstract classes.  Abstract classes are similar to Interfaces in that they provide a common API for: implementers of the interface or subclasses of the Abstract class.  At the same time, Interfaces and Abstract classes guarantee this common API for classes from other packages to work against.  The Abstract class takes it one step beyond the Interface in that it also adds real functionality to the base class which can reused in its subclasses.</p>
<p>So if ActionScript doesn&#8217;t enforce the Abstract class, how can you guarantee that someone down the line doesn&#8217;t start abusing it?  A passable answer to this question is the seldom-used &#8220;self&#8221; keyword, as seen here:</p>

<div class="wp_syntax"><div class="code"><pre class="actionscript" style="font-family:monospace;"><span style="color: #0066CC;">public</span> <span style="color: #000000; font-weight: bold;">function</span> AbstractClass<span style="color: #66cc66;">&#40;</span>self:AbstractClass<span style="color: #66cc66;">&#41;</span>
<span style="color: #66cc66;">&#123;</span>
	<span style="color: #b1b100;">if</span><span style="color: #66cc66;">&#40;</span>self <span style="color: #66cc66;">!</span>= <span style="color: #0066CC;">this</span><span style="color: #66cc66;">&#41;</span>
	<span style="color: #66cc66;">&#123;</span>
		<span style="color: #0066CC;">throw</span> <span style="color: #000000; font-weight: bold;">new</span> <span style="color: #0066CC;">Error</span><span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">&quot;Whoa!  You can't instantiate AbstractClass directly suckah!&quot;</span><span style="color: #66cc66;">&#41;</span>;
	<span style="color: #66cc66;">&#125;</span>
<span style="color: #66cc66;">&#125;</span></pre></div></div>

<p>The drawback to this method is that it&#8217;s not enforced at compile-time.  Instead, the error will be thrown at runtime and alert the developer that they did something wrong.  Further, there&#8217;s nothing stopping the developer from then catching the error and ignoring it.  Ruh roh.  So there is no real solution that guarantees the Abstract nature of the class is respected, but at least this little warning will deter all but the most irresponsible of programmers.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.brandondement.com/blog/2009/10/27/enforcing-abstract-classes-in-as3/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>AS3 Reference on Your iPhone</title>
		<link>http://www.brandondement.com/blog/2009/09/21/as3-reference-on-your-iphone/</link>
		<comments>http://www.brandondement.com/blog/2009/09/21/as3-reference-on-your-iphone/#comments</comments>
		<pubDate>Mon, 21 Sep 2009 20:32:19 +0000</pubDate>
		<dc:creator>Brandon</dc:creator>
				<category><![CDATA[ActionScript]]></category>
		<category><![CDATA[iPhone]]></category>

		<guid isPermaLink="false">http://www.brandondement.com/blog/?p=59</guid>
		<description><![CDATA[This has flown under my radar since January, but now that I know it exists, its a must-have!  I’ve played with it only briefly so far and noticed that it only includes the class references, more obscure things like keywords aren’t included, but it’s still super handy nonetheless.
Because all the data is stored locally, [...]]]></description>
			<content:encoded><![CDATA[<p>This has flown under my radar since January, but now that I know it exists, its a must-have!  I’ve played with it only briefly so far and noticed that it only includes the class references, more obscure things like keywords aren’t included, but it’s still super handy nonetheless.</p>
<p>Because all the data is stored locally, you can use it while you’re on the go without connectivity, and searching is super fast, even faster than opening a browser and searching if you have your phone handy.</p>
<p><a href="http://www.mikechambers.com/blog/2009/01/26/actionscript-3-reference-for-iphone/" target="_blank">http://www.mikechambers.com/blog/2009/01/26/actionscript-3-reference-for-iphone/</a></p>
<p><a href="http://www.mikechambers.com/blog/2009/01/26/actionscript-3-reference-for-iphone/"><img class="aligncenter size-medium wp-image-60" title="AS3 Reference for iPhone" src="http://www.brandondement.com/blog/wp-content/uploads/2009/10/3210160283_ecc4c5dc80_o-200x300.png" alt="AS3 Reference for iPhone" width="200" height="300" /></a></p>
]]></content:encoded>
			<wfw:commentRss>http://www.brandondement.com/blog/2009/09/21/as3-reference-on-your-iphone/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Flash Camp Atlanta</title>
		<link>http://www.brandondement.com/blog/2009/08/24/flash-camp-atlanta/</link>
		<comments>http://www.brandondement.com/blog/2009/08/24/flash-camp-atlanta/#comments</comments>
		<pubDate>Mon, 24 Aug 2009 17:54:09 +0000</pubDate>
		<dc:creator>Brandon</dc:creator>
				<category><![CDATA[ActionScript]]></category>
		<category><![CDATA[conference]]></category>

		<guid isPermaLink="false">http://www.brandondement.com/blog/?p=37</guid>
		<description><![CDATA[I just signed up for Flash Camp Atlanta!  It&#8217;s been a while since my last conference, the Adobe onAir Tour, so I&#8217;m very excited to spend another day geeking out with fellow Flash developers.  Although I&#8217;d like to see more Adobe employees, the guests, speakers, and sessions do look like they&#8217;ll be interesting.
The [...]]]></description>
			<content:encoded><![CDATA[<p>I just signed up for Flash Camp Atlanta!  It&#8217;s been a while since my last conference, the <a href="http://onair.adobe.com/">Adobe onAir Tour</a>, so I&#8217;m very excited to spend another day geeking out with fellow Flash developers.  Although I&#8217;d like to see more Adobe employees, <a href="http://events.universalmind.com/page.cfm/flash-camp-atlanta-2009/speakers-and-sessions">the guests, speakers, and sessions</a> do look like they&#8217;ll be interesting.</p>
<p>The networking opportunities are what&#8217;s really gotten me excited though.  Most of the people I work with are all much more experienced than I am and have been around the block a few times, so they know all the names around the interactive industry in Atlanta.  I want to put some faces with those names, as well as spread my own around a bit.</p>
<p style="text-align: center;"><a href="http://www.flashcampatlanta.com/" target="_blank"><img class="size-full wp-image-38 aligncenter" title="Flash Camp Atlanta Badge" src="http://www.brandondement.com/blog/wp-content/uploads/2009/08/fcatl-200.png" alt="Flash Camp Atlanta Badge" width="200" height="200" /></a><br />
<a href="http://www.flashcampatlanta.com/" target="_blank">FlashCampAtlanta.com</a></p>
]]></content:encoded>
			<wfw:commentRss>http://www.brandondement.com/blog/2009/08/24/flash-camp-atlanta/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Using a Simple PHP Proxy to Load Data Across Domains</title>
		<link>http://www.brandondement.com/blog/2009/08/23/using-a-simple-php-proxy-to-load-data-across-domains/</link>
		<comments>http://www.brandondement.com/blog/2009/08/23/using-a-simple-php-proxy-to-load-data-across-domains/#comments</comments>
		<pubDate>Sun, 23 Aug 2009 23:53:56 +0000</pubDate>
		<dc:creator>Brandon</dc:creator>
				<category><![CDATA[ActionScript]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[crossdomain]]></category>
		<category><![CDATA[web services]]></category>

		<guid isPermaLink="false">http://www.brandondement.com/blog/?p=26</guid>
		<description><![CDATA[The Flash Player doesn&#8217;t allow you to load and use data from other domains, even a subdomain of where you SWF is being served from.  Normally this can be worked around by editing the policy file, crossdomain.xml, of the domain where the data is located, but what can you do when the data you [...]]]></description>
			<content:encoded><![CDATA[<p>The Flash Player doesn&#8217;t allow you to load and use data from other domains, even a subdomain of where you SWF is being served from.  Normally this can be worked around by editing the policy file, crossdomain.xml, of the domain where the data is located, but what can you do when the data you want to load is owned by someone like Facebook or Twitter?  Chances are that you don&#8217;t have the kind of pull it would take to get them to change their policy files, so it&#8217;s time to implement a web service on the domain where the SWF is hosted.</p>
<p>I ran into this problem while working with the Twitter and Facebook APIs on my site.  Their APIs allow you to get names, URLs, and other interesting data points, but I wanted to load images, which aren&#8217;t delivered through the API.  To solve this problem, I wrote this dead-simple PHP script which simply forwards GET requests to a URL specified in the &#8220;url&#8221; parameter and displays the result back to the requester:</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">&lt;?php</span>
     <span style="color: #000088;">$content</span> <span style="color: #339933;">=</span> <span style="color: #990000;">file_get_contents</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$_GET</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'url'</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
     <span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$content</span> <span style="color: #339933;">!==</span> <span style="color: #009900; font-weight: bold;">false</span><span style="color: #009900;">&#41;</span> 
     <span style="color: #009900;">&#123;</span>   
          <span style="color: #b1b100;">echo</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$content</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
     <span style="color: #009900;">&#125;</span> 
     <span style="color: #b1b100;">else</span> 
     <span style="color: #009900;">&#123;</span>  
          <span style="color: #666666; font-style: italic;">// there was an error</span>
     <span style="color: #009900;">&#125;</span>
<span style="color: #000000; font-weight: bold;">?&gt;</span></pre></div></div>

<p>Of course this is the most simple of examples of a web service that you can get, and is really only useful for simple content like <a href="http://www.brandondement.com/proxy.php?url=http://twitter.com/crossdomain.xml" target="_blank">XML</a>, <a href="http://www.brandondement.com/proxy.php?url=http://www.google.com" target="_blank">HTML</a> and <a href="http://www.brandondement.com/proxy.php?url=http://photos-f.ak.fbcdn.net/hphotos-ak-snc1/hs130.snc1/5570_625691532119_12805853_36162773_4932061_n.jpg" target="_blank">images</a>.  Anything more complicated than this and you would want to create a proper web service with input validation, caching, etc., but this is a quick way to get up and running. </p>
<p>Note that your browser won&#8217;t render the proxy-ed image correctly because it doesn&#8217;t receive the correct content-type header, which tells the browser to expect an image.  What you&#8217;re seeing is actually the ASCII representation of the image&#8217;s binary data, known as <code>BitmapData</code> to the AS3 world.</p>
<p>Bonus!  It can be slow to go through your proxy when not needed, so I use this simple class to create <code>URLRequests</code> with the proper URL as determined by the SWF&#8217;s security sandbox:</p>

<div class="wp_syntax"><div class="code"><pre class="actionscript" style="font-family:monospace;">package com.<span style="color: #006600;">bdement</span>.<span style="color: #006600;">proxy</span>
<span style="color: #66cc66;">&#123;</span>
<span style="color: #0066CC;">import</span> flash.<span style="color: #006600;">net</span>.<span style="color: #006600;">URLRequest</span>;
<span style="color: #0066CC;">import</span> flash.<span style="color: #0066CC;">system</span>.<span style="color: #006600;">Security</span>;
&nbsp;
<span style="color: #0066CC;">public</span> <span style="color: #000000; font-weight: bold;">class</span> ProxyService
<span style="color: #66cc66;">&#123;</span>
	<span style="color: #0066CC;">public</span> <span style="color: #0066CC;">static</span> const PROXY_URL:<span style="color: #0066CC;">String</span> = <span style="color: #ff0000;">&quot;http://www.brandondement.com/proxy.php?url=&quot;</span>;		
&nbsp;
	<span style="color: #0066CC;">public</span> <span style="color: #000000; font-weight: bold;">function</span> ProxyService<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>
	<span style="color: #66cc66;">&#123;</span>
		<span style="color: #0066CC;">throw</span> <span style="color: #000000; font-weight: bold;">new</span> <span style="color: #0066CC;">Error</span><span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">&quot;All methods of ProxyService are static, do not instantiate!&quot;</span><span style="color: #66cc66;">&#41;</span>;	
	<span style="color: #66cc66;">&#125;</span>
&nbsp;
	<span style="color: #0066CC;">public</span> <span style="color: #0066CC;">static</span> <span style="color: #000000; font-weight: bold;">function</span> getProxyRequest<span style="color: #66cc66;">&#40;</span><span style="color: #0066CC;">url</span>:<span style="color: #0066CC;">String</span><span style="color: #66cc66;">&#41;</span> : URLRequest
	<span style="color: #66cc66;">&#123;</span>
		<span style="color: #b1b100;">if</span><span style="color: #66cc66;">&#40;</span><span style="color: #0066CC;">url</span> == <span style="color: #000000; font-weight: bold;">null</span><span style="color: #66cc66;">&#41;</span> <span style="color: #b1b100;">return</span> <span style="color: #000000; font-weight: bold;">new</span> URLRequest<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;
		<span style="color: #b1b100;">return</span> <span style="color: #000000; font-weight: bold;">new</span> URLRequest<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#40;</span>isLocal ? <span style="color: #ff0000;">&quot;&quot;</span> : PROXY_URL<span style="color: #66cc66;">&#41;</span> + <span style="color: #0066CC;">url</span><span style="color: #66cc66;">&#41;</span>;
	<span style="color: #66cc66;">&#125;</span>
&nbsp;
	<span style="color: #0066CC;">public</span> <span style="color: #0066CC;">static</span> <span style="color: #000000; font-weight: bold;">function</span> toProxySource<span style="color: #66cc66;">&#40;</span>source:<span style="color: #0066CC;">String</span><span style="color: #66cc66;">&#41;</span> : <span style="color: #0066CC;">String</span>
	<span style="color: #66cc66;">&#123;</span>			
		<span style="color: #b1b100;">if</span><span style="color: #66cc66;">&#40;</span>source == <span style="color: #000000; font-weight: bold;">null</span><span style="color: #66cc66;">&#41;</span> <span style="color: #b1b100;">return</span> <span style="color: #000000; font-weight: bold;">null</span>;
		<span style="color: #b1b100;">return</span> <span style="color: #66cc66;">&#40;</span>isLocal ? <span style="color: #ff0000;">&quot;&quot;</span> : PROXY_URL<span style="color: #66cc66;">&#41;</span> + source;
	<span style="color: #66cc66;">&#125;</span>
&nbsp;
	<span style="color: #0066CC;">public</span> <span style="color: #0066CC;">static</span> <span style="color: #000000; font-weight: bold;">function</span> <span style="color: #0066CC;">get</span> isLocal<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span> : <span style="color: #0066CC;">Boolean</span>
	<span style="color: #66cc66;">&#123;</span>
		<span style="color: #b1b100;">return</span>	<span style="color: #66cc66;">&#40;</span>	Security.<span style="color: #006600;">sandboxType</span> == Security.<span style="color: #006600;">LOCAL_TRUSTED</span> 
			<span style="color: #66cc66;">||</span>	Security.<span style="color: #006600;">sandboxType</span> == Security.<span style="color: #006600;">LOCAL_WITH_NETWORK</span><span style="color: #66cc66;">&#41;</span>;
	<span style="color: #66cc66;">&#125;</span> 
<span style="color: #66cc66;">&#125;</span>
<span style="color: #66cc66;">&#125;</span></pre></div></div>

]]></content:encoded>
			<wfw:commentRss>http://www.brandondement.com/blog/2009/08/23/using-a-simple-php-proxy-to-load-data-across-domains/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Creating an Image Cache with ActionScript 3</title>
		<link>http://www.brandondement.com/blog/2009/08/18/creating-an-image-cache-with-actionscript-3/</link>
		<comments>http://www.brandondement.com/blog/2009/08/18/creating-an-image-cache-with-actionscript-3/#comments</comments>
		<pubDate>Wed, 19 Aug 2009 03:04:49 +0000</pubDate>
		<dc:creator>Brandon</dc:creator>
				<category><![CDATA[ActionScript]]></category>
		<category><![CDATA[cache]]></category>
		<category><![CDATA[performance]]></category>

		<guid isPermaLink="false">http://www.brandondement.com/blog/?p=3</guid>
		<description><![CDATA[A Flash application that loads images at runtime and uses them over and over won&#8217;t attempt to reuse any previously downloaded assets.  Instead, the Flash Player will download a new image from the server over and over, wasting time and bandwidth.  The additive effect of this can create a real noticeable difference in [...]]]></description>
			<content:encoded><![CDATA[<p>A Flash application that loads images at runtime and uses them over and over won&#8217;t attempt to reuse any previously downloaded assets.  Instead, the Flash Player will download a new image from the server over and over, wasting time and bandwidth.  The additive effect of this can create a real noticeable difference in performance on a large scale.  </p>
<p>For example, we ran into this problem on the leaderboard of the <a href="http://www.pgatour.com/shottracker/">PGA Tour Shot Tracker</a>.  The leaderboard displays the player&#8217;s name and the flag of the country they&#8217;re from.  There can be hundreds of players in the tournament, but they all come from about 2 dozen countries or so.  This setup is a perfect use case for caching images internally.</p>
<p>I started looking around for a solution, and came across <a href="http://stackoverflow.com/questions/303054/how-to-control-flex-3-image-control-caching/1123379">this question on StackOverflow.com</a> as well as an excellent pseudo-code example: <a href="http://userflex.wordpress.com/2008/07/28/image-caching/">this blog post</a>.</p>
<p>With about an hour&#8217;s worth of free time I created a fully functioning ActionScript image cache of my own.  There are only 2 parts:</p>
<ol>
<li><code>CachedImage.as</code> &#8211; A subclass of the Image control. A <code>CachedImage</code> adds itself to the cache when its <code>COMPLETE</code> event is fired.</li>
<li><code>ImageCache.as</code> &#8211; Stores the <code>BitMapData</code> of the <code>CachedImages</code> in a dictionary and provides a small set of static methods for querying, adding, and retrieving from the cache.
</ol>
<p><strong>CachedImage.as</strong></p>

<div class="wp_syntax"><div class="code"><pre class="actionscript" style="font-family:monospace;">package com.<span style="color: #006600;">bdement</span>.<span style="color: #006600;">imagecache</span>
<span style="color: #66cc66;">&#123;</span>
<span style="color: #0066CC;">import</span> flash.<span style="color: #006600;">events</span>.<span style="color: #006600;">Event</span>;
&nbsp;
<span style="color: #0066CC;">import</span> mx.<span style="color: #006600;">controls</span>.<span style="color: #006600;">Image</span>;
&nbsp;
<span style="color: #0066CC;">public</span> <span style="color: #000000; font-weight: bold;">class</span> CachedImage <span style="color: #0066CC;">extends</span> Image
<span style="color: #66cc66;">&#123;</span>
	<span style="color: #0066CC;">private</span> <span style="color: #000000; font-weight: bold;">function</span> onComplete<span style="color: #66cc66;">&#40;</span>event:Event<span style="color: #66cc66;">&#41;</span> : <span style="color: #0066CC;">void</span>
	<span style="color: #66cc66;">&#123;</span>		
		ImageCache.<span style="color: #0066CC;">add</span><span style="color: #66cc66;">&#40;</span><span style="color: #0066CC;">this</span><span style="color: #66cc66;">&#41;</span>;
	<span style="color: #66cc66;">&#125;</span> 
&nbsp;
	<span style="color: #0066CC;">public</span> override <span style="color: #000000; font-weight: bold;">function</span> <span style="color: #0066CC;">set</span> source<span style="color: #66cc66;">&#40;</span>source:<span style="color: #0066CC;">Object</span><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><span style="color: #66cc66;">!</span>ImageCache.<span style="color: #006600;">contains</span><span style="color: #66cc66;">&#40;</span>source<span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#123;</span>
			addEventListener<span style="color: #66cc66;">&#40;</span>Event.<span style="color: #006600;">COMPLETE</span>, onComplete<span style="color: #66cc66;">&#41;</span>; 
		<span style="color: #66cc66;">&#125;</span>			
		<span style="color: #0066CC;">super</span>.<span style="color: #006600;">source</span> = ImageCache.<span style="color: #0066CC;">get</span><span style="color: #66cc66;">&#40;</span>source<span style="color: #66cc66;">&#41;</span>;
	<span style="color: #66cc66;">&#125;</span>		
<span style="color: #66cc66;">&#125;</span>
<span style="color: #66cc66;">&#125;</span></pre></div></div>

<p><strong>ImageCache.as</strong></p>

<div class="wp_syntax"><div class="code"><pre class="actionscript" style="font-family:monospace;">package com.<span style="color: #006600;">bdement</span>.<span style="color: #006600;">imagecache</span>
<span style="color: #66cc66;">&#123;</span>
<span style="color: #0066CC;">import</span> flash.<span style="color: #006600;">display</span>.<span style="color: #006600;">Bitmap</span>;
<span style="color: #0066CC;">import</span> flash.<span style="color: #006600;">display</span>.<span style="color: #006600;">BitmapData</span>;
<span style="color: #0066CC;">import</span> flash.<span style="color: #006600;">utils</span>.<span style="color: #006600;">Dictionary</span>;
&nbsp;
<span style="color: #808080; font-style: italic;">/**
 * 
 * @author bdement
 * 
 * This class reduces the amount of HTTP requests your application has to make
 * by storing the BitMapData of CachedImage objects in memory for reuse
 * by images created after the first one completes.
 */</span>
<span style="color: #0066CC;">public</span> <span style="color: #000000; font-weight: bold;">class</span> ImageCache
<span style="color: #66cc66;">&#123;</span>
	<span style="color: #808080; font-style: italic;">/**
	 * The internal representation of the cache
	 */</span>		
	<span style="color: #0066CC;">private</span> <span style="color: #0066CC;">static</span> <span style="color: #000000; font-weight: bold;">var</span> cache:Dictionary = <span style="color: #000000; font-weight: bold;">new</span> Dictionary<span style="color: #66cc66;">&#40;</span><span style="color: #000000; font-weight: bold;">false</span><span style="color: #66cc66;">&#41;</span>;				
	<span style="color: #808080; font-style: italic;">/**
	 * All the methods of ImageCache are static, so the constructor shouldn't be called.
	 * 
	 */</span>				
	<span style="color: #0066CC;">public</span> <span style="color: #000000; font-weight: bold;">function</span> ImageCache<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>
	<span style="color: #66cc66;">&#123;</span>
		<span style="color: #0066CC;">throw</span> <span style="color: #000000; font-weight: bold;">new</span> <span style="color: #0066CC;">Error</span><span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">&quot;You don't need to instantiate the ImageCache!&quot;</span><span style="color: #66cc66;">&#41;</span>;
	<span style="color: #66cc66;">&#125;</span>	
	<span style="color: #808080; font-style: italic;">/**
	 * 
	 * @param imageSource The source of an image
	 * @return Whether the cache already contains the image indicated by imageSource 
	 * 
	 */</span>				
	<span style="color: #0066CC;">public</span> <span style="color: #0066CC;">static</span> <span style="color: #000000; font-weight: bold;">function</span> contains<span style="color: #66cc66;">&#40;</span>imageSource:<span style="color: #0066CC;">Object</span><span style="color: #66cc66;">&#41;</span> : <span style="color: #0066CC;">Boolean</span>
	<span style="color: #66cc66;">&#123;</span>
		<span style="color: #b1b100;">return</span> cache<span style="color: #66cc66;">&#91;</span>imageSource<span style="color: #66cc66;">&#93;</span> <span style="color: #66cc66;">!</span>= <span style="color: #000000; font-weight: bold;">null</span>;
	<span style="color: #66cc66;">&#125;</span>		
	<span style="color: #808080; font-style: italic;">/**
	 * Retrieves the image 
	 * 
	 * @param imageSource The source of an image
	 * @return Either: The image if it exists in the cache, OR the default
	 * source that was passed in via imageSource.
	 * 
	 */</span>		
	<span style="color: #0066CC;">public</span> <span style="color: #0066CC;">static</span> <span style="color: #000000; font-weight: bold;">function</span> <span style="color: #0066CC;">get</span><span style="color: #66cc66;">&#40;</span>imageSource:<span style="color: #0066CC;">Object</span><span style="color: #66cc66;">&#41;</span> : <span style="color: #0066CC;">Object</span>
	<span style="color: #66cc66;">&#123;</span>
		<span style="color: #b1b100;">if</span><span style="color: #66cc66;">&#40;</span>contains<span style="color: #66cc66;">&#40;</span>imageSource<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;using '&quot;</span> + imageSource + <span style="color: #ff0000;">&quot;' from cache!&quot;</span><span style="color: #66cc66;">&#41;</span>;
			<span style="color: #b1b100;">return</span> <span style="color: #000000; font-weight: bold;">new</span> Bitmap<span style="color: #66cc66;">&#40;</span>cache<span style="color: #66cc66;">&#91;</span>imageSource<span style="color: #66cc66;">&#93;</span> as BitmapData<span style="color: #66cc66;">&#41;</span>;	
		<span style="color: #66cc66;">&#125;</span>
		<span style="color: #b1b100;">return</span> imageSource; <span style="color: #808080; font-style: italic;">// String or Object</span>
	<span style="color: #66cc66;">&#125;</span>
	<span style="color: #808080; font-style: italic;">/**
	 * Adds an image to the cache
	 * @param image The image to be cached 
	 * 
	 */</span>		
	<span style="color: #0066CC;">public</span> <span style="color: #0066CC;">static</span> <span style="color: #000000; font-weight: bold;">function</span> <span style="color: #0066CC;">add</span><span style="color: #66cc66;">&#40;</span>image:CachedImage<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><span style="color: #66cc66;">!</span>contains<span style="color: #66cc66;">&#40;</span>image.<span style="color: #006600;">source</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;adding '&quot;</span> + image.<span style="color: #006600;">source</span> + <span style="color: #ff0000;">&quot;' to cache!&quot;</span><span style="color: #66cc66;">&#41;</span>;
	        <span style="color: #000000; font-weight: bold;">var</span> bitmapData:BitmapData = 
	        	        <span style="color: #000000; font-weight: bold;">new</span> BitmapData<span style="color: #66cc66;">&#40;</span>	image.<span style="color: #006600;">content</span>.<span style="color: #0066CC;">width</span>, 
	        	                                        image.<span style="color: #006600;">content</span>.<span style="color: #0066CC;">height</span>,
                                                                <span style="color: #000000; font-weight: bold;">true</span>,
	        		                                0x00000000<span style="color: #66cc66;">&#41;</span>;
&nbsp;
	        bitmapData.<span style="color: #006600;">draw</span> <span style="color: #66cc66;">&#40;</span>image.<span style="color: #006600;">content</span><span style="color: #66cc66;">&#41;</span>;
&nbsp;
	        cache<span style="color: #66cc66;">&#91;</span>image.<span style="color: #006600;">source</span><span style="color: #66cc66;">&#93;</span> = bitmapData;
	    <span style="color: #66cc66;">&#125;</span>
	<span style="color: #66cc66;">&#125;</span>
&nbsp;
<span style="color: #66cc66;">&#125;</span>
<span style="color: #66cc66;">&#125;</span></pre></div></div>

<p>Finally, you leverage the <code>ImageCache</code> and <code>CachedImage</code> in your application.  You can set the source of your <code>CachedImage</code>s in all the ways you normally would, and the <code>ImageCache</code> will be used automatically.  Note that our <code>ImageCache</code> doesn&#8217;t cache embedded images.  This is because embedded images don&#8217;t fire the  <code>COMPLETE</code> event, which is OK because they&#8217;re already cached in memory and they can be reused without using our <code>ImageCache</code>.  </p>
<p><strong>Application.mxml</strong></p>

<div class="wp_syntax"><div class="code"><pre class="xml" style="font-family:monospace;"><span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;?xml</span> <span style="color: #000066;">version</span>=<span style="color: #ff0000;">&quot;1.0&quot;</span> <span style="color: #000066;">encoding</span>=<span style="color: #ff0000;">&quot;utf-8&quot;</span><span style="color: #000000; font-weight: bold;">?&gt;</span></span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;mx:Application</span> </span>
<span style="color: #009900;">	<span style="color: #000066;">xmlns:mx</span>=<span style="color: #ff0000;">&quot;http://www.adobe.com/2006/mxml&quot;</span> </span>
<span style="color: #009900;">	<span style="color: #000066;">xmlns</span>=<span style="color: #ff0000;">&quot;*&quot;</span></span>
<span style="color: #009900;">	<span style="color: #000066;">width</span>=<span style="color: #ff0000;">&quot;500&quot;</span> <span style="color: #000066;">height</span>=<span style="color: #ff0000;">&quot;200&quot;</span></span>
<span style="color: #009900;">	<span style="color: #000066;">layout</span>=<span style="color: #ff0000;">&quot;horizontal&quot;</span>	</span>
<span style="color: #009900;"> <span style="color: #000000; font-weight: bold;">&gt;</span></span>  
	<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;CachedImage</span> <span style="color: #000066;">id</span>=<span style="color: #ff0000;">&quot;image1&quot;</span> <span style="color: #000066;">source</span>=<span style="color: #ff0000;">&quot;http://www.brandondement.com/blog/wp-content/uploads/2009/08/rooster.gif&quot;</span> <span style="color: #000000; font-weight: bold;">/&gt;</span></span>			
&nbsp;
	<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;mx:VBox<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
		<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;mx:Label</span> <span style="color: #000066;">text</span>=<span style="color: #ff0000;">&quot;Set image2.source to...&quot;</span> <span style="color: #000000; font-weight: bold;">/&gt;</span></span>
		<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;mx:Button</span> <span style="color: #000066;">click</span>=<span style="color: #ff0000;">&quot;{image2.source = image1.source}&quot;</span> <span style="color: #000066;">label</span>=<span style="color: #ff0000;">&quot;image1.source&quot;</span> <span style="color: #000066;">toolTip</span>=<span style="color: #ff0000;">&quot;image1.source&quot;</span> <span style="color: #000000; font-weight: bold;">/&gt;</span></span>
		<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;mx:Button</span> <span style="color: #000066;">click</span>=<span style="color: #ff0000;">&quot;{image2.source = 'http://www.brandondement.com/blog/wp-content/uploads/2009/08/rooster.gif'}&quot;</span>	<span style="color: #000066;">label</span>=<span style="color: #ff0000;">&quot;HTTP URL&quot;</span> <span style="color: #000066;">toolTip</span>=<span style="color: #ff0000;">&quot;http://www.brandondement.com/blog/wp-content/uploads/2009/08/rooster.gif&quot;</span> <span style="color: #000000; font-weight: bold;">/&gt;</span></span>
		<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;mx:Button</span> <span style="color: #000066;">click</span>=<span style="color: #ff0000;">&quot;{image2.source = null}&quot;</span>	<span style="color: #000066;">label</span>=<span style="color: #ff0000;">&quot;null&quot;</span> <span style="color: #000000; font-weight: bold;">/&gt;</span></span>
	<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/mx:VBox<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
&nbsp;
	<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;CachedImage</span> <span style="color: #000066;">id</span>=<span style="color: #ff0000;">&quot;image2&quot;</span> <span style="color: #000000; font-weight: bold;">/&gt;</span></span>
&nbsp;
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/mx:Application<span style="color: #000000; font-weight: bold;">&gt;</span></span></span></pre></div></div>

<p>And finally, here&#8217;s the working example.  To doublecheck that it&#8217;s <strong>actually</strong> using the cache, reload this page with a web debugging proxy on, like <a href="http://www.charlesproxy.com/">Charles</a>.  You&#8217;ll notice a request for &#8220;rooster.gif,&#8221; which is the flash movie downloading the image on the left.  (There will probably be two, since there are two example files)  But notice that when you click the buttons below, <strong>no</strong> more requests are made.  Success!</p>

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

	<!--[if !IE]>-->
	</object>
	<!--<![endif]-->
</object>
<p>And here, just for comparison&#8217;s sake, is the example using normal <code>mx:Image</code>s <strong>without</strong> caching built in.  With <a href="http://www.charlesproxy.com/">Charles</a> on you&#8217;ll notice that <strong>every</strong> time the image source is changed from null, a new request is made!</p>

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

	<!--[if !IE]>-->
	</object>
	<!--<![endif]-->
</object>
]]></content:encoded>
			<wfw:commentRss>http://www.brandondement.com/blog/2009/08/18/creating-an-image-cache-with-actionscript-3/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Creating an Image with Rounded Corners</title>
		<link>http://www.brandondement.com/blog/2009/06/21/creating-an-image-with-rounded-corners/</link>
		<comments>http://www.brandondement.com/blog/2009/06/21/creating-an-image-with-rounded-corners/#comments</comments>
		<pubDate>Sun, 21 Jun 2009 21:27:19 +0000</pubDate>
		<dc:creator>Brandon</dc:creator>
				<category><![CDATA[ActionScript]]></category>

		<guid isPermaLink="false">http://www.brandondement.com/blog/?p=15</guid>
		<description><![CDATA[I recently wanted to round the corners on my images for my website, and the component I found on Flex Examples wasn&#8217;t doing the trick when I used it as an ItemRenderer for a TileList, where I was setting the maxWidth and maxHeight.  After some toiling I tracked down the issue and produced this:

package [...]]]></description>
			<content:encoded><![CDATA[<p>I recently wanted to round the corners on my images for my website, and the component I found on <a href="http://blog.flexexamples.com/2008/09/09/rounding-the-corners-of-an-image-control-in-flex-using-a-mask/">Flex Examples</a> wasn&#8217;t doing the trick when I used it as an <code>ItemRenderer</code> for a <code>TileList</code>, where I was setting the <code>maxWidth</code> and <code>maxHeight</code>.  After some toiling I tracked down the issue and produced this:</p>

<div class="wp_syntax"><div class="code"><pre class="actionscript" style="font-family:monospace;">package com.<span style="color: #006600;">bdement</span>.<span style="color: #006600;">components</span>.<span style="color: #006600;">images</span>
<span style="color: #66cc66;">&#123;</span>
	<span style="color: #0066CC;">import</span> flash.<span style="color: #006600;">display</span>.<span style="color: #006600;">Sprite</span>;
	<span style="color: #0066CC;">import</span> flash.<span style="color: #006600;">events</span>.<span style="color: #006600;">Event</span>;
&nbsp;
	<span style="color: #0066CC;">import</span> mx.<span style="color: #006600;">controls</span>.<span style="color: #006600;">Image</span>;
	<span style="color: #0066CC;">import</span> mx.<span style="color: #006600;">events</span>.<span style="color: #006600;">ResizeEvent</span>;
&nbsp;
	<span style="color: #0066CC;">public</span> <span style="color: #000000; font-weight: bold;">class</span> RoundedCornerImage <span style="color: #0066CC;">extends</span> Image
	<span style="color: #66cc66;">&#123;</span>		
		<span style="color: #66cc66;">&#91;</span>Bindable<span style="color: #66cc66;">&#93;</span> <span style="color: #0066CC;">public</span> <span style="color: #000000; font-weight: bold;">var</span> cornerRadius:uint = <span style="color: #cc66cc;">10</span>;
&nbsp;
		<span style="color: #0066CC;">private</span> <span style="color: #000000; font-weight: bold;">var</span> roundedMask:Sprite;
&nbsp;
		<span style="color: #0066CC;">public</span> <span style="color: #000000; font-weight: bold;">function</span> RoundedCornerImage<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>
		<span style="color: #66cc66;">&#123;</span>
			<span style="color: #0066CC;">super</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;
		<span style="color: #66cc66;">&#125;</span>
&nbsp;
		override protected <span style="color: #000000; font-weight: bold;">function</span> updateDisplayList<span style="color: #66cc66;">&#40;</span>unscaledWidth:<span style="color: #0066CC;">Number</span>, unscaledHeight:<span style="color: #0066CC;">Number</span><span style="color: #66cc66;">&#41;</span> : <span style="color: #0066CC;">void</span>
	    <span style="color: #66cc66;">&#123;</span>   
	    	<span style="color: #0066CC;">super</span>.<span style="color: #006600;">updateDisplayList</span><span style="color: #66cc66;">&#40;</span>unscaledWidth, unscaledHeight<span style="color: #66cc66;">&#41;</span>;
&nbsp;
	    	<span style="color: #b1b100;">if</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">!</span>roundedMask<span style="color: #66cc66;">&#41;</span>
	    	<span style="color: #66cc66;">&#123;</span>
	    		roundedMask = <span style="color: #000000; font-weight: bold;">new</span> Sprite<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;
	    		addChild<span style="color: #66cc66;">&#40;</span>roundedMask<span style="color: #66cc66;">&#41;</span>;    
	    	<span style="color: #66cc66;">&#125;</span>
&nbsp;
	       	roundedMask.<span style="color: #006600;">graphics</span>.<span style="color: #0066CC;">clear</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;
	        roundedMask.<span style="color: #006600;">graphics</span>.<span style="color: #0066CC;">beginFill</span><span style="color: #66cc66;">&#40;</span>0xFF0000<span style="color: #66cc66;">&#41;</span>;
	        roundedMask.<span style="color: #006600;">graphics</span>.<span style="color: #006600;">drawRoundRect</span><span style="color: #66cc66;">&#40;</span><span style="color: #cc66cc;">0</span>, <span style="color: #cc66cc;">0</span>,
	                    contentWidth, contentHeight,
	                    cornerRadius, cornerRadius<span style="color: #66cc66;">&#41;</span>;
	        roundedMask.<span style="color: #006600;">graphics</span>.<span style="color: #0066CC;">endFill</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;
&nbsp;
	        <span style="color: #0066CC;">this</span>.<span style="color: #006600;">mask</span> = roundedMask;
	    <span style="color: #66cc66;">&#125;</span>
	<span style="color: #66cc66;">&#125;</span>    
<span style="color: #66cc66;">&#125;</span></pre></div></div>

<p>Works like a charm!</p>
<p>Side note: Did you know that rounded corners are easier for the eyes to perceive?  <a href="http://www.uiandus.com/2009/07/27/theories/realizations-of-rounded-rectangles/">This interesting article</a> about the history of rounded corners makes mention of it.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.brandondement.com/blog/2009/06/21/creating-an-image-with-rounded-corners/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
	</channel>
</rss>
