<?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 &#187; Flex</title>
	<atom:link href="http://www.curiousfind.com/blog/category/flex/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>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>3</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>6</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>
		<item>
		<title>Notes on learning Cairngorm</title>
		<link>http://www.curiousfind.com/blog/14</link>
		<comments>http://www.curiousfind.com/blog/14#comments</comments>
		<pubDate>Fri, 12 Sep 2008 18:23:14 +0000</pubDate>
		<dc:creator>Jamie McDaniel</dc:creator>
				<category><![CDATA[Cairngorm]]></category>

		<guid isPermaLink="false">http://www.curiousfind.com/blog/?p=14</guid>
		<description><![CDATA[Here is how I added Cairngorm to my skill-set (after first gaining enough Flex experience to understand why you would use an architectural framework).
David Tucker&#8217;s 5-Part Series
David&#8217;s excellent articles and accompanying videos are what I would highly recommend starting with.

 Getting Started with Cairngorm &#8211; Part 1
Getting Started with Cairngorm &#8211; Part 2
Getting Started with [...]]]></description>
			<content:encoded><![CDATA[<p>Here is how I added Cairngorm to my skill-set (after first gaining enough Flex experience to understand why you would use an architectural framework).</p>
<h3>David Tucker&#8217;s 5-Part Series</h3>
<p>David&#8217;s excellent articles and accompanying videos are what I would highly recommend starting with.</p>
<ul>
<li> <a href="http://www.davidtucker.net/2007/10/07/getting-started-with-cairngorm-%E2%80%93-part-1/">Getting Started with Cairngorm &#8211; Part 1</a></li>
<li><a href="http://www.davidtucker.net/2007/10/18/cairngorm-part-2/">Getting Started with Cairngorm &#8211; Part 2</a></li>
<li><a href="http://www.davidtucker.net/2007/10/29/cairngorm-part-3/">Getting Started with Cairngorm &#8211; Part 3</a></li>
<li><a href="http://www.davidtucker.net/2007/11/07/cairngorm-part-4/">Getting Started with Cairngorm &#8211; Part 4</a></li>
<li><a href="http://www.davidtucker.net/2007/11/30/getting-started-with-cairngorm-%E2%80%93-part-5/">Getting Started with Cairngorm &#8211; Part 5</a></li>
</ul>
<h3>CairngormStore Example</h3>
<p>Or rather <a href="http://www.brightworks.com/flex_ability/?p=61">Douglas McCarroll&#8217;s update</a> of Chen Bekor&#8217;s ModifiedCairngormStore.  Douglas updated it for Cairngorm 2.2.1 and Flex 3.</p>
<h3>10 Tips for Working with Cairngorm</h3>
<p>Jesse Warden&#8217;s <a href="http://jessewarden.com/2007/08/10-tips-for-working-with-cairngorm.html">10 Tips for Working with Cairngorm</a>.  Tip #10 about not having nested views dispatch CairngormEvents (but rather dispatch regular events &#8212; or your own custom events that extend the event class &#8212; to the main view which would then dispatch a CairngormEvent) is a best practice to keep in mind when studying the CairngormStore example.</p>
<h3>Adobe Consulting&#8217;s 6-Part Article</h3>
<p>Steven Webster and Leon Tanner of Adobe Consulting wrote <a href="http://www.adobe.com/devnet/flex/articles/cairngorm_pt1.html">Developing Flex RIAs with Cairngorm microarchitecture</a>. The article has a lot of really good information in it and uses the CairngormStore as an example (although you will want to get the updated CairngormStore from the link above).</p>
<p>Here are some nuggets I gleaned from the articles:</p>
<p><strong>Nugget #1</strong></p>
<blockquote><p>&#8230;resist the opportunity to scatter state all over your application as strings, numbers, Booleans, and all manner of other primitive objects. &#8230;we strongly advocate that the client hold the data &#8212; as state, model, or whatever you want to call it &#8212; as objects that have semantic meaning.</p></blockquote>
<p style="padding-left: 30px;">Source: <a href="http://www.adobe.com/devnet/flex/articles/cairngorm_pt2_04.html">part 2, page 4</a></p>
<p>The use of value objects (or data transfer objects) was brought up in other places and is not specific to Cairngorm.  Still, it is good stuff that bears repeating.</p>
<p><strong>Nugget #2</strong></p>
<blockquote><p>When you create components that rely upon client-side data, it is all too easy to create a direct reference to a Singleton model, such as <code>ShopModelLocator</code>. Indeed this is true throughout the application. We discourage this approach. Instead, consider passing the model and/or its properties down through a hierarchy of your view components, for a cleaner and more thoughtful solution.</p></blockquote>
<p style="padding-left: 30px;">Source: <a href="http://www.adobe.com/devnet/flex/articles/cairngorm_pt2_07.html">part 2, page 7</a></p>
<p>The goal is to make components more reusable. If you have components importing the modelLocator, using the <code>getInstance</code> method, and then binding directly to data in the Cairngorm modelLocator instance, then those components are coupled to your project and/or the Cairngorm framework.</p>
<p>The argument behind not using CairngormEvents other than in your main view (Jesse Warden&#8217;s tip #10 from above) is the same reasoning here &#8212; reusablity and loosely coupled components.  Ideally your components could be used outside of the Cairngorm framework.</p>
<p>The CairngormStore example follows this in some places, but not in others. In <code>Main.mxml</code>, for instance, a ProductVO is &#8220;injected&#8221; into the <code>selectedItem</code> attribute of the <code>&lt;details:ProductDetails&gt;</code> component. However other components, such as <code>ProductsAndCheckoutViewStack.mxml</code>, import the ModelLocator and use <code>ShopModelLocator.getInstance()</code>.</p>
<p>Regarding the CairngormStore and best practices, Alistair McLeod states in a <a href="http://weblogs.macromedia.com/amcleod/archives/2008/08/cairngorm_moved.html#c76304">comment on his blog</a> that &#8220;&#8230;you make a good point with CairngormStore &#8211; looking at the application now, it definitely does not advertise our best practices of building applications with Cairngorm, and that&#8217;s something else we want to rectify&#8230;&#8221;</p>
<p>I am still trying to fully understand best practices regarding reusability. There is a critique of Cairngorm (or rather a certain use of the Model Locator pattern) <a href="http://blog.iconara.net/2008/04/13/architectural-atrocities-part-x-cairngorms-model-locator-pattern/">here</a> where the author mentions some of this. Another blog post on Cairgorm with some discussion about the Model Locator and coupling components to it is <a href="http://www.jeffryhouser.com/index.cfm/2008/3/27/Learning-Cairngorm-Part-6-Dealing-with-the-Singleton">here</a>.</p>
<p>(And just when I thought I was beginning to understand reusability, I saw this <a href="http://www.onflex.org/ted/2008/08/creating-reusable-components-by-ben.php">session from 360Flex</a> about there being two &#8220;levels&#8221; of reusability &#8212; loosely-coupled components and polished, fit for cataloging/distribution components. The gist being that a truly reusable component takes a lot more time to do and involves such things as allowing css styling and programming default behaviors.)</p>
<p><strong>Nugget #3</strong></p>
<blockquote><p>Developers should always seek to extract these classes from the Cairngorm architecture. Pulling business logic out of  commands and encapsulating into classes is a classic implementation of <em>Extract  class</em> refactoring.</p></blockquote>
<p style="padding-left: 30px;">Source: <a href="http://www.adobe.com/devnet/flex/articles/cairngorm_pt4_05.html">part 4, page 5</a></p>
<p>This is in reference to the <code>AddProductToShoppingCartCommand</code> in CairngormStore. The execute function of this command class just calls a function on shoppingCart stored in the model locator.</p>
<div class="actionscript geshi no actionscript" style="font-family:monospace;">
<ol>
<li class="li1">
<div class="de1">ShopModelLocator.<span class="me1">getInstance</span><span class="br0">&#40;</span><span class="br0">&#41;</span>.<span class="me1">shoppingCart</span>.<span class="me1">addElement</span><span class="br0">&#40;</span>shoppingEvent.<span class="me1">product</span>, shoppingEvent.<span class="me1">quantity</span><span class="br0">&#41;</span>;</div>
</li>
</ol>
</div>
<p>Rather than have a lot of complex business logic associated with shopping cart behavior in the <code>AddProductToShoppingCartCommand</code> class, such business logic is encapsulated in a ShoppingCart class (which, in the CairngormStore example, was stored in the model folder.)</p>
<p><strong>Nugget #4</strong></p>
<blockquote><p>&#8230;you and your team will approach the addition of each and             every feature to a Cairngorm application in the same way. In short, you will             add an event to the controller, register it with a Command class, and implement             the Command class to do all the work. With this approach you can drive the             development of your application with feature after feature, in a consistent,             predictable manner that scales well.</p></blockquote>
<p style="padding-left: 30px;">Source: <a href="http://www.adobe.com/devnet/flex/articles/cairngorm_pt4_06.html">part 4, page 6</a></p>
<p>This is a good review of the flow in Cairngorm and the benefits of using an architectural framework.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.curiousfind.com/blog/14/feed</wfw:commentRss>
		<slash:comments>6</slash:comments>
		</item>
		<item>
		<title>Remote Object for both HTTPS and HTTP</title>
		<link>http://www.curiousfind.com/blog/10</link>
		<comments>http://www.curiousfind.com/blog/10#comments</comments>
		<pubDate>Wed, 11 Jun 2008 18:52:01 +0000</pubDate>
		<dc:creator>Jamie McDaniel</dc:creator>
				<category><![CDATA[Flex]]></category>

		<guid isPermaLink="false">http://www.curiousfind.com/blog/?p=10</guid>
		<description><![CDATA[One of my main Flex projects is a content management system.  It is continually being developed and is in production as my employer&#8217;s backend.  I hope to make it an even more usable CMS solution by making it where it can be deployed for other websites.
With that future goal in mind, I needed to revisit [...]]]></description>
			<content:encoded><![CDATA[<p>One of my main Flex projects is a content management system.  It is continually being developed and is in production as my employer&#8217;s backend.  I hope to make it an even more usable CMS solution by making it where it can be deployed for other websites.</p>
<p>With that future goal in mind, I needed to revisit my <code>services-config.xml</code> file.  I use AMFPHP and had previously hardcoded the endpoint.  We use SSL because the backend is used for more than just editing web pages.  So for it to work on another site, I would needed to edit the <code>services-config.xml</code> file and recompile.</p>
<p>I did a google search on <a href="http://www.google.com/search?q=services-config+secure">services-config secure</a> and found <a href="http://blog.crankybit.com/flex-remoting-over-ssl/">this page</a> which was very helpful. <a href="http://www.mikenimer.com/index.cfm/2007/1/10/Bye-bye-services">This page</a> was also an interesting read. Before reading these, I did not know you could use the tokens <code>{server.name}</code> and <code>{server.port}</code> in your <code>services-config.xml</code> file.</p>
<p>Here is my new <code>services-config.xml</code> file that will use SSL if the page is using SSL and regular HTTP if it is not.  I verified it was indeed using SSL with <a href="http://www.charlesproxy.com">Charles</a>.</p>
<div class="xml geshi no xml" style="font-family:monospace;">
<ol>
<li class="li1">
<div class="de1"><span class="sc3"><span class="re1">&lt;?xml</span> <span class="re0">version</span>=<span class="st0">&quot;1.0&quot;</span> <span class="re0">encoding</span>=<span class="st0">&quot;UTF-8&quot;</span><span class="re2">?&gt;</span></span></div>
</li>
<li class="li1">
<div class="de1"><span class="sc3"><span class="re1">&lt;services-config<span class="re2">&gt;</span></span></span></div>
</li>
<li class="li1">
<div class="de1">&nbsp;<span class="sc3"><span class="re1">&lt;services<span class="re2">&gt;</span></span></span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; <span class="sc3"><span class="re1">&lt;service</span> <span class="re0">id</span>=<span class="st0">&quot;amfphp-flashremoting-service&quot;</span> <span class="re0">class</span>=<span class="st0">&quot;flex.messaging.services.RemotingService&quot;</span> <span class="re0">messageTypes</span>=<span class="st0">&quot;flex.messaging.messages.RemotingMessage&quot;</span><span class="re2">&gt;</span></span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp;<span class="sc3"><span class="re1">&lt;default-channels<span class="re2">&gt;</span></span></span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; <span class="sc3"><span class="re1">&lt;channel</span> <span class="re0">ref</span>=<span class="st0">&quot;my-secure-amfphp&quot;</span><span class="re2">/&gt;</span></span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; <span class="sc3"><span class="re1">&lt;channel</span> <span class="re0">ref</span>=<span class="st0">&quot;my-amfphp&quot;</span><span class="re2">/&gt;</span></span> &nbsp; </div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp;<span class="sc3"><span class="re1">&lt;/default-channels<span class="re2">&gt;</span></span></span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp;<span class="sc3"><span class="re1">&lt;destination</span> <span class="re0">id</span>=<span class="st0">&quot;amfphp&quot;</span><span class="re2">&gt;</span></span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; <span class="sc3"><span class="re1">&lt;channels<span class="re2">&gt;</span></span></span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp;<span class="sc3"><span class="re1">&lt;channel</span> <span class="re0">ref</span>=<span class="st0">&quot;my-secure-amfphp&quot;</span><span class="re2">/&gt;</span></span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp;<span class="sc3"><span class="re1">&lt;channel</span> <span class="re0">ref</span>=<span class="st0">&quot;my-amfphp&quot;</span><span class="re2">/&gt;</span></span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; <span class="sc3"><span class="re1">&lt;/channels<span class="re2">&gt;</span></span></span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; <span class="sc3"><span class="re1">&lt;properties<span class="re2">&gt;</span></span></span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp;<span class="sc3"><span class="re1">&lt;source<span class="re2">&gt;</span></span></span>*<span class="sc3"><span class="re1">&lt;/source<span class="re2">&gt;</span></span></span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; <span class="sc3"><span class="re1">&lt;/properties<span class="re2">&gt;</span></span></span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp;<span class="sc3"><span class="re1">&lt;/destination<span class="re2">&gt;</span></span></span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; <span class="sc3"><span class="re1">&lt;/service<span class="re2">&gt;</span></span></span></div>
</li>
<li class="li1">
<div class="de1">&nbsp;<span class="sc3"><span class="re1">&lt;/services<span class="re2">&gt;</span></span></span></div>
</li>
<li class="li1">
<div class="de1">&nbsp;<span class="sc3"><span class="re1">&lt;channels<span class="re2">&gt;</span></span></span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; <span class="sc3"><span class="re1">&lt;channel-definition</span> <span class="re0">id</span>=<span class="st0">&quot;my-secure-amfphp&quot;</span> <span class="re0">class</span>=<span class="st0">&quot;mx.messaging.channels.SecureAMFChannel&quot;</span><span class="re2">&gt;</span></span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp;<span class="sc3"><span class="re1">&lt;endpoint</span> <span class="re0">uri</span>=<span class="st0">&quot;https://{server.name}:{server.port}/amfphp2/gateway.php&quot;</span> <span class="re0">class</span>=<span class="st0">&quot;flex.messaging.endpoints.SecureAMFEndpoint&quot;</span><span class="re2">/&gt;</span></span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp;<span class="sc3"><span class="re1">&lt;properties<span class="re2">&gt;</span></span></span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; <span class="sc3"><span class="re1">&lt;add-no-cache-headers<span class="re2">&gt;</span></span></span>false<span class="sc3"><span class="re1">&lt;/add-no-cache-headers<span class="re2">&gt;</span></span></span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; <span class="sc3"><span class="re1">&lt;polling-enabled<span class="re2">&gt;</span></span></span>false<span class="sc3"><span class="re1">&lt;/polling-enabled<span class="re2">&gt;</span></span></span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; <span class="sc3"><span class="re1">&lt;serialization<span class="re2">&gt;</span></span></span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp;<span class="sc3"><span class="re1">&lt;instantiate-types<span class="re2">&gt;</span></span></span>false<span class="sc3"><span class="re1">&lt;/instantiate-types<span class="re2">&gt;</span></span></span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; <span class="sc3"><span class="re1">&lt;/serialization<span class="re2">&gt;</span></span></span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp;<span class="sc3"><span class="re1">&lt;/properties<span class="re2">&gt;</span></span></span> &nbsp; </div>
</li>
<li class="li1">
<div class="de1">&nbsp; <span class="sc3"><span class="re1">&lt;/channel-definition<span class="re2">&gt;</span></span></span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; <span class="sc3"><span class="re1">&lt;channel-definition</span> <span class="re0">id</span>=<span class="st0">&quot;my-amfphp&quot;</span> <span class="re0">class</span>=<span class="st0">&quot;mx.messaging.channels.AMFChannel&quot;</span><span class="re2">&gt;</span></span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp;<span class="sc3"><span class="re1">&lt;endpoint</span> <span class="re0">uri</span>=<span class="st0">&quot;http://{server.name}:{server.port}/amfphp2/gateway.php&quot;</span> <span class="re0">class</span>=<span class="st0">&quot;flex.messaging.endpoints.AMFEndpoint&quot;</span><span class="re2">/&gt;</span></span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp;<span class="sc3"><span class="re1">&lt;properties<span class="re2">&gt;</span></span></span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; <span class="sc3"><span class="re1">&lt;add-no-cache-headers<span class="re2">&gt;</span></span></span>false<span class="sc3"><span class="re1">&lt;/add-no-cache-headers<span class="re2">&gt;</span></span></span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; <span class="sc3"><span class="re1">&lt;polling-enabled<span class="re2">&gt;</span></span></span>false<span class="sc3"><span class="re1">&lt;/polling-enabled<span class="re2">&gt;</span></span></span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; <span class="sc3"><span class="re1">&lt;serialization<span class="re2">&gt;</span></span></span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp;<span class="sc3"><span class="re1">&lt;instantiate-types<span class="re2">&gt;</span></span></span>false<span class="sc3"><span class="re1">&lt;/instantiate-types<span class="re2">&gt;</span></span></span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; <span class="sc3"><span class="re1">&lt;/serialization<span class="re2">&gt;</span></span></span> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp;<span class="sc3"><span class="re1">&lt;/properties<span class="re2">&gt;</span></span></span> &nbsp; </div>
</li>
<li class="li1">
<div class="de1">&nbsp; <span class="sc3"><span class="re1">&lt;/channel-definition<span class="re2">&gt;</span></span></span></div>
</li>
<li class="li1">
<div class="de1">&nbsp;<span class="sc3"><span class="re1">&lt;/channels<span class="re2">&gt;</span></span></span></div>
</li>
<li class="li1">
<div class="de1"><span class="sc3"><span class="re1">&lt;/services-config<span class="re2">&gt;</span></span></span></div>
</li>
</ol>
</div>
<p>The only problem with this solution is that when on an http page, the swf will try to access crossdomain.xml via https. On Firefox and IE this silently fails.  However on Safari (version 3.1.1 as of this writing) this causes the browser to stall indefinitely if you do not have a signed certificate. </p>
<p><img src="http://www.curiousfind.com/blog/wp-content/uploads/previewscreensnapz0011.jpg" alt="" title="previewscreensnapz0011" width="500" height="134" class="aligncenter size-full wp-image-12" /></p>
<p>Safari will not prompt you to accept the certificate, nor will it silently fail like the other browsers. Since my application is the backend for a CMS, I just went to the homepage via https and accepted the certificate permanently. However, that would not be a good solution for a public application.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.curiousfind.com/blog/10/feed</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>10 Google Map Mashups, Vote for the 1 Flex</title>
		<link>http://www.curiousfind.com/blog/8</link>
		<comments>http://www.curiousfind.com/blog/8#comments</comments>
		<pubDate>Tue, 06 May 2008 21:46:57 +0000</pubDate>
		<dc:creator>Jamie McDaniel</dc:creator>
				<category><![CDATA[Flex]]></category>

		<guid isPermaLink="false">http://www.curiousfind.com/blog/?p=8</guid>
		<description><![CDATA[Last month, Dice had a programming contest with a prize of $4,000.  My entry, using Flex, was selected as one of the ten finalists.  Go check out the 10 mashups and if you think mine is the best vote for Buried Treasure. Thank you!!  Here is the link to place your vote. Voting lasts until [...]]]></description>
			<content:encoded><![CDATA[<p>Last month, Dice had a programming contest with a prize of $4,000.  My entry, using Flex, was selected as one of the ten finalists.  Go check out the 10 mashups and <span style="text-decoration: line-through;">if you think mine is the best</span> vote for <strong>Buried Treasure</strong>. Thank you!!  Here is the <a href="http://career-resources.dice.com/tech_challenge/tech_chal_form.html">link to place your vote</a>. Voting lasts until May 31.</p>
<p style="text-align: center;"><a href="http://www.dice.com/ViewsFlash/servlet/viewsflash?cmd=showform&amp;pollid=Tech_Challenge!finalists1"><img class="size-medium wp-image-9" title="safariscreensnapz004" src="http://www.curiousfind.com/blog/wp-content/uploads/safariscreensnapz004-252x300.jpg" alt="Ten Radio Buttons for the poll. Vote for Buried Treasure." width="252" height="300" /></a></p>
<p>Also, I had a previous <a href="http://www.curiousfind.com/blog/3">blog post</a> on the challenges I ran into while creating my entry. If you are trying to put a Google Map inside a Flex application AND need Flex content to appear over the map, you&#8217;ll find it helpful.</p>
<p><strong>Update:</strong> I placed third.  The voting results are posted <a href="http://career-resources.dice.com/tech_challenge/tech_chal_form.html">here</a>.  I was quite surprised at the vote.  I thought I would finish first or second and the <a href="http://www.mapskrieg.com/view/">maps application</a> I thought would probably win ended up placing next to last.  I think that is the last of the contests for me.  Only paying clients going forward.  <img src='http://www.curiousfind.com/blog/wp-includes/images/smilies/icon_smile.gif' alt=':-)' class='wp-smiley' /> </p>
]]></content:encoded>
			<wfw:commentRss>http://www.curiousfind.com/blog/8/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>SitePoint Flex/AIR Contest</title>
		<link>http://www.curiousfind.com/blog/6</link>
		<comments>http://www.curiousfind.com/blog/6#comments</comments>
		<pubDate>Wed, 16 Apr 2008 21:21:45 +0000</pubDate>
		<dc:creator>Jamie McDaniel</dc:creator>
				<category><![CDATA[Flex]]></category>

		<guid isPermaLink="false">http://www.curiousfind.com/blog/?p=6</guid>
		<description><![CDATA[SitePoint puts outs free newsletters that I subscribe to.  I was glad to see AIR mentioned in a recent issue of their Tech Times. The email concluded with &#8220;You’ll certainly be seeing plenty more about Adobe AIR on SitePoint in the coming months.&#8221;  That is exciting news because generally I have gone to SitePoint for [...]]]></description>
			<content:encoded><![CDATA[<p>SitePoint puts outs free newsletters that I subscribe to.  I was glad to see AIR mentioned in a <a href="http://www.sitepoint.com/newsletter/viewissue.php?id=3&amp;issue=187&amp;format=html#7">recent issue</a> of their <em>Tech Times</em>. The email concluded with &#8220;You’ll certainly be seeing plenty more about Adobe AIR on SitePoint in the coming months.&#8221;  That is exciting news because generally I have gone to SitePoint for PHP, MySQL, and web hosting information but elsewhere for all things Flash.</p>
<p>When I went to SitePoint a few days ago, I saw that they also had <a href="http://www.sitepoint.com/blogs/2008/04/08/write-for-sitepoint-and-win-the-adobe-cs3-web-premium-suite/">two contests</a> going &#8211; one for the best Flex article and the second for the best AIR article.  I spent last weekend creating my entry for the Flex contest.  Wish me luck!</p>
<p><strong>Update:</strong> I was runner-up and got a PDF book.  See <a href="http://www.sitepoint.com/blogs/2008/05/26/adobe-flexair-article-competition-and-the-winners-are/">here</a>.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.curiousfind.com/blog/6/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Dice Programming Challenge</title>
		<link>http://www.curiousfind.com/blog/3</link>
		<comments>http://www.curiousfind.com/blog/3#comments</comments>
		<pubDate>Fri, 11 Apr 2008 15:16:54 +0000</pubDate>
		<dc:creator>Jamie McDaniel</dc:creator>
				<category><![CDATA[Flex]]></category>

		<guid isPermaLink="false">http://www.curiousfind.com/blog/?p=3</guid>
		<description><![CDATA[I received an email on Friday, March 27 about the Dice Programming Challenge.  (My inbox shows that I received the same email on the 19th, but I must have missed it.)  Anyway, the email stated &#8220;Show off your web-based application skills! Build a Google Maps mashup and you could win $4,000.&#8221;  I had used the [...]]]></description>
			<content:encoded><![CDATA[<p>I received an email on Friday, March 27 about the Dice Programming Challenge.  (My inbox shows that I received the same email on the 19th, but I must have missed it.)  Anyway, the email stated &#8220;Show off your web-based application skills! Build a Google Maps mashup and you could win $4,000.&#8221;  I had used the Yahoo! maps Flash component before, but I had never used Google Maps in an application.  The contest deadline was March 31.  On Saturday morning, I decided to put my whole weekend into creating an entry for the contest using Flex.</p>
<p>I first read about Google&#8217;s <a href="http://www.searchmash.com/flash/search/#q=maps:lexington%2C+ky">searchmash</a> site in a blog post at <a href="http://www.riapedia.com/2007/10/26/google_launches_flex_application_searchmash">RIApedia</a>. I had used an iframe before inside of a Flex application, but what I was really impressed with was how Google got Flex content to appear on top of their maps (notice the More combobox at the top and the Recent Searches slideout on the left.)  Previously I had always had to hide the iframe when showing an alert or popup window.</p>
<p>I used Firebug to peak at what they were doing.  For starters, they were using wmode = transparent. But the real trick was they were changing the z-index of the iframe from 300 to 100 whenever the Flex content needed to appear on top of the map. The flash stays at a z-index of 200, and as you know, containers with the higher z-index appear on top of containers with a lower z-index.</p>
<p>With that knowledge, I put together <a href="http://www.curiousfind.com/dice/flex.php">this application</a>.</p>
<p style="text-align: center;"><a href="http://www.curiousfind.com/dice/flex.php"><img class="aligncenter size-full wp-image-5" title="firefoxscreensnapz001" src="http://www.curiousfind.com/blog/wp-content/uploads/firefoxscreensnapz001.jpg" alt="Pirate Treasure Map Application build with Flex" width="424" height="290" /></a></p>
<p>The contest finalists won&#8217;t be announced until a few weeks and then dice members get to vote for the winner.</p>
<p>I had to overcome a few challenges in the three days I had to get my entry finished, so I thought I would document them here.</p>
<p>The first problem was my Flex application could not get the Geocoding data from Google using an HTTPService.  The problem was that Google did not have the necessary crossdomain.xml file in place. I found a solution on the web &#8211; use PHP to create a proxy on your server with <a href="http://www.php.net/curl">curl</a>. Then specify the url of the HTTPService as the proxy php file. The proxy just passes the XML from Google to the flash file.</p>
<p>Another obstacle was that Internet Explorer 7 (running under Parallels) would, about half the time, not show the Google map in the iframe.  Firefox 3 would display it fine every time. What was going on?  I had used <a href="http://www.deitte.com/archives/2006/08/finally_updated.htm">this component</a> for handling the iframe. You specify the url for the iframe in Flex and it passes it to the wrapper.  Apparently, that was a problem for how I had used Google maps.  When I hardcoded the url for the iframe in the wrapper, the problem in IE7 went away. With a deadline fast approaching, I didn&#8217;t dig too deep to find a more robust solution.</p>
<p>With just a few hours before midnight on March 31, I tested the application in Firefox 2 on Windows. And that is when a huge bug surfaced. The Flex application in Firefox on Windows would not respond to any mouse click that appeared over the iframe! A user could not get past the introductory popup message.</p>
<p>After doing several searches, I found a <a href="http://snook.ca/archives/other/hit_bug_in_fire/">blog post</a> that mentioned the issue. They had discovered that their flash movie does actually respond to the mouse click, but that the hit area is way off.  Sure enough, when I clicked about 50 pixels south of the button, it responded.</p>
<p>The solution that worked for me evolved from <a href="http://snook.ca/archives/other/hit_bug_in_fire/#c48366">this comment</a>. I created a secondary iframe with a width and height of 100%, a position of absolute, and a z-index of 101.</p>
<p><strong>Update 5/15/2008:</strong> Good news! The need for all this iframe z-index trickery is obsolete now.  Google just released their <a href="http://code.google.com/apis/maps/documentation/flash/">Google Maps API for Flash</a>.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.curiousfind.com/blog/3/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
