<?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>CuriousFind</title>
	<atom:link href="http://www.curiousfind.com/blog/feed" rel="self" type="application/rss+xml" />
	<link>http://www.curiousfind.com/blog</link>
	<description>Web development by Jamie McDaniel</description>
	<lastBuildDate>Sun, 14 Feb 2010 05:46:03 +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>This is the Kind of Thing I Would Have Done in Flash</title>
		<link>http://www.curiousfind.com/blog/204</link>
		<comments>http://www.curiousfind.com/blog/204#comments</comments>
		<pubDate>Sun, 14 Feb 2010 05:32:27 +0000</pubDate>
		<dc:creator>Jamie McDaniel</dc:creator>
				<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://www.curiousfind.com/blog/?p=204</guid>
		<description><![CDATA[Flash owns rich internet applications, and the Flex framework is where I spend a lot of my time now.  But I still do projects for clients in Flash like banner ads (using Greensock&#8217;s Tweening Platform), online presentations, and interactive widgets.
Since I am good at Flash, I tend to favor it over JavaScript for cranking [...]]]></description>
			<content:encoded><![CDATA[<p>Flash owns rich internet applications, and the Flex framework is where I spend a lot of my time now.  But I still do projects for clients in Flash like banner ads (using Greensock&#8217;s Tweening Platform), online presentations, and interactive widgets.</p>
<p>Since I am good at Flash, I tend to favor it over JavaScript for cranking out those rotating banners and such.  However, it is neat to see what things are now being done via JavaScript where there used to be a SWF.  And it is good for those skilled with Flash to ask the question of whether a SWF is still the best choice for these things.</p>
<p>Apple&#8217;s <a href="http://www.apple.com/itunes/10-billion-song-countdown/">iTunes countdown</a> is the example that prompted this post.  When I saw it I was curious about how it worked.  Here&#8217;s the <a href="http://images.apple.com/itunes/10-billion-song-countdown/images/counter_filmstrip20100211.png">53&#215;6180 png file</a>.</p>
<p>Sure enough, the banner works on the iPhone.  Although the animation is considerably less smooth on my iPhone 3GS than it is on my 3-year-old MacBook Pro (with a hard reset of the iPhone just to be sure.)</p>
<p>When Flash Player 10.1 is out on other mobile devices it will be interesting to see how it performs with animation like this.</p>
<p><a href="http://www.curiousfind.com/blog/wp-content/uploads/photo.jpg"><img src="http://www.curiousfind.com/blog/wp-content/uploads/photo.jpg" alt="iTunes counter on iPhone" title="photo" width="480" height="320" class="aligncenter size-full wp-image-205" /></a></p>
]]></content:encoded>
			<wfw:commentRss>http://www.curiousfind.com/blog/204/feed</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>AS3 and Big Numbers</title>
		<link>http://www.curiousfind.com/blog/183</link>
		<comments>http://www.curiousfind.com/blog/183#comments</comments>
		<pubDate>Wed, 27 Jan 2010 16:08:53 +0000</pubDate>
		<dc:creator>Jamie McDaniel</dc:creator>
				<category><![CDATA[ActionScript 3]]></category>

		<guid isPermaLink="false">http://www.curiousfind.com/blog/?p=183</guid>
		<description><![CDATA[I ran into a problem when transferring large numbers between the client and server.  They would send me a number and when I sent it back to them it would be different.  Turns out ActionScript 3 has problems with big numbers. Here is a quick example. The expected output would be 129090238754375001.



var string:String [...]]]></description>
			<content:encoded><![CDATA[<p>I ran into a problem when transferring large numbers between the client and server.  They would send me a number and when I sent it back to them it would be different.  Turns out ActionScript 3 has problems with big numbers. Here is a quick example. The expected output would be 129090238754375001.</p>
<div class="actionscript geshi no actionscript" style="font-family:monospace;">
<ol>
<li class="li1">
<div class="de1"><span class="kw2">var</span> <span class="kw3">string</span>:<span class="kw3">String</span> = <span class="st0">&quot;129090238754375000&quot;</span>;</div>
</li>
<li class="li1">
<div class="de1"><span class="kw2">var</span> <span class="kw3">number</span>:<span class="kw3">Number</span> = <span class="kw3">Number</span><span class="br0">&#40;</span><span class="kw3">string</span><span class="br0">&#41;</span>;</div>
</li>
<li class="li1">
<div class="de1"><span class="kw2">var</span> nextNumber = <span class="kw3">number</span> + <span class="nu0">1</span>;</div>
</li>
<li class="li1">
<div class="de1"><span class="kw3">trace</span><span class="br0">&#40;</span>nextNumber<span class="br0">&#41;</span>;</div>
</li>
</ol>
</div>
<p>Here are the variables after execution.  Notice that both number and nextNumber are 129090238754375008.</p>
<p><img src="http://www.curiousfind.com/blog/wp-content/uploads/FlashScreenSnapz002.jpg" alt="Screenshot showing variables at breakpoint" title="FlashScreenSnapz002" width="415" height="456" class="alignnone size-full wp-image-184" /></p>
<p>And the output window:</p>
<p><img src="http://www.curiousfind.com/blog/wp-content/uploads/FlashScreenSnapz003.jpg" alt="Output window showing 129090238754375000" title="FlashScreenSnapz003" width="459" height="82" class="alignnone size-full wp-image-185" /></p>
<p>So <a href="http://help.adobe.com/en_US/FlashPlatform/reference/actionscript/3/int.html">int</a> has a range of -2,147,483,648 to 2,147,483,647 and <a href="http://help.adobe.com/en_US/FlashPlatform/reference/actionscript/3/uint.html">uint</a> has a range of 0 to 4,294,967,295.  While <a href="http://help.adobe.com/en_US/FlashPlatform/reference/actionscript/3/Number.html">Number</a> can represent integers outside the range of int and uint, it has precision limitations.</p>
<p>The solution in our case was that, since we were not doing any math and just using it as an identifier, we changed the server code to use a string instead.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.curiousfind.com/blog/183/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Ultimate Reset of a Loaded AS3 MovieClip</title>
		<link>http://www.curiousfind.com/blog/174</link>
		<comments>http://www.curiousfind.com/blog/174#comments</comments>
		<pubDate>Wed, 27 Jan 2010 05:16:07 +0000</pubDate>
		<dc:creator>Jamie McDaniel</dc:creator>
				<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://www.curiousfind.com/blog/?p=174</guid>
		<description><![CDATA[I had a project that loaded individual SWF files for playing in sequence.  There were the typical play, pause, previous, next buttons.  The SWFs were loaded via Loader. An MP3 file was associated with each SWF.
If the loaded SWF had no nested movieclips, everything went smoothly with movieClip.stop(), movieClip.play(), etc.  However on [...]]]></description>
			<content:encoded><![CDATA[<p>I had a project that loaded individual SWF files for playing in sequence.  There were the typical play, pause, previous, next buttons.  The SWFs were loaded via <a href="http://help.adobe.com/en_US/FlashPlatform/reference/actionscript/3/flash/display/Loader.html">Loader</a>. An MP3 file was associated with each SWF.</p>
<p>If the loaded SWF had no nested movieclips, everything went smoothly with movieClip.stop(), movieClip.play(), etc.  However on this project, there were nested movieClips in the SWF, so these all needed to be stopped when the user pressed pause, and restarted when the user pressed play.</p>
<div class="actionscript geshi no actionscript" style="font-family:monospace;">
<ol>
<li class="li1">
<div class="de1"><span class="kw3">private</span> <span class="kw2">function</span> stopMovieClipAndChildren<span class="br0">&#40;</span>content:DisplayObjectContainer<span class="br0">&#41;</span>:<span class="kw3">void</span></div>
</li>
<li class="li1">
<div class="de1"><span class="br0">&#123;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; <span class="kw1">if</span> <span class="br0">&#40;</span>content is <span class="kw3">MovieClip</span><span class="br0">&#41;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; <span class="br0">&#40;</span>content as <span class="kw3">MovieClip</span><span class="br0">&#41;</span>.<span class="kw3">stop</span><span class="br0">&#40;</span><span class="br0">&#41;</span>;</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; <span class="kw1">if</span> <span class="br0">&#40;</span>content.<span class="me1">numChildren</span><span class="br0">&#41;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; <span class="br0">&#123;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; <span class="kw2">var</span> child:DisplayObjectContainer;</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; <span class="kw2">var</span> n:<span class="kw3">int</span> = content.<span class="me1">numChildren</span>;</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; <span class="kw1">for</span> <span class="br0">&#40;</span><span class="kw2">var</span> i:<span class="kw3">int</span> = <span class="nu0">0</span>; i <span class="sy0">&lt;</span> n; i++<span class="br0">&#41;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; <span class="br0">&#123;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="kw1">if</span> <span class="br0">&#40;</span>content.<span class="me1">getChildAt</span><span class="br0">&#40;</span>i<span class="br0">&#41;</span> is DisplayObjectContainer<span class="br0">&#41;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="br0">&#123;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; child = content.<span class="me1">getChildAt</span><span class="br0">&#40;</span>i<span class="br0">&#41;</span> as DisplayObjectContainer;</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="kw1">if</span> <span class="br0">&#40;</span>child.<span class="me1">numChildren</span><span class="br0">&#41;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; stopMovieClipAndChildren<span class="br0">&#40;</span>child<span class="br0">&#41;</span>;</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="kw1">else</span> <span class="kw1">if</span> <span class="br0">&#40;</span>child is <span class="kw3">MovieClip</span><span class="br0">&#41;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="br0">&#40;</span>child as <span class="kw3">MovieClip</span><span class="br0">&#41;</span>.<span class="kw3">stop</span><span class="br0">&#40;</span><span class="br0">&#41;</span>;</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="br0">&#125;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; <span class="br0">&#125;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; <span class="br0">&#125;</span></div>
</li>
<li class="li1">
<div class="de1"><span class="br0">&#125;</span></div>
</li>
</ol>
</div>
<div class="actionscript geshi no actionscript" style="font-family:monospace;">
<ol>
<li class="li1">
<div class="de1"><span class="kw3">private</span> <span class="kw2">function</span> playMovieClipAndChildren<span class="br0">&#40;</span>content:DisplayObjectContainer<span class="br0">&#41;</span>:<span class="kw3">void</span></div>
</li>
<li class="li1">
<div class="de1"><span class="br0">&#123;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; <span class="kw1">if</span> <span class="br0">&#40;</span>content is <span class="kw3">MovieClip</span><span class="br0">&#41;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; <span class="br0">&#123;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; <span class="kw2">var</span> <span class="kw3">movieClip</span>:<span class="kw3">MovieClip</span> = content as <span class="kw3">MovieClip</span>;</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; <span class="kw1">if</span> <span class="br0">&#40;</span><span class="kw3">movieClip</span>.<span class="me1">currentFrame</span> <span class="sy0">&lt;</span> <span class="kw3">movieClip</span>.<span class="me1">totalFrames</span><span class="br0">&#41;</span> <span class="co1">// if the main timeline has reached the end, don&#39;t play it</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="kw3">movieClip</span>.<span class="kw3">play</span><span class="br0">&#40;</span><span class="br0">&#41;</span>;</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; <span class="br0">&#125;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; <span class="kw1">if</span> <span class="br0">&#40;</span>content.<span class="me1">numChildren</span><span class="br0">&#41;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; <span class="br0">&#123;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; <span class="kw2">var</span> child:DisplayObjectContainer;</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; <span class="kw2">var</span> n:<span class="kw3">int</span> = content.<span class="me1">numChildren</span>;</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; <span class="kw1">for</span> <span class="br0">&#40;</span><span class="kw2">var</span> i:<span class="kw3">int</span> = <span class="nu0">0</span>; i <span class="sy0">&lt;</span> n; i++<span class="br0">&#41;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; <span class="br0">&#123;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="kw1">if</span> <span class="br0">&#40;</span>content.<span class="me1">getChildAt</span><span class="br0">&#40;</span>i<span class="br0">&#41;</span> is DisplayObjectContainer<span class="br0">&#41;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="br0">&#123;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; child = content.<span class="me1">getChildAt</span><span class="br0">&#40;</span>i<span class="br0">&#41;</span> as DisplayObjectContainer;</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="kw1">if</span> <span class="br0">&#40;</span>child.<span class="me1">numChildren</span><span class="br0">&#41;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; playMovieClipAndChildren<span class="br0">&#40;</span>child<span class="br0">&#41;</span>;</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="kw1">else</span> <span class="kw1">if</span> <span class="br0">&#40;</span>child is <span class="kw3">MovieClip</span><span class="br0">&#41;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="br0">&#123;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="kw2">var</span> childMovieClip:<span class="kw3">MovieClip</span> = child as <span class="kw3">MovieClip</span>;</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="kw1">if</span> <span class="br0">&#40;</span>childMovieClip.<span class="me1">currentFrame</span> <span class="sy0">&lt;</span> childMovieClip.<span class="me1">totalFrames</span><span class="br0">&#41;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; childMovieClip.<span class="kw3">play</span><span class="br0">&#40;</span><span class="br0">&#41;</span>;</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="br0">&#125;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="br0">&#125;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; <span class="br0">&#125;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; <span class="br0">&#125;</span></div>
</li>
<li class="li1">
<div class="de1"><span class="br0">&#125;</span></div>
</li>
</ol>
</div>
<p>(my google search landed me <a href="http://www.unfocus.com/2009/12/07/stop-all-child-movieclips-in-flash-with-actionscript-3-0/">here</a> before writing my own)</p>
<p>Clicking the previous button presented a problem however.  Calling movieClip.gotoAndStop(1) on the movieClip (and even all its children) was not putting it back to its &#8220;new out of the box&#8221; state.  I needed a way to do an ultimate reset of the movieClip but since it was a loaded SWF, I didn&#8217;t have the class to do:</p>
<div class="actionscript geshi no actionscript" style="font-family:monospace;">
<ol>
<li class="li1">
<div class="de1">&nbsp;<span class="kw3">movieClip</span>:<span class="kw3">MovieClip</span> = <span class="kw2">new</span> SomeLoadedMovieClip<span class="br0">&#40;</span><span class="br0">&#41;</span>;</div>
</li>
</ol>
</div>
<p>However, after reading <a href="http://www.dannyburbol.com/2009/01/movieclip-clone-flash-as3/">this blog</a> I found out how.</p>
<div class="actionscript geshi no actionscript" style="font-family:monospace;">
<ol>
<li class="li1">
<div class="de1"><span class="kw3">private</span> <span class="kw2">function</span> resetMovieClip<span class="br0">&#40;</span><span class="kw3">movieClip</span>:<span class="kw3">MovieClip</span><span class="br0">&#41;</span>:<span class="kw3">MovieClip</span></div>
</li>
<li class="li1">
<div class="de1"><span class="br0">&#123;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; <span class="kw2">var</span> sourceClass:<span class="kw2">Class</span> = <span class="kw3">movieClip</span>.<span class="kw3">constructor</span>;</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; <span class="kw2">var</span> resetMovieClip:<span class="kw3">MovieClip</span> = <span class="kw2">new</span> sourceClass<span class="br0">&#40;</span><span class="br0">&#41;</span>;</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; <span class="kw1">return</span> resetMovieClip;</div>
</li>
<li class="li1">
<div class="de1"><span class="br0">&#125;</span></div>
</li>
</ol>
</div>
<p>Use it like this:</p>
<div class="actionscript geshi no actionscript" style="font-family:monospace;">
<ol>
<li class="li1">
<div class="de1">stopMovieClipAndChildren<span class="br0">&#40;</span><span class="kw3">movieClip</span><span class="br0">&#41;</span>;</div>
</li>
<li class="li1">
<div class="de1"><span class="co1">// remember to remove all event listeners from movieClip and anything that references it</span></div>
</li>
<li class="li1">
<div class="de1"><span class="co1">// remove movieClip from the display list</span></div>
</li>
<li class="li1">
<div class="de1">removeChild<span class="br0">&#40;</span><span class="kw3">movieClip</span><span class="br0">&#41;</span>;</div>
</li>
<li class="li1">
<div class="de1"><span class="co1">// reset the loaded movieClip by creating a new instance of it</span></div>
</li>
<li class="li1">
<div class="de1"><span class="kw3">movieClip</span> = resetMovieClip<span class="br0">&#40;</span><span class="kw3">movieClip</span><span class="br0">&#41;</span>;</div>
</li>
<li class="li1">
<div class="de1">addChild<span class="br0">&#40;</span><span class="kw3">movieClip</span><span class="br0">&#41;</span>;</div>
</li>
</ol>
</div>
]]></content:encoded>
			<wfw:commentRss>http://www.curiousfind.com/blog/174/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Learned Something About Events in ActionScript 3</title>
		<link>http://www.curiousfind.com/blog/164</link>
		<comments>http://www.curiousfind.com/blog/164#comments</comments>
		<pubDate>Sun, 12 Jul 2009 01:27:39 +0000</pubDate>
		<dc:creator>Jamie McDaniel</dc:creator>
				<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://www.curiousfind.com/blog/?p=164</guid>
		<description><![CDATA[I was recently presented with a multiple choice question that went something like this:
Events in ActionScript 3 represent what type of code?

Synchronous Execution
Asynchronous Execution
Object Oriented Programming
Procedural Programming


Thinking how events allow for loosely-coupled components, I clicked answer #3 and moved on.  Like every Flex developer, I use custom events that extend the Event class and [...]]]></description>
			<content:encoded><![CDATA[<p>I was recently presented with a multiple choice question that went something like this:</p>
<blockquote><p>Events in ActionScript 3 represent what type of code?</p>
<ol>
<li>Synchronous Execution</li>
<li>Asynchronous Execution</li>
<li>Object Oriented Programming</li>
<li>Procedural Programming</li>
</ol>
</blockquote>
<p>Thinking how events allow for loosely-coupled components, I clicked answer #3 and moved on.  Like every Flex developer, I use custom events that extend the Event class and deliver a payload to the event handler function.  However, here recently, I&#8217;ve been working on a project for a client where they used no custom events whatsoever.  It is a large project and, architecturally-wise, it is really a mess.  Every object has a reference to every other object and they all call methods on each other, or worse, on each other&#8217;s children.</p>
<p>Anyway, as I thought back to the question it got me wondering if, despite my constant use of events, I had a good understanding of how Flash&#8217;s eventDispatcher class (whose code, unlike the open-source Flex framework, is part of playerglobal.swc and cannot be viewed) works.</p>
<p>I did a quick test in the Flash IDE</p>
<div class="actionscript geshi no actionscript" style="font-family:monospace;">
<ol>
<li class="li1">
<div class="de1">addEventListener<span class="br0">&#40;</span><span class="st0">&quot;myEvent&quot;</span>, myEventHandler<span class="br0">&#41;</span>;</div>
</li>
<li class="li1">
<div class="de1">dispatchEvent<span class="br0">&#40;</span><span class="kw2">new</span> Event<span class="br0">&#40;</span><span class="st0">&quot;myEvent&quot;</span><span class="br0">&#41;</span><span class="br0">&#41;</span>;</div>
</li>
<li class="li1">
<div class="de1"><span class="kw3">trace</span><span class="br0">&#40;</span><span class="st0">&quot;hello&quot;</span><span class="br0">&#41;</span>;</div>
</li>
<li class="li1">
<div class="de1">&nbsp;</div>
</li>
<li class="li1">
<div class="de1"><span class="kw2">function</span> myEventHandler<span class="br0">&#40;</span>event:Event<span class="br0">&#41;</span>:<span class="kw3">void</span></div>
</li>
<li class="li1">
<div class="de1"><span class="br0">&#123;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; <span class="kw3">trace</span><span class="br0">&#40;</span><span class="st0">&quot;hello from myEventHandler&quot;</span><span class="br0">&#41;</span>;</div>
</li>
<li class="li1">
<div class="de1"><span class="br0">&#125;</span></div>
</li>
</ol>
</div>
<p>Which produced the result:</p>
<blockquote><p>hello from myEventHandler<br />
hello
</p></blockquote>
<p>So the correct answer to the question above is 1. Synchronous Execution. <span style="color:#FF0000">(Added: or not&#8230; see discussion in the comments)</span>.</p>
<p>Calling the dispatchEvent method on EventDispatcher (or any class that extends it) causes EventDispatcher to immediately look up the functions that were registered as event handlers and call them in the order they were registered (or in the order of the priority argument passed in when registering the handler via addEventListener).</p>
<p>I don&#8217;t know why I didn&#8217;t realize this before.  I guess I just hadn&#8217;t walked it through in my mind or thought events got queued up or something with handlers called when that queue was processed, perhaps on the next frame.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.curiousfind.com/blog/164/feed</wfw:commentRss>
		<slash:comments>7</slash:comments>
		</item>
		<item>
		<title>Adventures in Freelancing: Death of the MacBook Pro</title>
		<link>http://www.curiousfind.com/blog/151</link>
		<comments>http://www.curiousfind.com/blog/151#comments</comments>
		<pubDate>Fri, 20 Mar 2009 23:41:30 +0000</pubDate>
		<dc:creator>Jamie McDaniel</dc:creator>
				<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://www.curiousfind.com/blog/?p=151</guid>
		<description><![CDATA[On Sunday, I went into the home office to work on my third gig since moving to full-time freelancing.  My out-of-warranty-but-still-very-new-to-me MacBook Pro with its 4GB of memory, 1920 x 1200 screen, and nearly $3,000 price tag in 2007 was dead &#8212; a victim of the infamous NVidia 8600 failure. I remember when such hardware [...]]]></description>
			<content:encoded><![CDATA[<p>On Sunday, I went into the home office to work on my third gig since moving to full-time freelancing.  My out-of-warranty-but-still-very-new-to-me MacBook Pro with its 4GB of memory, 1920 x 1200 screen, and nearly $3,000 price tag in 2007 was dead &#8212; a victim of the <a href="http://support.apple.com/kb/TS2377">infamous NVidia 8600 failure</a>. I remember when such hardware failures meant going into my personal inventory of spare parts such as <a href="http://en.wikipedia.org/wiki/3dfx_Interactive">3dfx Voodoo cards</a>, ATX 350W power supplies, network cards, overclocked <a href="http://en.wikipedia.org/wiki/Duron">AMD Duron</a> chips, and the like.  A desktop computer could be back up in no time.</p>
<p>Apple had the repair box to me on Tuesday and the computer arrived at their repair center on Wednesday.  It was back on my desk on Friday, all fixed.  Apple mistakenly charged me for the repair, but after a thirty minute call they credited me back the amount.</p>
<p>I like my MacBook Pro very much &#8212; better than any computer I&#8217;ve owned (all previous Windows machines).  It is not without its quirks, however. And now hardware failures.  Those entertaining &#8220;I&#8217;m a problem-prone PC, I&#8217;m an eager and trouble-free Mac&#8221; advertisements are products of Apple&#8217;s marketing department, not user surveys, and must be viewed with the proper dose of <a href="http://www.youtube.com/watch?v=bm7JH1FT_yM">skepticism</a>.</p>
<p>I am a little concerned that the replacement board with the same NVidia chip will just fail again after a certain number of heating/cooling cycles and that this MacBook Pro&#8217;s dependability, and indeed life expectancy, is in question.  I did have a week of downtime due to not having a backup computer.  That&#8217;s a reason not to sell your old laptop for $400 on eBay when upgrading!  That said, if I were suddenly back on my Dell Inspiron running CS2 on Windows, I might remember why I switched to Apple and OS X.</p>
<p>One thing I did learn about through this experience is Apple&#8217;s Target Disk mode.  If you hold down the T key while booting your Mac, it will function as an external firewire drive.  With both the monitor and external display not working due to the graphics card failure, I was still able to access the drive and pull my files off using Chris&#8217; Windows PC and a program called <a href="http://www.mediafour.com/products/macdrive/">MacDrive</a>.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.curiousfind.com/blog/151/feed</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Friends Competing in The Amazing Race</title>
		<link>http://www.curiousfind.com/blog/141</link>
		<comments>http://www.curiousfind.com/blog/141#comments</comments>
		<pubDate>Sun, 15 Feb 2009 19:47:28 +0000</pubDate>
		<dc:creator>Jamie McDaniel</dc:creator>
				<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://www.curiousfind.com/blog/?p=141</guid>
		<description><![CDATA[Tonight, my friend Mel White and his son will compete in the 14th season of CBS&#8217;s reality show, The Amazing Race.  I&#8217;ve known Mel for eight years.  He is an author and gay rights activist.  His son is a movie writer whose credits include School of Rock and Nacho Libre.
From the teaser videos that CBS [...]]]></description>
			<content:encoded><![CDATA[<p><img class="alignright size-full wp-image-142" title="amazing_race_small" src="http://www.curiousfind.com/blog/wp-content/uploads/amazing_race_small.jpg" alt="amazing_race_small" width="191" height="228" />Tonight, my friend Mel White and his son will compete in the 14th season of CBS&#8217;s reality show, <em>The Amazing Race</em>.  I&#8217;ve known Mel for eight years.  He is an author and gay rights activist.  His son is a movie writer whose credits include <em>School of Rock</em> and <em>Nacho Libre</em>.</p>
<p>From the teaser videos that CBS has released, there is a challenge where teams jump from the second highest bungee jump in the world. I thought it was Hoover Dam on first look.  I&#8217;m thinking I would not have done that even if they had guaranteed me the million dollars.  Life is too fragile and my spidey sense of danger is all-the-time tingling. And if they somehow convinced me to (only for a guaranteed million mind you), I&#8217;m confident the first officer in my brain would shout to my legs, &#8220;Ensign, belay that order!&#8221; all Star Trek style.</p>
<p>Anyways, Mel contracted me to overhaul his <a href="http://www.melwhite.org">personal website</a>. I designed the new layout, switched his website to my <a href="http://www.curiousfind.com/hosting">Backlit Content Management System</a>, and integrated a Wordpress blog.  Backlit makes it easy for clients to edit webpages and upload photos.  I then recommend <a href="http://illuminex.com/ecto/">Ecto</a> (or <a href="http://download.live.com/writer">Live Writer</a> if they&#8217;re on Windows) to manage their blog entries.  (However, in Mel and Mike&#8217;s case, teams cannot blog about anything related to the race while the show is ongoing due to their contract with CBS.)</p>
<p>Go team Mel &amp; Mike!</p>
]]></content:encoded>
			<wfw:commentRss>http://www.curiousfind.com/blog/141/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Introducing Backlit &#8212; a Flex CMS using XStandard</title>
		<link>http://www.curiousfind.com/blog/131</link>
		<comments>http://www.curiousfind.com/blog/131#comments</comments>
		<pubDate>Tue, 03 Feb 2009 00:45:27 +0000</pubDate>
		<dc:creator>Jamie McDaniel</dc:creator>
				<category><![CDATA[Flex]]></category>

		<guid isPermaLink="false">http://www.curiousfind.com/blog/?p=131</guid>
		<description><![CDATA[
Backlit is the Flex project I have been working on for several months.  It is the content management system that I am offering to distinguish my website hosting business from the typical shared hosting provider.   Backlit makes it easy to manage articles and photos.  It utilizes the XStandard plugin which generates clean XHTML strict code.  [...]]]></description>
			<content:encoded><![CDATA[<p><img class="aligncenter size-full wp-image-133" title="backlit2" src="http://www.curiousfind.com/blog/wp-content/uploads/backlit2.jpg" alt="backlit2" width="540" height="290" /></p>
<p><em>Backlit</em> is the Flex project I have been working on for several months.  It is the content management system that I am offering to distinguish my website hosting business from the typical shared hosting provider.   <em>Backlit</em> makes it easy to manage articles and photos.  It utilizes the XStandard plugin which generates clean XHTML strict code.  Photos can be uploaded, moved between albums, and deleted.</p>
<p>Here are some links that provide a lot more information:</p>
<p>1. <a href="http://www.backlitsite.com/backlit" target="_blank">Demo Site Backend</a> (username: <strong>guest</strong> password: <strong>password</strong>)</p>
<p>2. <a href="http://www.curiousfind.com/article/7">Tutorials</a></p>
<p>3. <a href="http://www.curiousfind.com/article/10">Super Easy to Create a Frontend</a></p>
<p>4. <a href="http://www.curiousfind.com/hosting">More Information</a></p>
<p>The demo site completely resets itself every few hours, so feel free to give it a good test drive.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.curiousfind.com/blog/131/feed</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Passed the Flex 3 with AIR Certification Exam</title>
		<link>http://www.curiousfind.com/blog/113</link>
		<comments>http://www.curiousfind.com/blog/113#comments</comments>
		<pubDate>Fri, 09 Jan 2009 20:16:14 +0000</pubDate>
		<dc:creator>Jamie McDaniel</dc:creator>
				<category><![CDATA[Flex]]></category>

		<guid isPermaLink="false">http://www.curiousfind.com/blog/?p=113</guid>
		<description><![CDATA[I end full time work with my current employer on January 31, so I wanted to get the Flex 3 with AIR certification on my resume.  I passed, but it is obvious which section nearly torpedoed me! I was confident I had only missed seven&#8230; maybe eight of the fifty questions.  I&#8217;d love [...]]]></description>
			<content:encoded><![CDATA[<p>I end full time work with my current employer on January 31, so I wanted to get the Flex 3 with AIR certification on <a href="http://www.curiousfind.com/article/4">my resume</a>.  I passed, but it is obvious which section nearly torpedoed me! I was confident I had only missed seven&#8230; maybe eight of the fifty questions.  I&#8217;d love to have been able to review which ones I missed, but since that isn&#8217;t an option, I&#8217;ll revisit the reference books while it is still fresh.</p>
<p><img src="http://www.curiousfind.com/images/ace_flex_air.jpg" alt="Adobe Certified Expert - Flex 3 with AIR" /></p>
]]></content:encoded>
			<wfw:commentRss>http://www.curiousfind.com/blog/113/feed</wfw:commentRss>
		<slash:comments>5</slash:comments>
		</item>
		<item>
		<title>Sorting a Tree in Flex and Maintaining Open State on Refresh</title>
		<link>http://www.curiousfind.com/blog/78</link>
		<comments>http://www.curiousfind.com/blog/78#comments</comments>
		<pubDate>Mon, 08 Dec 2008 20:31:13 +0000</pubDate>
		<dc:creator>Jamie McDaniel</dc:creator>
				<category><![CDATA[Flex]]></category>

		<guid isPermaLink="false">http://www.curiousfind.com/blog/?p=78</guid>
		<description><![CDATA[I used Flex&#8217;s tree component in a content management system.  The tree&#8217;s data provider was an ArrayCollection that received its data from a server call. The application would get the site map from the server whenever:

a new article was saved
an existing article was saved with a new parentID
the user clicked the Refresh Site Map [...]]]></description>
			<content:encoded><![CDATA[<p>I used Flex&#8217;s tree component in a content management system.  The tree&#8217;s data provider was an ArrayCollection that received its data from a server call. The application would get the site map from the server whenever:</p>
<ul>
<li>a new article was saved</li>
<li>an existing article was saved with a new parentID</li>
<li>the user clicked the Refresh Site Map button</li>
</ul>
<p>The site map had two issues: the articles were not sorted alphabetically, and the site map would lose its open state upon refresh.</p>
<p>I was able to solve both issues.  Here is an example.  You can <a href="http://www.curiousfind.com/tutorials/sitemaptutorial/srcview/index.html">view the full code</a>.</p>
<p>You will first notice that the articles in the tree are not sorted alphabetically.  If you check the Sort checkbox and click Refresh, it will simulate a call to the server where the data provider is replaced.  The sort is performed in the setter for the data provider.</p>
<p>Also notice that the tree does not maintain its open state when its data provider is changed.  Now check the Remember Open State checkbox and click Refresh.  The tree maintains its open state.</p>
<p>The article objects in the tree have two properties: articleID and title.  The articleID needs to be unique in order for the Remember Open State to work.  It remembers its state by using recursion to cycle through all the tree items and saving an array of articleIDs that are open.  When the new data provider is set, the nodes with articleIDs saved in the _openItems array are opened with the tree&#8217;s <code>expandItem</code> method.</p>

    <object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" id="swfobj_0" width="500" height="450">
      <param name="movie" value="/tutorials/sitemaptutorial/Main.swf" />
      <param name="base" value="." />
      <!--[if !IE]>-->
      <object type="application/x-shockwave-flash" data="/tutorials/sitemaptutorial/Main.swf" width="500" height="450" base=".">
      <!--<![endif]-->
        <p>The Flash plugin is required to view this object.</p>
      <!--[if !IE]>-->
      </object>
      <!--<![endif]-->
    </object>

]]></content:encoded>
			<wfw:commentRss>http://www.curiousfind.com/blog/78/feed</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
		<item>
		<title>Creating a Loosely-Coupled Custom Component in Flex</title>
		<link>http://www.curiousfind.com/blog/51</link>
		<comments>http://www.curiousfind.com/blog/51#comments</comments>
		<pubDate>Thu, 20 Nov 2008 19:49:50 +0000</pubDate>
		<dc:creator>Jamie McDaniel</dc:creator>
				<category><![CDATA[Flex]]></category>

		<guid isPermaLink="false">http://www.curiousfind.com/blog/?p=51</guid>
		<description><![CDATA[Note: This is a tutorial that I wrote for a contest at SitePoint earlier this year.  I had titled it Creating a Reusable Custom Component in Flex. After watching this session from 360Flex, I now know about there being two “levels” of reusability: loosely-coupled components and polished, fit for cataloging/distribution components. This tutorial is for the [...]]]></description>
			<content:encoded><![CDATA[<p><strong>Note:</strong> This is a tutorial that I wrote for a <a href="http://www.sitepoint.com/blogs/2008/05/26/adobe-flexair-article-competition-and-the-winners-are/">contest at SitePoint</a> earlier this year.  I had titled it <em>Creating a Reusable Custom Component in Flex</em>. After watching this <a href="http://www.onflex.org/ted/2008/08/creating-reusable-components-by-ben.php">session from 360Flex</a>, I now know about there being two “levels” of reusability: loosely-coupled components and polished, fit for cataloging/distribution components. This tutorial is for the former.</p>
<hr />
<h3 style="margin-bottom:0;">Creating a Reusable Custom Component in Flex</h3>
<p style="margin-top:0;"><em>by Jamie McDaniel</em></p>
<p>In this tutorial, I will guide you through the process of creating a custom Flex component. You will also learn how to pass data between the main Flex application and the custom component using best practices.</p>
<p>If you do not have Flex Builder, you can download a <a href="http://www.adobe.com/go/flex_trial">60-day trial</a>.  If you are a student, faculty, or staff of an eligible education institution, you can get the education version of Flex Builder 3 free by going to <a href="http://flexregistration.com">http://flexregistration.com</a>.</p>
<p>The component we will be creating is a slideshow navigation bar.  The navigation bar will include buttons for previous, next, play/pause, full screen on/off, and sound on/off.  We will start by using the default buttons in Flex, and then proceed to style them using more recognizable graphics.</p>
<p>Open Flex Builder and click File -&gt; New -&gt; Flex Project. I am giving this project the name of SitePointTutorial.</p>
<p><a href="http://www.curiousfind.com/blog/wp-content/uploads/flex_article_1.png"><img class="alignnone size-full wp-image-52" title="flex_article_1" src="http://www.curiousfind.com/blog/wp-content/uploads/flex_article_1.png" alt="" width="444" height="544" /></a></p>
<p>When you click Finish, Flex Builder will create folders for your project. In the src folder you will find the main application file called SitePointTutorial.mxml. Go ahead and create three additional folders inside the src folder and name them assets, components, and events.</p>
<p>Click File -&gt; New -&gt; MXML Component. Select the components folder as the parent folder and give this component a filename of SlideshowNavigationBar.  Base it on HBox and set the width to 400 and the height to 60.</p>
<p><a href="http://www.curiousfind.com/blog/wp-content/uploads/flex_article_2.png"><img class="alignnone size-full wp-image-53" title="flex_article_2" src="http://www.curiousfind.com/blog/wp-content/uploads/flex_article_2.png" alt="" width="324" height="481" /></a></p>
<p>In the SlideShowNavigationBar.mxml file, enter the following code:</p>
<div class="actionscript geshi no actionscript" style="font-family:monospace;">
<ol>
<li class="li1">
<div class="de1"><span class="sy0">&lt;</span>?<span class="kw3">xml</span> <span class="kw3">version</span>=<span class="st0">&quot;1.0&quot;</span> encoding=<span class="st0">&quot;utf-8&quot;</span>?<span class="sy0">&gt;</span></div>
</li>
<li class="li1">
<div class="de1"><span class="sy0">&lt;</span>mx:HBox xmlns:mx=<span class="st0">&quot;http://www.adobe.com/2006/mxml&quot;</span> <span class="kw3">width</span>=<span class="st0">&quot;400&quot;</span> <span class="kw3">height</span>=<span class="st0">&quot;60&quot;</span> initialize=<span class="st0">&quot;onInitialize()&quot;</span> horizontalAlign=<span class="st0">&quot;center&quot;</span> verticalAlign=<span class="st0">&quot;middle&quot;</span><span class="sy0">&gt;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; <span class="sy0">&lt;</span>mx:Script<span class="sy0">&gt;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; <span class="sy0">&lt;!</span><span class="br0">&#91;</span>CDATA<span class="br0">&#91;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="kw3">private</span> <span class="kw2">function</span> onInitialize<span class="br0">&#40;</span><span class="br0">&#41;</span>:<span class="kw3">void</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="br0">&#123;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="kw3">this</span>.<span class="me1">drawRoundRect</span><span class="br0">&#40;</span><span class="nu0">0</span>, <span class="nu0">0</span>, <span class="nu0">400</span>, <span class="nu0">60</span>,</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="br0">&#123;</span>tl: <span class="nu0">7</span>, tr:<span class="nu0">7</span>, bl:<span class="nu0">7</span>, br: <span class="nu0">7</span><span class="br0">&#125;</span>,</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; 0&#215;3A3A3A, <span class="nu0">0.75</span><span class="br0">&#41;</span>;</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="br0">&#125;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; <span class="br0">&#93;</span><span class="br0">&#93;</span><span class="sy0">&gt;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; <span class="sy0">&lt;/</span>mx:Script<span class="sy0">&gt;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; <span class="sy0">&lt;</span>mx:<span class="kw3">Button</span> id=<span class="st0">&quot;btPrev&quot;</span> label=<span class="st0">&quot;Previous&quot;</span><span class="sy0">/&gt;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; <span class="sy0">&lt;</span>mx:<span class="kw3">Button</span> id=<span class="st0">&quot;btNext&quot;</span> label=<span class="st0">&quot;Next&quot;</span><span class="sy0">/&gt;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; <span class="sy0">&lt;</span>mx:<span class="kw3">Button</span> id=<span class="st0">&quot;btPlay&quot;</span> label=<span class="st0">&quot;Play&quot;</span><span class="sy0">/&gt;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; <span class="sy0">&lt;</span>mx:<span class="kw3">Button</span> id=<span class="st0">&quot;btFullScreen&quot;</span> label=<span class="st0">&quot;Full Screen&quot;</span><span class="sy0">/&gt;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; <span class="sy0">&lt;</span>mx:<span class="kw3">Button</span> id=<span class="st0">&quot;btSound&quot;</span> label=<span class="st0">&quot;Sound&quot;</span><span class="sy0">/&gt;</span></div>
</li>
<li class="li1">
<div class="de1"><span class="sy0">&lt;/</span>mx:HBox<span class="sy0">&gt;</span></div>
</li>
</ol>
</div>
<p>This will create the five buttons and center them within an HBox with a rounded rectangle background. To include our new component in the main application, open up SitePointTutorial.mxml and update it so your code matches the following:</p>
<div class="actionscript geshi no actionscript" style="font-family:monospace;">
<ol>
<li class="li1">
<div class="de1"><span class="sy0">&lt;</span>?<span class="kw3">xml</span> <span class="kw3">version</span>=<span class="st0">&quot;1.0&quot;</span> encoding=<span class="st0">&quot;utf-8&quot;</span>?<span class="sy0">&gt;</span></div>
</li>
<li class="li1">
<div class="de1"><span class="sy0">&lt;</span>mx:Application xmlns:mx=<span class="st0">&quot;http://www.adobe.com/2006/mxml&quot;</span> xmlns:components=<span class="st0">&quot;components.*&quot;</span> layout=<span class="st0">&quot;absolute&quot;</span><span class="sy0">&gt;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; <span class="sy0">&lt;</span>mx:HBox <span class="kw3">width</span>=<span class="st0">&quot;100%&quot;</span> horizontalAlign=<span class="st0">&quot;center&quot;</span> bottom=<span class="st0">&quot;60&quot;</span><span class="sy0">&gt;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; <span class="sy0">&lt;</span>components:SlideshowNavigationBar id=<span class="st0">&quot;mySlideshowNavigationBar&quot;</span><span class="sy0">/&gt;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; <span class="sy0">&lt;/</span>mx:HBox<span class="sy0">&gt;</span></div>
</li>
<li class="li1">
<div class="de1"><span class="sy0">&lt;/</span>mx:Application<span class="sy0">&gt;</span></div>
</li>
</ol>
</div>
<p>Note the <code>xmlns:components="components.*"</code> in the Application tag. This is because our custom component is in a folder that we named components.  Therefore we need to define a namespace that tells the compiler where to find our custom component.  All the standard components that ship with the Flex framework begin with a namespace of mx.  The mx namespace is also defined in the Application tag and it points to www.adobe.com/2006/mxml.</p>
<p>Our component is added to the application with the simple mxml tag:</p>
<div class="actionscript geshi no actionscript" style="font-family:monospace;">
<ol>
<li class="li1">
<div class="de1"><span class="sy0">&lt;</span>components:SlideshowNavigationBar id=<span class="st0">&quot;mySlideshowNavigationBar&quot;</span><span class="sy0">/&gt;</span></div>
</li>
</ol>
</div>
<p>The id property is needed to access the component with ActionScript.</p>
<p>To test the application, click the Debug button.</p>
<p><a href="http://www.curiousfind.com/blog/wp-content/uploads/flex_article_3.png"><img class="alignnone size-full wp-image-54" title="flex_article_3" src="http://www.curiousfind.com/blog/wp-content/uploads/flex_article_3.png" alt="" width="215" height="101" /></a></p>
<p>You should see the application running in your browser.</p>
<p><a href="http://www.curiousfind.com/blog/wp-content/uploads/flex_article_4.png"><img class="alignnone size-full wp-image-55" title="flex_article_4" src="http://www.curiousfind.com/blog/wp-content/uploads/flex_article_4.png" alt="" width="443" height="388" /></a></p>
<h3>Styling the Slideshow Navigation Bar</h3>
<p>In SlideshowNavigationBar.mxml add the following code inside the <code>&lt;mx:Script&gt;</code> tag just above the onInitialize function:</p>
<div class="actionscript geshi no actionscript" style="font-family:monospace;">
<ol>
<li class="li1">
<div class="de1"><span class="br0">&#91;</span>Embed<span class="br0">&#40;</span>source=<span class="st0">&quot;../assets/prev.png&quot;</span><span class="br0">&#41;</span><span class="br0">&#93;</span></div>
</li>
<li class="li1">
<div class="de1"><span class="kw3">private</span> <span class="kw2">var</span> _prevIcon:<span class="kw2">Class</span>;</div>
</li>
<li class="li1">
<div class="de1"><span class="br0">&#91;</span>Embed<span class="br0">&#40;</span>source=<span class="st0">&quot;../assets/next.png&quot;</span><span class="br0">&#41;</span><span class="br0">&#93;</span></div>
</li>
<li class="li1">
<div class="de1"><span class="kw3">private</span> <span class="kw2">var</span> _nextIcon:<span class="kw2">Class</span>;</div>
</li>
<li class="li1">
<div class="de1"><span class="br0">&#91;</span>Embed<span class="br0">&#40;</span>source=<span class="st0">&quot;../assets/play.png&quot;</span><span class="br0">&#41;</span><span class="br0">&#93;</span></div>
</li>
<li class="li1">
<div class="de1"><span class="kw3">private</span> <span class="kw2">var</span> _playIcon:<span class="kw2">Class</span>;</div>
</li>
<li class="li1">
<div class="de1"><span class="br0">&#91;</span>Embed<span class="br0">&#40;</span>source=<span class="st0">&quot;../assets/pause.png&quot;</span><span class="br0">&#41;</span><span class="br0">&#93;</span></div>
</li>
<li class="li1">
<div class="de1"><span class="kw3">private</span> <span class="kw2">var</span> _pauseIcon:<span class="kw2">Class</span>;</div>
</li>
<li class="li1">
<div class="de1"><span class="br0">&#91;</span>Embed<span class="br0">&#40;</span>source=<span class="st0">&quot;../assets/fullscreen.png&quot;</span><span class="br0">&#41;</span><span class="br0">&#93;</span></div>
</li>
<li class="li1">
<div class="de1"><span class="kw3">private</span> <span class="kw2">var</span> _fullscreenIcon:<span class="kw2">Class</span>;</div>
</li>
<li class="li1">
<div class="de1"><span class="br0">&#91;</span>Embed<span class="br0">&#40;</span>source=<span class="st0">&quot;../assets/smallscreen.png&quot;</span><span class="br0">&#41;</span><span class="br0">&#93;</span></div>
</li>
<li class="li1">
<div class="de1"><span class="kw3">private</span> <span class="kw2">var</span> _smallscreenIcon:<span class="kw2">Class</span>;</div>
</li>
<li class="li1">
<div class="de1"><span class="br0">&#91;</span>Embed<span class="br0">&#40;</span>source=<span class="st0">&quot;../assets/sound_on.png&quot;</span><span class="br0">&#41;</span><span class="br0">&#93;</span></div>
</li>
<li class="li1">
<div class="de1"><span class="kw3">private</span> <span class="kw2">var</span> _soundOnIcon:<span class="kw2">Class</span>;</div>
</li>
<li class="li1">
<div class="de1"><span class="br0">&#91;</span>Embed<span class="br0">&#40;</span>source=<span class="st0">&quot;../assets/sound_off.png&quot;</span><span class="br0">&#41;</span><span class="br0">&#93;</span></div>
</li>
<li class="li1">
<div class="de1"><span class="kw3">private</span> <span class="kw2">var</span> _soundOffIcon:<span class="kw2">Class</span>;</div>
</li>
</ol>
</div>
<p>You will need to copy the graphic files from this tutorial into the assets folder of your project.</p>
<p>It is worth noting that we could do without the above code and set the upSkin, overSkin, and downSkin properties of each of our buttons like so:</p>
<div class="actionscript geshi no actionscript" style="font-family:monospace;">
<ol>
<li class="li1">
<div class="de1"><span class="sy0">&lt;</span>mx:<span class="kw3">Button</span> id=<span class="st0">&quot;btPrev&quot;</span> upSkin=<span class="st0">&quot;@Embed(source=&#39;../assets/prev.png&#39;)&quot;</span></div>
</li>
<li class="li1">
<div class="de1">overSkin=<span class="st0">&quot;@Embed(source=&#39;../assets/prev.png&#39;)&quot;</span></div>
</li>
<li class="li1">
<div class="de1">downSkin=<span class="st0">&quot;@Embed(source=&#39;../assets/prev.png&#39;)&quot;</span><span class="sy0">/&gt;</span></div>
</li>
</ol>
</div>
<p>However by associating each graphic with a class, we can swap out the icons at runtime using ActionScript. We will need to do that, for example, when the play button should show a pause graphic.</p>
<p>Also note that we have designated the scope of our variables as private and have prefixed their names with an underscore.  Setting variables inside a custom component as private is not required, but it is recommended as a best practice.  You can always make the variable more accessible later if needed. Prefixing private variables with an underscore is a coding practice used by many developers for readability.</p>
<p>We now need to update the onInitialize function so that it contains the following code:</p>
<div class="actionscript geshi no actionscript" style="font-family:monospace;">
<ol>
<li class="li1">
<div class="de1"><span class="kw3">private</span> <span class="kw2">function</span> onInitialize<span class="br0">&#40;</span><span class="br0">&#41;</span>:<span class="kw3">void</span></div>
</li>
<li class="li1">
<div class="de1"><span class="br0">&#123;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; btPrev.<span class="kw3">setStyle</span><span class="br0">&#40;</span><span class="st0">&quot;upSkin&quot;</span>, _prevIcon<span class="br0">&#41;</span>;</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; btPrev.<span class="kw3">setStyle</span><span class="br0">&#40;</span><span class="st0">&quot;overSkin&quot;</span>, _prevIcon<span class="br0">&#41;</span>;</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; btPrev.<span class="kw3">setStyle</span><span class="br0">&#40;</span><span class="st0">&quot;downSkin&quot;</span>, _prevIcon<span class="br0">&#41;</span>;</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; btNext.<span class="kw3">setStyle</span><span class="br0">&#40;</span><span class="st0">&quot;upSkin&quot;</span>, _nextIcon<span class="br0">&#41;</span>;</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; btNext.<span class="kw3">setStyle</span><span class="br0">&#40;</span><span class="st0">&quot;overSkin&quot;</span>, _nextIcon<span class="br0">&#41;</span>;</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; btNext.<span class="kw3">setStyle</span><span class="br0">&#40;</span><span class="st0">&quot;downSkin&quot;</span>, _nextIcon<span class="br0">&#41;</span>;</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; btPlay.<span class="kw3">setStyle</span><span class="br0">&#40;</span><span class="st0">&quot;upSkin&quot;</span>, _pauseIcon<span class="br0">&#41;</span>;</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; btPlay.<span class="kw3">setStyle</span><span class="br0">&#40;</span><span class="st0">&quot;overSkin&quot;</span>, _pauseIcon<span class="br0">&#41;</span>;</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; btPlay.<span class="kw3">setStyle</span><span class="br0">&#40;</span><span class="st0">&quot;downSkin&quot;</span>, _pauseIcon<span class="br0">&#41;</span>;</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; btFullScreen.<span class="kw3">setStyle</span><span class="br0">&#40;</span><span class="st0">&quot;upSkin&quot;</span>, _fullscreenIcon<span class="br0">&#41;</span>;</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; btFullScreen.<span class="kw3">setStyle</span><span class="br0">&#40;</span><span class="st0">&quot;overSkin&quot;</span>, _fullscreenIcon<span class="br0">&#41;</span>;</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; btFullScreen.<span class="kw3">setStyle</span><span class="br0">&#40;</span><span class="st0">&quot;downSkin&quot;</span>, _fullscreenIcon<span class="br0">&#41;</span>;</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; btSound.<span class="kw3">setStyle</span><span class="br0">&#40;</span><span class="st0">&quot;upSkin&quot;</span>, _soundOnIcon<span class="br0">&#41;</span>;</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; btSound.<span class="kw3">setStyle</span><span class="br0">&#40;</span><span class="st0">&quot;overSkin&quot;</span>, _soundOnIcon<span class="br0">&#41;</span>;</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; btSound.<span class="kw3">setStyle</span><span class="br0">&#40;</span><span class="st0">&quot;downSkin&quot;</span>, _soundOnIcon<span class="br0">&#41;</span>;</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; <span class="kw3">this</span>.<span class="me1">drawRoundRect</span><span class="br0">&#40;</span><span class="nu0">0</span>, <span class="nu0">0</span>, <span class="nu0">400</span>, <span class="nu0">60</span>,</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; <span class="br0">&#123;</span>tl: <span class="nu0">7</span>, tr:<span class="nu0">7</span>, bl:<span class="nu0">7</span>, br: <span class="nu0">7</span><span class="br0">&#125;</span>,</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; 0&#215;3A3A3A, <span class="nu0">0.75</span><span class="br0">&#41;</span>;</div>
</li>
<li class="li1">
<div class="de1"><span class="br0">&#125;</span></div>
</li>
</ol>
</div>
<p>Remove the label property on each of the five buttons so that they look like the following:</p>
<div class="actionscript geshi no actionscript" style="font-family:monospace;">
<ol>
<li class="li1">
<div class="de1"><span class="sy0">&lt;</span>mx:<span class="kw3">Button</span> id=<span class="st0">&quot;btPrev&quot;</span><span class="sy0">/&gt;</span></div>
</li>
<li class="li1">
<div class="de1"><span class="sy0">&lt;</span>mx:<span class="kw3">Button</span> id=<span class="st0">&quot;btNext&quot;</span><span class="sy0">/&gt;</span></div>
</li>
<li class="li1">
<div class="de1"><span class="sy0">&lt;</span>mx:<span class="kw3">Button</span> id=<span class="st0">&quot;btPlay&quot;</span><span class="sy0">/&gt;</span></div>
</li>
<li class="li1">
<div class="de1"><span class="sy0">&lt;</span>mx:<span class="kw3">Button</span> id=<span class="st0">&quot;btFullScreen&quot;</span><span class="sy0">/&gt;</span></div>
</li>
<li class="li1">
<div class="de1"><span class="sy0">&lt;</span>mx:<span class="kw3">Button</span> id=<span class="st0">&quot;btVolume&quot;</span><span class="sy0">/&gt;</span></div>
</li>
</ol>
</div>
<p>Run the application and you should see the styled navigation bar below:</p>
<p><a href="http://www.curiousfind.com/blog/wp-content/uploads/flex_article_5.png"><img class="alignnone size-full wp-image-56" title="flex_article_5" src="http://www.curiousfind.com/blog/wp-content/uploads/flex_article_5.png" alt="" width="468" height="362" /></a></p>
<h3>Changing a Button’s Appearance on Mouseover</h3>
<p>When the user hovers over the buttons, we would like to provide visual feedback.  One way to do that is by adjusting the alpha value.  In the onInitialize function, add the following code:</p>
<div class="actionscript geshi no actionscript" style="font-family:monospace;">
<ol>
<li class="li1">
<div class="de1">btPrev.<span class="me1">alpha</span> = <span class="nu0">0.75</span>;</div>
</li>
<li class="li1">
<div class="de1">btNext.<span class="me1">alpha</span> = <span class="nu0">0.75</span>;</div>
</li>
<li class="li1">
<div class="de1">btPlay.<span class="me1">alpha</span> = <span class="nu0">0.75</span>;</div>
</li>
<li class="li1">
<div class="de1">btFullScreen.<span class="me1">alpha</span> = <span class="nu0">0.75</span>;</div>
</li>
<li class="li1">
<div class="de1">btSound.<span class="me1">alpha</span> = <span class="nu0">0.75</span>;</div>
</li>
</ol>
</div>
<p>To make the buttons respond to a mouseover event, we will first need to register event handler functions for each of the five buttons.  To do so, add the following code to the onInitialize function:</p>
<div class="actionscript geshi no actionscript" style="font-family:monospace;">
<ol>
<li class="li1">
<div class="de1">btPrev.<span class="me1">addEventListener</span><span class="br0">&#40;</span>MouseEvent.<span class="me1">MOUSE_OVER</span>, onButtonMouseOver<span class="br0">&#41;</span>;</div>
</li>
<li class="li1">
<div class="de1">btPrev.<span class="me1">addEventListener</span><span class="br0">&#40;</span>MouseEvent.<span class="me1">MOUSE_OUT</span>, onButtonMouseOut<span class="br0">&#41;</span>;</div>
</li>
<li class="li1">
<div class="de1">btNext.<span class="me1">addEventListener</span><span class="br0">&#40;</span>MouseEvent.<span class="me1">MOUSE_OVER</span>, onButtonMouseOver<span class="br0">&#41;</span>;</div>
</li>
<li class="li1">
<div class="de1">btNext.<span class="me1">addEventListener</span><span class="br0">&#40;</span>MouseEvent.<span class="me1">MOUSE_OUT</span>, onButtonMouseOut<span class="br0">&#41;</span>;</div>
</li>
<li class="li1">
<div class="de1">btPlay.<span class="me1">addEventListener</span><span class="br0">&#40;</span>MouseEvent.<span class="me1">MOUSE_OVER</span>, onButtonMouseOver<span class="br0">&#41;</span>;</div>
</li>
<li class="li1">
<div class="de1">btPlay.<span class="me1">addEventListener</span><span class="br0">&#40;</span>MouseEvent.<span class="me1">MOUSE_OUT</span>, onButtonMouseOut<span class="br0">&#41;</span>;</div>
</li>
<li class="li1">
<div class="de1">btFullScreen.<span class="me1">addEventListener</span><span class="br0">&#40;</span>MouseEvent.<span class="me1">MOUSE_OVER</span>, onButtonMouseOver<span class="br0">&#41;</span>;</div>
</li>
<li class="li1">
<div class="de1">btFullScreen.<span class="me1">addEventListener</span><span class="br0">&#40;</span>MouseEvent.<span class="me1">MOUSE_OUT</span>, onButtonMouseOut<span class="br0">&#41;</span>;</div>
</li>
<li class="li1">
<div class="de1">btSound.<span class="me1">addEventListener</span><span class="br0">&#40;</span>MouseEvent.<span class="me1">MOUSE_OVER</span>, onButtonMouseOver<span class="br0">&#41;</span>;</div>
</li>
<li class="li1">
<div class="de1">btSound.<span class="me1">addEventListener</span><span class="br0">&#40;</span>MouseEvent.<span class="me1">MOUSE_OUT</span>, onButtonMouseOut<span class="br0">&#41;</span>;</div>
</li>
</ol>
</div>
<p>Next, add these two event handler functions. The functions can appear anywhere, but I would suggest placing them after the onInitialize function.</p>
<div class="actionscript geshi no actionscript" style="font-family:monospace;">
<ol>
<li class="li1">
<div class="de1"><span class="kw3">private</span> <span class="kw2">function</span> onButtonMouseOver<span class="br0">&#40;</span>event:MouseEvent<span class="br0">&#41;</span>:<span class="kw3">void</span></div>
</li>
<li class="li1">
<div class="de1"><span class="br0">&#123;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; event.<span class="me1">currentTarget</span>.<span class="me1">alpha</span> = <span class="nu0">1.0</span>;</div>
</li>
<li class="li1">
<div class="de1"><span class="br0">&#125;</span></div>
</li>
<li class="li1">
<div class="de1"><span class="kw3">private</span> <span class="kw2">function</span> onButtonMouseOut<span class="br0">&#40;</span>event:MouseEvent<span class="br0">&#41;</span>:<span class="kw3">void</span></div>
</li>
<li class="li1">
<div class="de1"><span class="br0">&#123;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; event.<span class="me1">currentTarget</span>.<span class="me1">alpha</span> = <span class="nu0">0.75</span>;</div>
</li>
<li class="li1">
<div class="de1"><span class="br0">&#125;</span></div>
</li>
</ol>
</div>
<p>When an event occurs, an event object gets passed to the event handler function. The event object has properties that contain information about the event. Here we have used the currentTarget property of the event object to point to the button that triggered the event.</p>
<p>Before we run the application, let’s set the background color in our SitePointTutorial.mxml file.</p>
<div class="actionscript geshi no actionscript" style="font-family:monospace;">
<ol>
<li class="li1">
<div class="de1"><span class="sy0">&lt;</span>mx:Application xmlns:mx=<span class="st0">&quot;http://www.adobe.com/2006/mxml&quot;</span> xmlns:components=<span class="st0">&quot;components.*&quot;</span> layout=<span class="st0">&quot;absolute&quot;</span> <span class="kw3">backgroundColor</span>=<span class="st0">&quot;#000000&quot;</span><span class="sy0">&gt;</span></div>
</li>
</ol>
</div>
<p>Now when you hover the mouse over the buttons, you should get a subtle visual clue.</p>
<p>With our slideshow navigation bar looking good, let’s move to the next step &#8212; programming our custom component to dispatch an event that contains information on which button was clicked.  Events are how components notify the application (or the larger component that they are part of) that an action has taken place.  Just as each of the five button components dispatched mouseover events that our SlideshowNavigationBar component listened for, the SlideshowNavigationBar component can be programmed to dispatch events that its parent (the application SitePointTutorial) listens for.</p>
<h3>“Loosely Coupled” Versus “Tightly Coupled” Components</h3>
<p>Before programming the SlideshowNavigationBar to dispatch its own custom events, let’s talk about how you could accomplish the same result without doing so. You could update the SitePointTutorial.mxml file as follows:</p>
<div class="actionscript geshi no actionscript" style="font-family:monospace;">
<ol>
<li class="li1">
<div class="de1"><span class="sy0">&lt;</span>mx:Application xmlns:mx=<span class="st0">&quot;http://www.adobe.com/2006/mxml&quot;</span> xmlns:components=<span class="st0">&quot;components.*&quot;</span> layout=<span class="st0">&quot;absolute&quot;</span> <span class="kw3">backgroundColor</span>=<span class="st0">&quot;#000000&quot;</span> initialize=<span class="st0">&quot;onInitialize()&quot;</span><span class="sy0">&gt;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; <span class="sy0">&lt;</span>mx:Script<span class="sy0">&gt;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; <span class="sy0">&lt;!</span><span class="br0">&#91;</span>CDATA<span class="br0">&#91;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="kw3">private</span> <span class="kw2">function</span> onInitialize<span class="br0">&#40;</span><span class="br0">&#41;</span>:<span class="kw3">void</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp;</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="br0">&#123;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; mySlideshowNavigationBar.<span class="me1">btPrev</span>.<span class="me1">addEventListener</span><span class="br0">&#40;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; MouseEvent.<span class="me1">CLICK</span>, onPrevClick<span class="br0">&#41;</span>;</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="br0">&#125;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="kw3">private</span> <span class="kw2">function</span> onPrevClick<span class="br0">&#40;</span>event:MouseEvent<span class="br0">&#41;</span>:<span class="kw3">void</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="br0">&#123;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="kw3">trace</span><span class="br0">&#40;</span><span class="st0">&quot;Previous Button Clicked&quot;</span><span class="br0">&#41;</span>;</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="br0">&#125;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; <span class="br0">&#93;</span><span class="br0">&#93;</span><span class="sy0">&gt;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; <span class="sy0">&lt;/</span>mx:Script<span class="sy0">&gt;</span></div>
</li>
</ol>
</div>
<p>Here we have registered an event listener on the component btPrev inside our component mySlideshowNavigationBar.  This works, however it is not a best practice.   By doing so, you are creating what is referred to as a “tightly coupled” component.  If you were to use the slideshow navigation bar in several applications and then changed the id of the button to something else (perhaps btPrevSlide), it would break all the applications that relied on the component the next time they were compiled.</p>
<p>A “loosely coupled” component, on the other hand, has a well-defined interface. The internal workings of the component can change, but the interface does not. Information is passed down to the component through the setting of properties. The component passes information back up with event objects (or, in some cases, the parent reads a property of the component at a specific point in time.)</p>
<p>To develop a “loosely coupled” (and thus highly reusable component) you should avoid accessing the component’s own internal components.  So instead of “reaching inside” mySlideshowNavigationBar and registering an event listener on its button, we should register an event listener directly on mySlideshowNavigationBar.  But first we need to program our slideshow navigation bar component to dispatch events.</p>
<h3>Creating a Custom Event</h3>
<p>The base class for all event objects is the flash.events.Event class.  Subclasses such as the MouseEvent class extend the Event class to contain additional information.  You can see all the standard subclasses listed in the <a href="http://livedocs.adobe.com/flex/3/langref/flash/events/Event.html">Flex documentation</a>.  You can create your own subclasses of the Event class as well, which is what we will be doing now.</p>
<p>Click File -&gt; New -&gt; ActionScript Class.  Browse and select the events folder as the package. Give it a name of SlideshowNavigationBarEvent. Set the Superclass as flash.events.Event (if you click Browse, it is under Event – flash.events).</p>
<p><a href="http://www.curiousfind.com/blog/wp-content/uploads/flex_article_6.png"><img class="alignnone size-full wp-image-57" title="flex_article_6" src="http://www.curiousfind.com/blog/wp-content/uploads/flex_article_6.png" alt="" width="500" height="557" /></a></p>
<p>Update the code for SlideshowNavigationBarEvent.as to match the following:</p>
<div class="actionscript geshi no actionscript" style="font-family:monospace;">
<ol>
<li class="li1">
<div class="de1">package events</div>
</li>
<li class="li1">
<div class="de1"><span class="br0">&#123;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; <span class="kw3">import</span> flash.<span class="me1">events</span>.<span class="me1">Event</span>;</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; <span class="kw3">public</span> <span class="kw2">class</span> SlideshowNavigationBarEvent <span class="kw3">extends</span> Event</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; <span class="br0">&#123;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; <span class="kw3">public</span> <span class="kw3">static</span> const PLAY_CLICK:<span class="kw3">String</span> = <span class="st0">&quot;playClick&quot;</span>;</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; <span class="kw3">public</span> <span class="kw3">static</span> const PREVIOUS_CLICK:<span class="kw3">String</span> = <span class="st0">&quot;previousClick&quot;</span>;</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; <span class="kw3">public</span> <span class="kw3">static</span> const NEXT_CLICK:<span class="kw3">String</span> = <span class="st0">&quot;nextClick&quot;</span>;</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; <span class="kw3">public</span> <span class="kw3">static</span> const FULLSCREEN_CLICK:<span class="kw3">String</span> = <span class="st0">&quot;fullscreenClick&quot;</span>;</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; <span class="kw3">public</span> <span class="kw3">static</span> const SOUND_CLICK:<span class="kw3">String</span> = <span class="st0">&quot;soundClick&quot;</span>;</div>
</li>
<li class="li1">
<div class="de1">&nbsp;</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; <span class="kw3">public</span> <span class="kw2">function</span> SlideshowNavigationBarEvent<span class="br0">&#40;</span><span class="kw3">type</span>:<span class="kw3">String</span>,</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; bubbles:<span class="kw3">Boolean</span>=<span class="kw2">false</span>, cancelable:<span class="kw3">Boolean</span>=<span class="kw2">false</span><span class="br0">&#41;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; <span class="br0">&#123;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="kw3">super</span><span class="br0">&#40;</span><span class="kw3">type</span>, bubbles, cancelable<span class="br0">&#41;</span>;</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; <span class="br0">&#125;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp;</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; override <span class="kw3">public</span> <span class="kw2">function</span> clone<span class="br0">&#40;</span><span class="br0">&#41;</span>:Event</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; <span class="br0">&#123;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="kw1">return</span> <span class="kw2">new</span> SlideshowNavigationBarEvent<span class="br0">&#40;</span><span class="kw3">type</span>, bubbles,</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; cancelable<span class="br0">&#41;</span>;</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; <span class="br0">&#125;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; <span class="br0">&#125;</span></div>
</li>
<li class="li1">
<div class="de1"><span class="br0">&#125;</span></div>
</li>
</ol>
</div>
<p>In our custom event class we have defined five constants that will be used as the value for the event’s type property. We have defined the constructor to require the type property be set. The constructor also accepts two optional arguments.  All three properties are passed with the super method.  (The super method calls the constructor of the superclass, which is the Event class.)  We also overrode the clone method which is required when creating a subclass of the Event class.</p>
<p>To use our new custom event, add this line to SlideshowNavigationBar.mxml inside the  <code>&lt;mx:Script&gt;</code> tag at the top:</p>
<div class="actionscript geshi no actionscript" style="font-family:monospace;">
<ol>
<li class="li1">
<div class="de1"><span class="kw3">import</span> events.<span class="me1">SlideshowNavigationBarEvent</span>;</div>
</li>
</ol>
</div>
<p>Before the  <code>&lt;mx:Script&gt;</code> tag, add the following:</p>
<div class="actionscript geshi no actionscript" style="font-family:monospace;">
<ol>
<li class="li1">
<div class="de1"><span class="sy0">&lt;</span>mx:Metadata<span class="sy0">&gt;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; <span class="br0">&#91;</span>Event<span class="br0">&#40;</span><span class="kw3">name</span>=<span class="st0">&quot;playClick&quot;</span>, <span class="kw3">type</span>=<span class="st0">&quot;events.SlideshowNavigationBarEvent&quot;</span><span class="br0">&#41;</span><span class="br0">&#93;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; <span class="br0">&#91;</span>Event<span class="br0">&#40;</span><span class="kw3">name</span>=<span class="st0">&quot;previousClick&quot;</span>, <span class="kw3">type</span>=<span class="st0">&quot;events.SlideshowNavigationBarEvent&quot;</span><span class="br0">&#41;</span><span class="br0">&#93;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; <span class="br0">&#91;</span>Event<span class="br0">&#40;</span><span class="kw3">name</span>=<span class="st0">&quot;nextClick&quot;</span>, <span class="kw3">type</span>=<span class="st0">&quot;events.SlideshowNavigationBarEvent&quot;</span><span class="br0">&#41;</span><span class="br0">&#93;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; <span class="br0">&#91;</span>Event<span class="br0">&#40;</span><span class="kw3">name</span>=<span class="st0">&quot;fullscreenClick&quot;</span>, <span class="kw3">type</span>=<span class="st0">&quot;events.SlideshowNavigationBarEvent&quot;</span><span class="br0">&#41;</span><span class="br0">&#93;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; <span class="br0">&#91;</span>Event<span class="br0">&#40;</span><span class="kw3">name</span>=<span class="st0">&quot;soundClick&quot;</span>, <span class="kw3">type</span>=<span class="st0">&quot;events.SlideshowNavigationBarEvent&quot;</span><span class="br0">&#41;</span><span class="br0">&#93;</span></div>
</li>
<li class="li1">
<div class="de1"><span class="sy0">&lt;/</span>mx:Metadata<span class="sy0">&gt;</span></div>
</li>
</ol>
</div>
<p>Now in the onInitialize function in SlideshowNavigatonBar.mxml add the following:</p>
<div class="actionscript geshi no actionscript" style="font-family:monospace;">
<ol>
<li class="li1">
<div class="de1">btPrev.<span class="me1">addEventListener</span><span class="br0">&#40;</span>MouseEvent.<span class="me1">CLICK</span>, onButtonClick<span class="br0">&#41;</span>;</div>
</li>
<li class="li1">
<div class="de1">btNext.<span class="me1">addEventListener</span><span class="br0">&#40;</span>MouseEvent.<span class="me1">CLICK</span>, onButtonClick<span class="br0">&#41;</span>;</div>
</li>
<li class="li1">
<div class="de1">btPlay.<span class="me1">addEventListener</span><span class="br0">&#40;</span>MouseEvent.<span class="me1">CLICK</span>, onButtonClick<span class="br0">&#41;</span>;</div>
</li>
<li class="li1">
<div class="de1">btFullScreen.<span class="me1">addEventListener</span><span class="br0">&#40;</span>MouseEvent.<span class="me1">CLICK</span>, onButtonClick<span class="br0">&#41;</span>;</div>
</li>
<li class="li1">
<div class="de1">btSound.<span class="me1">addEventListener</span><span class="br0">&#40;</span>MouseEvent.<span class="me1">CLICK</span>, onButtonClick<span class="br0">&#41;</span>;</div>
</li>
</ol>
</div>
<p>Add this event handler function to SlideshowNavigationBar.mxml after the other functions:</p>
<div class="actionscript geshi no actionscript" style="font-family:monospace;">
<ol>
<li class="li1">
<div class="de1"><span class="kw3">private</span> <span class="kw2">function</span> onButtonClick<span class="br0">&#40;</span>event:MouseEvent<span class="br0">&#41;</span>:<span class="kw3">void</span></div>
</li>
<li class="li1">
<div class="de1"><span class="br0">&#123;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; <span class="kw2">var</span> eventObj:SlideshowNavigationBarEvent;</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; <span class="kw1">switch</span> <span class="br0">&#40;</span>event.<span class="me1">currentTarget</span>.<span class="me1">id</span><span class="br0">&#41;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; <span class="br0">&#123;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; <span class="kw1">case</span> <span class="st0">&#39;btPrev&#39;</span> :</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; eventObj = <span class="kw2">new</span> SlideshowNavigationBarEvent<span class="br0">&#40;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; SlideshowNavigationBarEvent.<span class="me1">PREVIOUS_CLICK</span><span class="br0">&#41;</span>;</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; dispatchEvent<span class="br0">&#40;</span>eventObj<span class="br0">&#41;</span>;</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="kw1">break</span>;</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; <span class="kw1">case</span> <span class="st0">&#39;btNext&#39;</span> :</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; eventObj = <span class="kw2">new</span> SlideshowNavigationBarEvent<span class="br0">&#40;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; SlideshowNavigationBarEvent.<span class="me1">NEXT_CLICK</span><span class="br0">&#41;</span>;</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; dispatchEvent<span class="br0">&#40;</span>eventObj<span class="br0">&#41;</span>;</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="kw1">break</span>;</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; <span class="kw1">case</span> <span class="st0">&#39;btPlay&#39;</span> :</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; eventObj = <span class="kw2">new</span> SlideshowNavigationBarEvent<span class="br0">&#40;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; SlideshowNavigationBarEvent.<span class="me1">PLAY_CLICK</span><span class="br0">&#41;</span>;</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; dispatchEvent<span class="br0">&#40;</span>eventObj<span class="br0">&#41;</span>;</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="kw1">break</span>;</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; <span class="kw1">case</span> <span class="st0">&#39;btFullScreen&#39;</span> :</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; eventObj = <span class="kw2">new</span> SlideshowNavigationBarEvent<span class="br0">&#40;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; SlideshowNavigationBarEvent.<span class="me1">FULLSCREEN_CLICK</span><span class="br0">&#41;</span>;</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; dispatchEvent<span class="br0">&#40;</span>eventObj<span class="br0">&#41;</span>;</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="kw1">break</span>;</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; <span class="kw1">case</span> <span class="st0">&#39;btSound&#39;</span> :</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; eventObj = <span class="kw2">new</span> SlideshowNavigationBarEvent<span class="br0">&#40;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; SlideshowNavigationBarEvent.<span class="me1">SOUND_CLICK</span><span class="br0">&#41;</span>;</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; dispatchEvent<span class="br0">&#40;</span>eventObj<span class="br0">&#41;</span>;</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="kw1">break</span>;</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; <span class="kw2">default</span> :</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="kw1">break</span>;</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; <span class="br0">&#125;</span></div>
</li>
<li class="li1">
<div class="de1"><span class="br0">&#125;</span></div>
</li>
</ol>
</div>
<p>Our slideshow navigation bar component will now dispatch events that its parent component can listen for.  Update the SitePointTutorial.mxml as so:</p>
<div class="actionscript geshi no actionscript" style="font-family:monospace;">
<ol>
<li class="li1">
<div class="de1"><span class="sy0">&lt;</span>mx:Application xmlns:mx=<span class="st0">&quot;http://www.adobe.com/2006/mxml&quot;</span> xmlns:components=<span class="st0">&quot;components.*&quot;</span> layout=<span class="st0">&quot;absolute&quot;</span> <span class="kw3">backgroundColor</span>=<span class="st0">&quot;#000000&quot;</span> initialize=<span class="st0">&quot;onInitialize()&quot;</span><span class="sy0">&gt;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; <span class="sy0">&lt;</span>mx:Script<span class="sy0">&gt;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; <span class="sy0">&lt;!</span><span class="br0">&#91;</span>CDATA<span class="br0">&#91;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="kw3">import</span> events.<span class="me1">SlideshowNavigationBarEvent</span>;</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="kw3">private</span> <span class="kw2">function</span> onInitialize<span class="br0">&#40;</span><span class="br0">&#41;</span>:<span class="kw3">void</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="br0">&#123;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; mySlideshowNavigationBar.<span class="me1">addEventListener</span><span class="br0">&#40;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; SlideshowNavigationBarEvent.<span class="me1">PREVIOUS_CLICK</span>, onPrevClick<span class="br0">&#41;</span>;</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; mySlideshowNavigationBar.<span class="me1">addEventListener</span><span class="br0">&#40;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; SlideshowNavigationBarEvent.<span class="me1">NEXT_CLICK</span>, onNextClick<span class="br0">&#41;</span>;</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; mySlideshowNavigationBar.<span class="me1">addEventListener</span><span class="br0">&#40;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; SlideshowNavigationBarEvent.<span class="me1">PLAY_CLICK</span>, onPlayClick<span class="br0">&#41;</span>;</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; mySlideshowNavigationBar.<span class="me1">addEventListener</span><span class="br0">&#40;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; SlideshowNavigationBarEvent.<span class="me1">FULLSCREEN_CLICK</span>, onFullScreenClick<span class="br0">&#41;</span>;</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; mySlideshowNavigationBar.<span class="me1">addEventListener</span><span class="br0">&#40;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; SlideshowNavigationBarEvent.<span class="me1">SOUND_CLICK</span>, onSoundClick<span class="br0">&#41;</span>;</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="br0">&#125;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="kw3">private</span> <span class="kw2">function</span> onPrevClick<span class="br0">&#40;</span>event:SlideshowNavigationBarEvent<span class="br0">&#41;</span>:<span class="kw3">void</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="br0">&#123;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; myTextArea.<span class="kw3">htmlText</span> += <span class="st0">&quot;Go to previous slide.&lt;br&gt;&quot;</span>;</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="br0">&#125;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="kw3">private</span> <span class="kw2">function</span> onNextClick<span class="br0">&#40;</span>event:SlideshowNavigationBarEvent<span class="br0">&#41;</span>:<span class="kw3">void</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="br0">&#123;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; myTextArea.<span class="kw3">htmlText</span> += <span class="st0">&quot;Go to next slide.&lt;br&gt;&quot;</span>;</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="br0">&#125;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="kw3">private</span> <span class="kw2">function</span> onPlayClick<span class="br0">&#40;</span>event:SlideshowNavigationBarEvent<span class="br0">&#41;</span>:<span class="kw3">void</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="br0">&#123;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; myTextArea.<span class="kw3">htmlText</span> += <span class="st0">&quot;Pause slideshow.&lt;br&gt;&quot;</span>;</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="br0">&#125;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="kw3">private</span> <span class="kw2">function</span> onFullScreenClick<span class="br0">&#40;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; event:SlideshowNavigationBarEvent<span class="br0">&#41;</span>:<span class="kw3">void</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="br0">&#123;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; myTextArea.<span class="kw3">htmlText</span> += <span class="st0">&quot;Go to full screen.&lt;br&gt;&quot;</span>;</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="br0">&#125;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="kw3">private</span> <span class="kw2">function</span> onSoundClick<span class="br0">&#40;</span>event:SlideshowNavigationBarEvent<span class="br0">&#41;</span>:<span class="kw3">void</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="br0">&#123;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; myTextArea.<span class="kw3">htmlText</span> += <span class="st0">&quot;Turn sound off.&lt;br&gt;&quot;</span>;</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="br0">&#125;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; <span class="br0">&#93;</span><span class="br0">&#93;</span><span class="sy0">&gt;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; <span class="sy0">&lt;/</span>mx:Script<span class="sy0">&gt;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; <span class="sy0">&lt;</span>mx:HBox <span class="kw3">width</span>=<span class="st0">&quot;100%&quot;</span> horizontalAlign=<span class="st0">&quot;center&quot;</span><span class="sy0">&gt;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; <span class="sy0">&lt;</span>mx:TextArea id=<span class="st0">&quot;myTextArea&quot;</span> <span class="kw3">width</span>=<span class="st0">&quot;500&quot;</span> <span class="kw3">height</span>=<span class="st0">&quot;400&quot;</span><span class="sy0">/&gt;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; <span class="sy0">&lt;/</span>mx:HBox<span class="sy0">&gt;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; <span class="sy0">&lt;</span>mx:HBox <span class="kw3">width</span>=<span class="st0">&quot;100%&quot;</span> horizontalAlign=<span class="st0">&quot;center&quot;</span> bottom=<span class="st0">&quot;60&quot;</span><span class="sy0">&gt;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; <span class="sy0">&lt;</span>components:SlideshowNavigationBar id=<span class="st0">&quot;mySlideshowNavigationBar&quot;</span><span class="sy0">/&gt;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; <span class="sy0">&lt;/</span>mx:HBox<span class="sy0">&gt;</span></div>
</li>
<li class="li1">
<div class="de1"><span class="sy0">&lt;/</span>mx:Application<span class="sy0">&gt;</span></div>
</li>
</ol>
</div>
<p>When you run the application, take a moment to mentally step through the sequence that occurs when you click the Previous button:</p>
<ol>
<li>The btPrev component in the mySlideshowNavigationBar component dispatches a click event.</li>
<li>As a result of the click event, the onButtonClick event handler function gets called and creates a new event object that is an instance of SlideshowNavigationBarEvent &#8212; a custom class that we created which extends the Event class. This event object has its type property set to the string “previousClick” (defined by the constant PREVIOUS_CLICK). The event is then dispatched with the dispatchEvent method.</li>
<li>In the main application, the function onPrevClick gets called because we registered the appropriate event listener. The application then sends information to the myTextArea component by setting its htmlText property.</li>
</ol>
<p>This pattern is one that you will use repeatedly in the development of larger Flex applications.  The main application will contain several child components that dispatch events up to the parent application, which then sets properties on other child components.</p>
<p>It is also important to know that custom events can contain much more information than we used in our SlideshowNavigationBarEvent. We only used the type property, which is a standard property of the Event class. We could have extended the Event class to include new variables, including complex objects.</p>
<h3>Creating Properties for our Custom Component</h3>
<p>There are a few things left to do to make our slideshow navigation bar complete.  A slideshow would probably be playing automatically and when the user clicks the pause button, the application would stop at the current slide and change the pause button to a play button.  To allow for that, let’s add a property to the slideshow navigation bar component called isPlaying.  Add the following code to SlideshowNavigationBar.mxml above the onInitialize function:</p>
<div class="actionscript geshi no actionscript" style="font-family:monospace;">
<ol>
<li class="li1">
<div class="de1"><span class="kw3">private</span> <span class="kw2">var</span> _isPlaying:<span class="kw3">Boolean</span>;</div>
</li>
<li class="li1">
<div class="de1"><span class="kw3">public</span> <span class="kw2">function</span> <span class="kw3">get</span> isPlaying<span class="br0">&#40;</span><span class="br0">&#41;</span>:<span class="kw3">Boolean</span></div>
</li>
<li class="li1">
<div class="de1"><span class="br0">&#123;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; <span class="kw1">return</span> _isPlaying;</div>
</li>
<li class="li1">
<div class="de1"><span class="br0">&#125;</span></div>
</li>
<li class="li1">
<div class="de1"><span class="kw3">public</span> <span class="kw2">function</span> <span class="kw3">set</span> isPlaying<span class="br0">&#40;</span>isPlaying:<span class="kw3">Boolean</span><span class="br0">&#41;</span>:<span class="kw3">void</span></div>
</li>
<li class="li1">
<div class="de1"><span class="br0">&#123;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; _isPlaying = isPlaying</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; <span class="kw1">if</span> <span class="br0">&#40;</span>_isPlaying == <span class="kw2">true</span><span class="br0">&#41;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; <span class="br0">&#123;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; btPlay.<span class="kw3">setStyle</span><span class="br0">&#40;</span><span class="st0">&quot;upSkin&quot;</span>, _pauseIcon<span class="br0">&#41;</span>;</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; btPlay.<span class="kw3">setStyle</span><span class="br0">&#40;</span><span class="st0">&quot;overSkin&quot;</span>, _pauseIcon<span class="br0">&#41;</span>;</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; btPlay.<span class="kw3">setStyle</span><span class="br0">&#40;</span><span class="st0">&quot;downSkin&quot;</span>, _pauseIcon<span class="br0">&#41;</span>;</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; <span class="br0">&#125;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; <span class="kw1">else</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; <span class="br0">&#123;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; btPlay.<span class="kw3">setStyle</span><span class="br0">&#40;</span><span class="st0">&quot;upSkin&quot;</span>, _playIcon<span class="br0">&#41;</span>;</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; btPlay.<span class="kw3">setStyle</span><span class="br0">&#40;</span><span class="st0">&quot;overSkin&quot;</span>, _playIcon<span class="br0">&#41;</span>;</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; btPlay.<span class="kw3">setStyle</span><span class="br0">&#40;</span><span class="st0">&quot;downSkin&quot;</span>, _playIcon<span class="br0">&#41;</span>; </div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; <span class="br0">&#125;</span></div>
</li>
<li class="li1">
<div class="de1"><span class="br0">&#125;</span></div>
</li>
</ol>
</div>
<p>We are defining the public property isPlaying by using a setter method.  Using getter and setter methods are not required, but they are a best practice when creating custom components.  Here we have a private variable named _isPlaying.  When this variable changes, the icon for the btPlay button needs to change as well.  Using a setter method allows us to always run code that is associated with the property whenever the property changes.</p>
<p>To simulate a slideshow automatically playing, add the following line to the onInitialize function in SitePointTutorial.mxml:</p>
<div class="actionscript geshi no actionscript" style="font-family:monospace;">
<ol>
<li class="li1">
<div class="de1">mySlideshowNavigationBar.<span class="me1">isPlaying</span> = <span class="kw2">true</span>;</div>
</li>
</ol>
</div>
<p>Update the onPlayClick function in SitePointTutorial.mxml as so:</p>
<div class="actionscript geshi no actionscript" style="font-family:monospace;">
<ol>
<li class="li1">
<div class="de1"><span class="kw3">private</span> <span class="kw2">function</span> onPlayClick<span class="br0">&#40;</span>event:SlideshowNavigationBarEvent<span class="br0">&#41;</span>:<span class="kw3">void</span></div>
</li>
<li class="li1">
<div class="de1"><span class="br0">&#123;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; <span class="kw1">if</span> <span class="br0">&#40;</span>mySlideshowNavigationBar.<span class="me1">isPlaying</span> == <span class="kw2">true</span><span class="br0">&#41;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; <span class="br0">&#123;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; mySlideshowNavigationBar.<span class="me1">isPlaying</span> = <span class="kw2">false</span>;</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; myTextArea.<span class="kw3">htmlText</span> += <span class="st0">&quot;Pause slideshow.&lt;br&gt;&quot;</span>;</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; <span class="br0">&#125;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; <span class="kw1">else</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp;</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; <span class="br0">&#123;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; mySlideshowNavigationBar.<span class="me1">isPlaying</span> = <span class="kw2">true</span>;</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; myTextArea.<span class="kw3">htmlText</span> += <span class="st0">&quot;Play slideshow.&lt;br&gt;&quot;</span>;</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; <span class="br0">&#125;</span></div>
</li>
<li class="li1">
<div class="de1"><span class="br0">&#125;</span></div>
</li>
</ol>
</div>
<p>Now when you run the application, the dual function of the Play/Pause button will work.</p>
<p><a href="http://www.curiousfind.com/blog/wp-content/uploads/flex_article_7.png"><img class="alignnone size-full wp-image-58" title="flex_article_7" src="http://www.curiousfind.com/blog/wp-content/uploads/flex_article_7.png" alt="" width="500" height="511" /></a></p>
<p>I’ll leave it to you to implement the dual function of the Full Screen and Sound buttons.  You can run the <a href="http://www.curiousfind.com/tutorials/sitepointtutorial/SitePointTutorial.html">finished application</a> and <a href="http://www.curiousfind.com/tutorials/sitepointtutorial/srcview/index.html">view the full code</a>.</p>
<p>You can learn more about creating custom components in Adobe Flex by consulting the <a href="http://livedocs.adobe.com/flex/3/html/Part1_intro_1.html">official documentation</a>.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.curiousfind.com/blog/51/feed</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
	</channel>
</rss>
