<?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>Geek.blog &#187; external images</title>
	<atom:link href="http://blog.728media.com/tag/external-images/feed/" rel="self" type="application/rss+xml" />
	<link>http://blog.728media.com</link>
	<description>Advanced Flash and Actionscript 3 by Andrew Christensen</description>
	<lastBuildDate>Fri, 24 Dec 2010 00:14:11 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.2.1</generator>
		<item>
		<title>How to Load External Images in Actionscript 3.0</title>
		<link>http://blog.728media.com/2009/03/11/how-to-load-external-images-in-actionscript-30/</link>
		<comments>http://blog.728media.com/2009/03/11/how-to-load-external-images-in-actionscript-30/#comments</comments>
		<pubDate>Thu, 12 Mar 2009 03:37:12 +0000</pubDate>
		<dc:creator>Andrew Christensen</dc:creator>
				<category><![CDATA[AS3]]></category>
		<category><![CDATA[actionscript]]></category>
		<category><![CDATA[actionscript 3.0]]></category>
		<category><![CDATA[external images]]></category>
		<category><![CDATA[flash]]></category>

		<guid isPermaLink="false">http://blog.728media.com/?p=222</guid>
		<description><![CDATA[Using the flash.display.Loader class in AS3, you can load in external image files to display in flash. The loader class supports loading in JPG, SWF, PNG, or GIF file types. The Loader class sounds more like a loading manager that watches load progress, rather than a display object. Fact is, the Loader is treated as [...]]]></description>
			<content:encoded><![CDATA[<p><img class="alignnone size-full wp-image-225" title="loadingimage" src="http://blog.728media.com/wp-content/uploads/2009/03/loadingimage.jpg" alt="loadingimage" width="650" height="280" /></p>
<p>Using the <a href="http://livedocs.adobe.com/flash/9.0/ActionScriptLangRefV3/flash/display/Loader.html">flash.display.Loader</a> class in AS3, you can load in external image files to display in flash. The loader class supports loading in JPG, SWF, PNG, or GIF file types. The Loader class sounds more like a loading manager that watches load progress, rather than a display object. Fact is, the Loader is treated as a <a href="http://livedocs.adobe.com/flash/9.0/ActionScriptLangRefV3/flash/display/DisplayObject.html">DisplayObject</a>, so when it&#8217;s ready you just add it to the stage. Pretty simple, so let&#8217;s get started!</p>
<p><span id="more-222"></span></p>
<p>First, you will need to create an instance of the loader class and add a couple event listeners to it. One to watch load progress, and one to watch for when the loading is complete.</p>
<div class="codecolorer-container actionscript3 vibrant" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br />2<br />3<br /></div></td><td><div class="actionscript3 codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #6699cc; font-weight: bold;">var</span> myLoader<span style="color: #000066; font-weight: bold;">:</span><a href="http://www.google.com/search?q=loader%20inurl:http://livedocs.adobe.com/flex/201/langref/%20inurl:loader.html"><span style="color: #004993;">Loader</span></a> = <span style="color: #0033ff; font-weight: bold;">new</span> <a href="http://www.google.com/search?q=loader%20inurl:http://livedocs.adobe.com/flex/201/langref/%20inurl:loader.html"><span style="color: #004993;">Loader</span></a><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span><br />
myLoader<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">contentLoaderInfo</span><span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">addEventListener</span><span style="color: #000000;">&#40;</span><a href="http://www.google.com/search?q=progressevent%20inurl:http://livedocs.adobe.com/flex/201/langref/%20inurl:progressevent.html"><span style="color: #004993;">ProgressEvent</span></a><span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">PROGRESS</span><span style="color: #000066; font-weight: bold;">,</span> onLoaderProgress<span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span><br />
myLoader<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">contentLoaderInfo</span><span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">addEventListener</span><span style="color: #000000;">&#40;</span><a href="http://www.google.com/search?q=event%20inurl:http://livedocs.adobe.com/flex/201/langref/%20inurl:event.html"><span style="color: #004993;">Event</span></a><span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">COMPLETE</span><span style="color: #000066; font-weight: bold;">,</span> onLoaderComplete<span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span></div></td></tr></tbody></table></div>
<p>You&#8217;ll notice that I&#8217;m not adding the event listener to the loader instance (myLoader), but instead adding them to a property of myLoader called <strong><a href="http://livedocs.adobe.com/flash/9.0/ActionScriptLangRefV3/flash/display/Loader.html#contentLoaderInfo">contentLoaderInfo</a>. </strong>The Loader class has a special property that controls all the loading events. This property is an instance of the <a href="http://livedocs.adobe.com/flash/9.0/ActionScriptLangRefV3/flash/display/LoaderInfo.html">LoaderInfo</a> class, so we will listen to it for events, rather than our Loader instance.</p>
<p>Next, we will call the <a href="http://livedocs.adobe.com/flash/9.0/ActionScriptLangRefV3/flash/display/Loader.html#load()">Loader.load()</a> method to initiate the loading sequence. You will need to create a new variable that will be an instance of the <a href="http://livedocs.adobe.com/flash/9.0/ActionScriptLangRefV3/flash/net/URLRequest.html">URLRequest</a> class. This new variable will be passed to the load() method.</p>
<div class="codecolorer-container actionscript3 vibrant" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br />2<br />3<br />4<br />5<br />6<br /></div></td><td><div class="actionscript3 codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #6699cc; font-weight: bold;">var</span> myLoader<span style="color: #000066; font-weight: bold;">:</span><a href="http://www.google.com/search?q=loader%20inurl:http://livedocs.adobe.com/flex/201/langref/%20inurl:loader.html"><span style="color: #004993;">Loader</span></a> = <span style="color: #0033ff; font-weight: bold;">new</span> <a href="http://www.google.com/search?q=loader%20inurl:http://livedocs.adobe.com/flex/201/langref/%20inurl:loader.html"><span style="color: #004993;">Loader</span></a><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span><br />
myLoader<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">contentLoaderInfo</span><span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">addEventListener</span><span style="color: #000000;">&#40;</span><a href="http://www.google.com/search?q=progressevent%20inurl:http://livedocs.adobe.com/flex/201/langref/%20inurl:progressevent.html"><span style="color: #004993;">ProgressEvent</span></a><span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">PROGRESS</span><span style="color: #000066; font-weight: bold;">,</span> onProgressStatus<span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span><br />
myLoader<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">contentLoaderInfo</span><span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">addEventListener</span><span style="color: #000000;">&#40;</span><a href="http://www.google.com/search?q=event%20inurl:http://livedocs.adobe.com/flex/201/langref/%20inurl:event.html"><span style="color: #004993;">Event</span></a><span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">COMPLETE</span><span style="color: #000066; font-weight: bold;">,</span> onLoaderReady<span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span><br />
<br />
<span style="color: #6699cc; font-weight: bold;">var</span> fileRequest<span style="color: #000066; font-weight: bold;">:</span><a href="http://www.google.com/search?q=urlrequest%20inurl:http://livedocs.adobe.com/flex/201/langref/%20inurl:urlrequest.html"><span style="color: #004993;">URLRequest</span></a> = <span style="color: #0033ff; font-weight: bold;">new</span> <a href="http://www.google.com/search?q=urlrequest%20inurl:http://livedocs.adobe.com/flex/201/langref/%20inurl:urlrequest.html"><span style="color: #004993;">URLRequest</span></a><span style="color: #000000;">&#40;</span><span style="color: #990000;">&quot;myImage.jpg&quot;</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span><br />
myLoader<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">load</span><span style="color: #000000;">&#40;</span>fileRequest<span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span></div></td></tr></tbody></table></div>
<p>Ok, so that&#8217;s pretty much it. All that is left is to create our callback methods for each of our eventListeners. Our final code should look like this:</p>
<div class="codecolorer-container actionscript3 vibrant" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;height:300px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br />2<br />3<br />4<br />5<br />6<br />7<br />8<br />9<br />10<br />11<br />12<br />13<br />14<br />15<br />16<br /></div></td><td><div class="actionscript3 codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #6699cc; font-weight: bold;">var</span> myLoader<span style="color: #000066; font-weight: bold;">:</span><a href="http://www.google.com/search?q=loader%20inurl:http://livedocs.adobe.com/flex/201/langref/%20inurl:loader.html"><span style="color: #004993;">Loader</span></a> = <span style="color: #0033ff; font-weight: bold;">new</span> <a href="http://www.google.com/search?q=loader%20inurl:http://livedocs.adobe.com/flex/201/langref/%20inurl:loader.html"><span style="color: #004993;">Loader</span></a><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span><br />
myLoader<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">contentLoaderInfo</span><span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">addEventListener</span><span style="color: #000000;">&#40;</span><a href="http://www.google.com/search?q=progressevent%20inurl:http://livedocs.adobe.com/flex/201/langref/%20inurl:progressevent.html"><span style="color: #004993;">ProgressEvent</span></a><span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">PROGRESS</span><span style="color: #000066; font-weight: bold;">,</span> onProgressStatus<span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span><br />
myLoader<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">contentLoaderInfo</span><span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">addEventListener</span><span style="color: #000000;">&#40;</span><a href="http://www.google.com/search?q=event%20inurl:http://livedocs.adobe.com/flex/201/langref/%20inurl:event.html"><span style="color: #004993;">Event</span></a><span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">COMPLETE</span><span style="color: #000066; font-weight: bold;">,</span> onLoaderReady<span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span><br />
<br />
<span style="color: #6699cc; font-weight: bold;">var</span> fileRequest<span style="color: #000066; font-weight: bold;">:</span><a href="http://www.google.com/search?q=urlrequest%20inurl:http://livedocs.adobe.com/flex/201/langref/%20inurl:urlrequest.html"><span style="color: #004993;">URLRequest</span></a> = <span style="color: #0033ff; font-weight: bold;">new</span> <a href="http://www.google.com/search?q=urlrequest%20inurl:http://livedocs.adobe.com/flex/201/langref/%20inurl:urlrequest.html"><span style="color: #004993;">URLRequest</span></a><span style="color: #000000;">&#40;</span><span style="color: #990000;">&quot;myImage.jpg&quot;</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span><br />
myLoader<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">load</span><span style="color: #000000;">&#40;</span>fileRequest<span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span><br />
<br />
<span style="color: #0033ff; font-weight: bold;">public</span> <span style="color: #339966; font-weight: bold;">function</span> onProgressStatus<span style="color: #000000;">&#40;</span>e<span style="color: #000066; font-weight: bold;">:</span><a href="http://www.google.com/search?q=progressevent%20inurl:http://livedocs.adobe.com/flex/201/langref/%20inurl:progressevent.html"><span style="color: #004993;">ProgressEvent</span></a><span style="color: #000000;">&#41;</span> <span style="color: #000000;">&#123;</span>   <br />
  &nbsp; &nbsp; <span style="color: #009900; font-style: italic;">// this is where progress will be monitored     </span><br />
&nbsp; &nbsp; &nbsp; <span style="color: #004993;">trace</span><span style="color: #000000;">&#40;</span>e<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">bytesLoaded</span><span style="color: #000066; font-weight: bold;">,</span> e<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">bytesTotal</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span> <br />
<span style="color: #000000;">&#125;</span><br />
<br />
<span style="color: #0033ff; font-weight: bold;">public</span> <span style="color: #339966; font-weight: bold;">function</span> onLoaderReady<span style="color: #000000;">&#40;</span>e<span style="color: #000066; font-weight: bold;">:</span><a href="http://www.google.com/search?q=event%20inurl:http://livedocs.adobe.com/flex/201/langref/%20inurl:event.html"><span style="color: #004993;">Event</span></a><span style="color: #000000;">&#41;</span> <span style="color: #000000;">&#123;</span>     <br />
&nbsp; &nbsp; &nbsp; <span style="color: #009900; font-style: italic;">// the image is now loaded, so let's add it to the display tree!     </span><br />
&nbsp; &nbsp; &nbsp; <span style="color: #004993;">addChild</span><span style="color: #000000;">&#40;</span>myLoader<span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span><br />
<span style="color: #000000;">&#125;</span></div></td></tr></tbody></table></div>
]]></content:encoded>
			<wfw:commentRss>http://blog.728media.com/2009/03/11/how-to-load-external-images-in-actionscript-30/feed/</wfw:commentRss>
		<slash:comments>42</slash:comments>
		</item>
	</channel>
</rss>

