<?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>Blogizm &#187; DisplayObject</title>
	<atom:link href="http://blog.aquamedia.com.au/tag/displayobject/feed/" rel="self" type="application/rss+xml" />
	<link>http://blog.aquamedia.com.au</link>
	<description>Thoughts and views expressed online by the staff at Aqua Media</description>
	<lastBuildDate>Tue, 08 Jun 2010 07:03:13 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.9.2</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>Loading external images with ActionScript 3</title>
		<link>http://blog.aquamedia.com.au/2009/08/loading-external-images-with-actionscript-3/</link>
		<comments>http://blog.aquamedia.com.au/2009/08/loading-external-images-with-actionscript-3/#comments</comments>
		<pubDate>Thu, 06 Aug 2009 23:55:43 +0000</pubDate>
		<dc:creator>Flashnutz</dc:creator>
				<category><![CDATA[Flash & ActionScript]]></category>
		<category><![CDATA[DisplayObject]]></category>
		<category><![CDATA[Loader]]></category>
		<category><![CDATA[LoaderInfo]]></category>
		<category><![CDATA[URLLoader]]></category>
		<category><![CDATA[URLRequest]]></category>

		<guid isPermaLink="false">http://blog.aquamedia.com.au/2009/08/loading-external-images-with-actionscript-3/</guid>
		<description><![CDATA[
			
				
			
		
One technique of loading external images is using the Loader class.
It's similar to the URLLoader class but the Loader class loads and displays loaded images and SWF content. The Loader class is a part of the DisplayObject class; it is capable of displaying content as well as loading it.
To load external images using the Loader [...]]]></description>
			<content:encoded><![CDATA[<div class="tweetmeme_button" style="float: right; margin-left: 15px;">
			<a href="http://api.tweetmeme.com/share?url=http%3A%2F%2Fblog.aquamedia.com.au%2F2009%2F08%2Floading-external-images-with-actionscript-3%2F"><br />
				<img src="http://api.tweetmeme.com/imagebutton.gif?url=http%3A%2F%2Fblog.aquamedia.com.au%2F2009%2F08%2Floading-external-images-with-actionscript-3%2F&amp;source=aquamedia&amp;style=normal&amp;service=bit.ly" height="61" width="50" /><br />
			</a>
		</div>
<p>One technique of loading external images is using the <strong>Loader</strong> class.</p>
<p>It's similar to the <strong>URLLoader</strong> class but the Loader class loads and displays loaded images and SWF content. The <strong>Loader</strong> class is a part of the <strong>DisplayObject</strong> class; it is capable of displaying content as well as loading it.</p>
<p>To load external images using the <strong>Loader</strong> class, you need to create an object of the <strong>Loader</strong> class.</p>
<blockquote>
<pre class="actionscript"><span style="color: #000000; font-weight: bold;">var</span> imgLoader:Loader = <span style="color: #000000; font-weight: bold;">new</span> Loader<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;</pre>
</blockquote>
<p>To load an image into the <strong>Loader Object</strong>, the load method of the <strong>Loader</strong> class is used, along with a <strong>URLRequest</strong>.</p>
<blockquote>
<pre class="actionscript"><span style="color: #000000; font-weight: bold;">var</span> imgLoader:Loader = <span style="color: #000000; font-weight: bold;">new</span> Loader<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;
imgLoader.<span style="color: #0066CC;">load</span><span style="color: #66cc66;">&#40;</span><span style="color: #000000; font-weight: bold;">new</span> URLRequest<span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">'image.jpg'</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span>;</pre>
</blockquote>
<p>The <strong>LoaderInfo</strong> class also has events and event types that dispatch information about the progress of the load through the <strong>Loader</strong> class.</p>
<p>The code below traces a loaded message after the loader object has completed loading the image.</p>
<blockquote>
<pre class="actionscript"><span style="color: #000000; font-weight: bold;">var</span> imgLoader:Loader =  <span style="color: #000000; font-weight: bold;">new</span> Loader<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;
imgLoader.<span style="color: #006600;">contentLoaderInfo</span>.<span style="color: #006600;">addEventListner</span><span style="color: #66cc66;">&#40;</span>Event.<span style="color: #006600;">COMPLETE</span>,
loaderCompleteHandler<span style="color: #66cc66;">&#41;</span>;
&nbsp;
<span style="color: #000000; font-weight: bold;">function</span> loaderCompleteHandler<span style="color: #66cc66;">&#40;</span><span style="color: #0066CC;">e</span>:Event<span style="color: #66cc66;">&#41;</span>:<span style="color: #0066CC;">void</span><span style="color: #66cc66;">&#123;</span>
   <span style="color: #0066CC;">trace</span><span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">'Image has loaded.'</span><span style="color: #66cc66;">&#41;</span>;
<span style="color: #66cc66;">&#125;</span>
&nbsp;
imgLoader.<span style="color: #0066CC;">load</span><span style="color: #66cc66;">&#40;</span><span style="color: #000000; font-weight: bold;">new</span> URLRequest<span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">'image.jpg'</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span>;</pre>
</blockquote>
<p>At this point all you have done is loaded in the image to the <strong>Loader</strong> Object. For the loaded image to display you will need to add the <strong>Loader </strong>object to the display list.</p>
<blockquote>
<pre class="actionscript">addChild<span style="color: #66cc66;">&#40;</span>imgLoader<span style="color: #66cc66;">&#41;</span>;</pre>
</blockquote>
<p>The complete source code looks like this.</p>
<blockquote>
<pre class="actionscript"><span style="color: #000000; font-weight: bold;">var</span> imgLoader:Loader =  <span style="color: #000000; font-weight: bold;">new</span> Loader<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;
imgLoader.<span style="color: #006600;">contentLoaderInfo</span>.<span style="color: #006600;">addEventListner</span><span style="color: #66cc66;">&#40;</span>Event.<span style="color: #006600;">COMPLETE</span>,
loaderCompleteHandler<span style="color: #66cc66;">&#41;</span>;
&nbsp;
<span style="color: #000000; font-weight: bold;">function</span> loaderCompleteHandler<span style="color: #66cc66;">&#40;</span><span style="color: #0066CC;">e</span>:Event<span style="color: #66cc66;">&#41;</span>:<span style="color: #0066CC;">void</span><span style="color: #66cc66;">&#123;</span>
   <span style="color: #0066CC;">trace</span><span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">'Image has loaded.'</span><span style="color: #66cc66;">&#41;</span>;
   addChild<span style="color: #66cc66;">&#40;</span>imgLoader<span style="color: #66cc66;">&#41;</span>;
<span style="color: #66cc66;">&#125;</span>
&nbsp;
imgLoader.<span style="color: #0066CC;">load</span><span style="color: #66cc66;">&#40;</span><span style="color: #000000; font-weight: bold;">new</span> URLRequest<span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">'image.jpg'</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span>;</pre>
</blockquote>
<p>Now your ready to build a preloader in ActionScript 3. <a href="http://www.flashnutz.com/2009/03/building-a-preloader-in-actionscript-3/" target="_blank">Let's build it</a>.</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.aquamedia.com.au/2009/08/loading-external-images-with-actionscript-3/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
