<?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; performance</title>
	<atom:link href="http://www.brandondement.com/blog/tag/performance/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.brandondement.com/blog</link>
	<description>Adventures in software development</description>
	<lastBuildDate>Thu, 29 Sep 2011 23:31:38 +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>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_1542270589"
			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_1542270589"
			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_1521720577"
			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_1521720577"
			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>
	</channel>
</rss>

