<?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>Blue Flex &#187; tips</title>
	<atom:link href="http://kennethsutherland.com/category/tips/feed/" rel="self" type="application/rss+xml" />
	<link>http://kennethsutherland.com</link>
	<description>Flex with a hint of cool</description>
	<lastBuildDate>Wed, 18 Apr 2012 21:22:11 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.1.4</generator>
		<item>
		<title>iOS &#8211; Mobile dev, make sure you flush when you&#8217;re done.</title>
		<link>http://kennethsutherland.com/2011/09/07/ios-mobile-dev-make-sure-you-flush-when-youre-done/</link>
		<comments>http://kennethsutherland.com/2011/09/07/ios-mobile-dev-make-sure-you-flush-when-youre-done/#comments</comments>
		<pubDate>Wed, 07 Sep 2011 20:05:59 +0000</pubDate>
		<dc:creator>Kenneth</dc:creator>
				<category><![CDATA[Flex]]></category>
		<category><![CDATA[Flex 4]]></category>
		<category><![CDATA[mobile]]></category>
		<category><![CDATA[tips]]></category>
		<category><![CDATA[AIR]]></category>
		<category><![CDATA[iOS]]></category>

		<guid isPermaLink="false">http://kennethsutherland.com/?p=739</guid>
		<description><![CDATA[Developing for Apple&#8217;s devices can throw up a few little quirks that don&#8217;t happen when using Android devices. This one happens if you are using shared objects to store information between sessions. Basically, you should always call the flush mechanism whether you are adding more data to the shared object or if you are deleting [...]]]></description>
			<content:encoded><![CDATA[<p>Developing for Apple&#8217;s devices can throw up a few little quirks that don&#8217;t happen when using Android devices.</p>
<p>This one happens if you are using shared objects to store information between sessions.<br />
Basically, you should always call the flush mechanism whether you are adding more data to the shared object or if you are deleting something from the shared object.</p>
<p>What you find is if you have a shared object &#8216;shared&#8217; with a value shared.data.firstValue = &#8220;something&#8221;, then you delete that value using</p>

<div class="wp_syntax"><div class="code"><pre class="actionscript" style="font-family:monospace;"><span style="color: #0066CC;">delete</span> shared.<span style="color: #0066CC;">data</span>.<span style="color: #006600;">firstValue</span>;</pre></div></div>

<p> if you try to access the value firstValue you will get <em><strong>null</strong></em>.<br />
<em>This is exactly what I&#8217;d expect.</em></p>
<p>Then lets say you exit the app and you either kill the app from running in the background or iOS stops it. Then the next time you load the app and access the shared object shared.data.firstValue you will get back &#8220;something&#8221; and not null.</p>
<p><strong>You must flush the shared object for it to be stored locally, otherwise when the app is killed, the local storage will not have been updated.</strong></p>
<p style="text-align: center;"><script type="text/javascript"><!--
google_ad_client = "pub-7396620608505330";
google_ad_slot = "1277482570";
google_ad_width = 468;
google_ad_height = 60;
//--></script>
<script type="text/javascript" src="http://pagead2.googlesyndication.com/pagead/show_ads.js"></script>
</p>
]]></content:encoded>
			<wfw:commentRss>http://kennethsutherland.com/2011/09/07/ios-mobile-dev-make-sure-you-flush-when-youre-done/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Updating bindings when you only change a property inside an Object</title>
		<link>http://kennethsutherland.com/2011/08/30/updating-bindings-when-you-only-change-a-property-inside-an-object/</link>
		<comments>http://kennethsutherland.com/2011/08/30/updating-bindings-when-you-only-change-a-property-inside-an-object/#comments</comments>
		<pubDate>Tue, 30 Aug 2011 21:08:23 +0000</pubDate>
		<dc:creator>Kenneth</dc:creator>
				<category><![CDATA[actionscript]]></category>
		<category><![CDATA[Flex]]></category>
		<category><![CDATA[tips]]></category>
		<category><![CDATA[bindingManager]]></category>
		<category><![CDATA[Flex 3]]></category>
		<category><![CDATA[flex 4]]></category>

		<guid isPermaLink="false">http://kennethsutherland.com/?p=705</guid>
		<description><![CDATA[Its quite a common thing with Flex and actionscript projects to create an Object and inside that object it will have many properties.  Something in your view will be bound to the object so that the view changes with the object. So long as you change the entire object this will work fine. Where this [...]]]></description>
			<content:encoded><![CDATA[<p>Its quite a common thing with Flex and actionscript projects to create an Object and inside that object it will have many properties.  Something in your view will be bound to the object so that the view changes with the object. So long as you change the entire object this will work fine.</p>
<p>Where this doesn&#8217;t work is if you change a property inside the object.</p>
<p>So if we have something like this</p>

<div class="wp_syntax"><div class="code"><pre class="actionscript" style="font-family:monospace;"><span style="color: #66cc66;">&#91;</span>Bindable<span style="color: #66cc66;">&#93;</span>			
<span style="color: #0066CC;">private</span> <span style="color: #000000; font-weight: bold;">var</span> myObject : ObjectDataVO;
&nbsp;
<span style="color: #66cc66;">&lt;</span>view:SomeComponent
...
<span style="color: #0066CC;">data</span>=<span style="color: #ff0000;">&quot;{ myObject }&quot;</span>
...
<span style="color: #66cc66;">/&gt;</span></pre></div></div>

<p>When we set myObject to something the view component gets updated (great so far).<br />
Lets say the myObject has a property text and the view component uses this to display some visual label, then somewhere in the app I change that property, myObject.text = &#8220;something else&#8221;;<br />
The binding will not trigger as I haven&#8217;t actually changed the myObject, just a property inside it.</p>
<p>So how do we fire the binding manually? Well there is the <strong>BindingManager </strong>class (note this is an <em>excluded </em>class so you&#8217;ll not see it in the autocomplete ).<br />
So in this example if I changed the myObject.text property then I could call</p>
<p><span style="text-decoration: underline;"> BindingManager.executeBindings( this, &#8216;myObject.text&#8217;, myObject );</span></p>
<p>This would fire of the binding as if the actual myObject had changed so anything listening in will now get updated.</p>
<p style="text-align: center;"><script type="text/javascript"><!--
google_ad_client = "pub-7396620608505330";
google_ad_slot = "1277482570";
google_ad_width = 468;
google_ad_height = 60;
//--></script>
<script type="text/javascript" src="http://pagead2.googlesyndication.com/pagead/show_ads.js"></script>
</p>
]]></content:encoded>
			<wfw:commentRss>http://kennethsutherland.com/2011/08/30/updating-bindings-when-you-only-change-a-property-inside-an-object/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Additional compiler arguments &#8211; debug only code</title>
		<link>http://kennethsutherland.com/2011/01/07/additional-compiler-arguments-debug-only-code/</link>
		<comments>http://kennethsutherland.com/2011/01/07/additional-compiler-arguments-debug-only-code/#comments</comments>
		<pubDate>Fri, 07 Jan 2011 22:24:20 +0000</pubDate>
		<dc:creator>Kenneth</dc:creator>
				<category><![CDATA[actionscript]]></category>
		<category><![CDATA[Flex]]></category>
		<category><![CDATA[tips]]></category>

		<guid isPermaLink="false">http://kennethsutherland.com/?p=618</guid>
		<description><![CDATA[Inserting code that will be excluded depending on compiler arguments]]></description>
			<content:encoded><![CDATA[<p>Many times you look something up, do it once and think cool I&#8217;ll remember that as it&#8217;s simple.  Then 1 year later you&#8217;ve forgotten the syntax and you can&#8217;t find that help/blog page where you learned about it the first time.<br />
Well I needed to add in some debug code that would only be there for debugging, and the last thing I want to do when building a release version is to scan through the code to remove it. So the ideal way is to use a conditional compiler argument.</p>
<p>So in Flashbuilder, under the project properties and then the Flex compiler properties you&#8217;ll see something like this</p>
<div id="attachment_620" class="wp-caption aligncenter" style="width: 610px"><a href="http://kennethsutherland.com/wordpress1/wp-content/uploads/2011/01/compiler_args1.png"><img class="size-full wp-image-620" title="Compiler Arguments" src="http://kennethsutherland.com/wordpress1/wp-content/uploads/2011/01/compiler_args1.png" alt="Compiler Arguments" width="600" height="179" /></a><p class="wp-caption-text">Example for custom arguments</p></div>
<p>So if you had the following defined, -define=CONFIG::DEBUG,true -define+=CONFIG::SOMETHING_ELSE,false</p>
<p>Then in code you could do the following.</p>

<div class="wp_syntax"><div class="code"><pre class="actionscript3" style="font-family:monospace;">    CONFIG<span style="color: #000066; font-weight: bold;">::</span>DEBUG
    <span style="color: #0033ff; font-weight: bold;">private</span> <span style="color: #6699cc; font-weight: bold;">var</span> <span style="color: #004993;">test</span> <span style="color: #000066; font-weight: bold;">:</span> <span style="color: #004993;">Boolean</span><span style="color: #000066; font-weight: bold;">;</span>
&nbsp;
    CONFIG<span style="color: #000066; font-weight: bold;">::</span>SOMETHING_ELSE
    <span style="color: #0033ff; font-weight: bold;">private</span> <span style="color: #339966; font-weight: bold;">function</span> somethingElse<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span> <span style="color: #000066; font-weight: bold;">:</span> <span style="color: #0033ff; font-weight: bold;">void</span>
    <span style="color: #000000;">&#123;</span>
&nbsp;
    <span style="color: #000000;">&#125;</span></pre></div></div>

<p>The variable and function code will only be included if the compiler argument is true. So in the above example if you called the function &#8216;somethingElse()&#8217; then this would generate a build error as somethingElse() doesn&#8217;t exist. Change the argument to true and it will build fine.</p>
<p style="text-align: center;"><script type="text/javascript"><!--
google_ad_client = "pub-7396620608505330";
google_ad_slot = "1277482570";
google_ad_width = 468;
google_ad_height = 60;
//--></script>
<script type="text/javascript" src="http://pagead2.googlesyndication.com/pagead/show_ads.js"></script>
</p>
]]></content:encoded>
			<wfw:commentRss>http://kennethsutherland.com/2011/01/07/additional-compiler-arguments-debug-only-code/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Simple tip #4 (GOTCHA) &#8211; Datagrid borders</title>
		<link>http://kennethsutherland.com/2010/09/17/simple-tip-4-gotach-datagrid-borders/</link>
		<comments>http://kennethsutherland.com/2010/09/17/simple-tip-4-gotach-datagrid-borders/#comments</comments>
		<pubDate>Fri, 17 Sep 2010 09:10:58 +0000</pubDate>
		<dc:creator>Kenneth</dc:creator>
				<category><![CDATA[actionscript]]></category>
		<category><![CDATA[Flex]]></category>
		<category><![CDATA[tips]]></category>

		<guid isPermaLink="false">http://kennethsutherland.com/?p=594</guid>
		<description><![CDATA[simple tip on drawing borders around a Datagrid]]></description>
			<content:encoded><![CDATA[<p>More of a gotcha than a simple tip.</p>
<p>I was customising a DataGrid with various skin parts the other day (Flex 3) and could I get the borderskin to show, heck no! Its been a while since I had to create a DG from scratch so I&#8217;d obviously blacked out any previous pain with using the dammed DG.</p>
<p>Anyway why would the borderskin not show? I tried a simple solid border, nope. I tried a custom png graphic taken from Fireworks for the DG&#8217;s border, nope. I tried a programmatic skin border and guess what nope &#8211; nothing.  The issue was that I had the background alpha set to 1 (which is pretty normal!) and I had set the alternate row colours.</p>
<p>Setting the background alpha to something less than 1 revealed the border so I ended up fudging it by creating the programmatic skin border by whatever the borderThickness is outside the size of the DG.  <br />
So if the DG was meant to be 400px wide and borderThickness was 2, I made the DG 396px wide and drew the border outside that area.  This is what I&#8217;ve expect to happen automatically.</p>
<p>Can&#8217;t believe I&#8217;ve missed this/forgotten this before. Crappy DG.</p>
<table width="100%">
<tbody>
<tr>
<td>
<p style="text-align: left;"><a title="Simple tip #3" href="http://kennethsutherland.com/2009/06/12/simple-tip-3-utility-swc-library-project/" target="_self">Previous Tip<br />
</a></p>
</td>
<td>
<p style="text-align: right;">
<a title="Simple tip #5" href="http://kennethsutherland.com/2011/08/03/simple-tip-5-create-function-to-call-any-function-with-unknown-args/" target="_self">Next Tip<br />
</a>
</p>
</td>
</tr>
</tbody>
</table>
<p style="text-align: center;"><script type="text/javascript"><!--
google_ad_client = "pub-7396620608505330";
google_ad_slot = "1277482570";
google_ad_width = 468;
google_ad_height = 60;
//--></script>
<script type="text/javascript" src="http://pagead2.googlesyndication.com/pagead/show_ads.js"></script>
</p>
]]></content:encoded>
			<wfw:commentRss>http://kennethsutherland.com/2010/09/17/simple-tip-4-gotach-datagrid-borders/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Simple tip #2 &#8211; random colours</title>
		<link>http://kennethsutherland.com/2009/06/12/simple-tip-2-random-colours/</link>
		<comments>http://kennethsutherland.com/2009/06/12/simple-tip-2-random-colours/#comments</comments>
		<pubDate>Fri, 12 Jun 2009 08:12:23 +0000</pubDate>
		<dc:creator>Kenneth</dc:creator>
				<category><![CDATA[actionscript]]></category>
		<category><![CDATA[Flex]]></category>
		<category><![CDATA[tips]]></category>
		<category><![CDATA[colours]]></category>
		<category><![CDATA[random]]></category>
		<category><![CDATA[tip]]></category>
		<category><![CDATA[utility]]></category>

		<guid isPermaLink="false">http://kennethsutherland.com/?p=502</guid>
		<description><![CDATA[Their are so many times I&#8217;ve used a random colour in my apps (mainly for testing) that I thought I&#8217;d add this way of using a getter method with actionscript to simplify the process. First of if you haven&#8217;t got one already, create a uiltily class so features that you use regulary across projects (you [...]]]></description>
			<content:encoded><![CDATA[<p>Their are so many times I&#8217;ve used a random colour in my apps (mainly for testing) that I thought I&#8217;d add this way of using a getter method with actionscript to simplify the process.</p>
<p>First of if you haven&#8217;t got one already, create a uiltily class so features that you use regulary across projects (you could turn this file into a SWC and reference that in you various projects &#8211; now that I think about it I explain this as simple tip #3 <img src='http://kennethsutherland.com/wordpress1/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' />  )</p>
<p>So inside your utility class place the following code</p>

<div class="wp_syntax"><div class="code"><pre class="actionscript3" style="font-family:monospace;"><span style="color: #0033ff; font-weight: bold;">public</span> static <span style="color: #339966; font-weight: bold;">function</span> <span style="color: #0033ff; font-weight: bold;">get</span> randomColour<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span> <span style="color: #000066; font-weight: bold;">:</span> <span style="color: #004993;">uint</span> <span style="color: #000000;">&#123;</span>
	<span style="color: #0033ff; font-weight: bold;">return</span> <span style="color: #004993;">Math</span><span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">random</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span> <span style="color: #000066; font-weight: bold;">*</span> <span style="color: #004993;">uint</span><span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">MAX_VALUE</span><span style="color: #000066; font-weight: bold;">;</span>
<span style="color: #000000;">&#125;</span></pre></div></div>

<p>Then lets just say you require a random colour for anything just call Utility.randomColour, no brackets, no = signs.  Because you&#8217;ve set the function as a getter using the function name will be enough.  This method also means that you don&#8217;t need to remember the max/min values for a colour.  The uint min and max values are the same as the the min/max values for colours.</p>
<p>e.g.</p>

<div class="wp_syntax"><div class="code"><pre class="mxml" style="font-family:monospace;"><span style="color: #000000;"><span style="color: #7400FF;">&lt;mx:Canvas</span> backgroundColor=<span style="color: #ff0000;">&quot;{Utility.randomColour}&quot;</span></span>
<span style="color: #000000;">   width=<span style="color: #ff0000;">&quot;600&quot;</span></span>
<span style="color: #000000;">   height=<span style="color: #ff0000;">&quot;600&quot;</span><span style="color: #7400FF;">&gt;</span></span></pre></div></div>

<p>Utility is the name of the class that holds my utility functions.</p>
<table width="100%">
<tr>
<td>
<p style="text-align: left;">
<a title="Simple tip #1" href="http://kennethsutherland.com/2009/05/22/simple-tip-1-custom-events/" target="_self">Previous Tip<br />
</a>
</p>
</td>
<td>
<p style="text-align: right;">
<a title="Simple tip #3" href="http://kennethsutherland.com/2009/06/12/simple-tip-3-utility-swc-library-project/" target="_self">Next Tip<br />
</a>
</p>
</td>
</tr>
</table>
<p style="text-align: center;"><script type="text/javascript"><!--
google_ad_client = "pub-7396620608505330";
google_ad_slot = "1277482570";
google_ad_width = 468;
google_ad_height = 60;
//--></script>
<script type="text/javascript" src="http://pagead2.googlesyndication.com/pagead/show_ads.js"></script>
</p>
]]></content:encoded>
			<wfw:commentRss>http://kennethsutherland.com/2009/06/12/simple-tip-2-random-colours/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Simple tip #3 &#8211; Utility SWC (library project)</title>
		<link>http://kennethsutherland.com/2009/06/12/simple-tip-3-utility-swc-library-project/</link>
		<comments>http://kennethsutherland.com/2009/06/12/simple-tip-3-utility-swc-library-project/#comments</comments>
		<pubDate>Fri, 12 Jun 2009 08:12:08 +0000</pubDate>
		<dc:creator>Kenneth</dc:creator>
				<category><![CDATA[actionscript]]></category>
		<category><![CDATA[Flex]]></category>
		<category><![CDATA[tips]]></category>
		<category><![CDATA[AS3]]></category>
		<category><![CDATA[flex builder]]></category>
		<category><![CDATA[swc]]></category>
		<category><![CDATA[utility file]]></category>

		<guid isPermaLink="false">http://kennethsutherland.com/?p=509</guid>
		<description><![CDATA[Do you frequently use simple actionscript functions in more than one project. Perhaps you&#8217;ve got a function to do tracking, parse strings to dates, or return a random colour etc. I&#8217;m sure most folk will have struggled to think of what project they last used a generic function ABC in as they could do with [...]]]></description>
			<content:encoded><![CDATA[<p>Do you frequently use simple actionscript functions in more than one project. Perhaps you&#8217;ve got a function to do tracking, parse strings to dates, or return a random colour etc. </p>
<p>I&#8217;m sure most folk will have struggled to think of what project they last used a generic function ABC in as they could do with using it for project XYZ and would rather spend 30 mins searching for said function rather than rewrite it.</p>
<p>Well as explained below is a way to stop this from happening and hopefully save you a heap of time.</p>
<ul>
<li>
<h6>Step 1</h6>
<p> &#8211; Create a library project.</li>
<li>So using flexbuilder, go to File-&gt;New-&gt;Flex Library Project.</li>
<li>This will create an empty library project.</li>
</ul>
<ul>
<li>
<h6>Step 2</h6>
<p> &#8211; add in your Utilty class to the library project.</li>
<li>To do this add/create a Utility actionscript file that contains your static functions. Save, and this should then automaticlaly create a SWC file inside the library bin folder. (If it hasn&#8217;t and the file added has no errors then check the project properties to make sure the newly added file is being included &#8211; see pic)</li>
</ul>
<p><img class="aligncenter" title="Library path for adding files to SWC" src="/images/utility (Custom).JPG" alt="" width="600" height="185" /></p>
<ul>
<li>
<h6>Step 3</h6>
<p> &#8211; add the reference of the newly created SWC file to any project you intend to use it in.</li>
<li>So go to your project you wish to use the SWC with, then select the projects properties and inside &#8216;Flex build path&#8217; select &#8216;Add SWC&#8217;.</li>
<li>Browse to the the previous library project and select the SWC from its bin folder.</li>
</ul>
<p><img class="aligncenter" title="Adding a SWC to you project" src="/images/addSWC (Custom).JPG" alt="" width="600" height="222" /></p>
<p>You are now done, any time you update the code in the library project, those changes will be reflected in any project that references the SWC file automatically.</p>
<table width="100%">
<tr>
<td>
<p style="text-align: left;">
<a title="Simple tip #2" href="http://kennethsutherland.com/2009/06/12/simple-tip-2-random-colours/" target="_self">Previous Tip<br />
</a>
</p>
</td>
<td>
<p style="text-align: right;"><a title="Simple tip #4" href="http://kennethsutherland.com/2010/09/17/simple-tip-4-gotach-datagrid-borders/" target="_self">Next Tip<br />
</a>
</p>
</td>
</tr>
</table>
<p style="text-align: center;"><script type="text/javascript"><!--
google_ad_client = "pub-7396620608505330";
google_ad_slot = "1277482570";
google_ad_width = 468;
google_ad_height = 60;
//--></script>
<script type="text/javascript" src="http://pagead2.googlesyndication.com/pagead/show_ads.js"></script>
</p>
]]></content:encoded>
			<wfw:commentRss>http://kennethsutherland.com/2009/06/12/simple-tip-3-utility-swc-library-project/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Simple tip #1 &#8211; custom events</title>
		<link>http://kennethsutherland.com/2009/05/22/simple-tip-1-custom-events/</link>
		<comments>http://kennethsutherland.com/2009/05/22/simple-tip-1-custom-events/#comments</comments>
		<pubDate>Fri, 22 May 2009 13:13:41 +0000</pubDate>
		<dc:creator>Kenneth</dc:creator>
				<category><![CDATA[actionscript]]></category>
		<category><![CDATA[Flex]]></category>
		<category><![CDATA[tips]]></category>
		<category><![CDATA[actionscript 3]]></category>
		<category><![CDATA[custom events]]></category>
		<category><![CDATA[events]]></category>

		<guid isPermaLink="false">http://kennethsutherland.com/?p=332</guid>
		<description><![CDATA[Today while coding I was creating some classes that required them to dispatch custom events. I know that this is a fairly common thing to do but sometimes it is these little things that can trip you up or take a while to find out how to do them. So I thought that each time [...]]]></description>
			<content:encoded><![CDATA[<p>Today while coding I was creating some classes that required them to dispatch custom events. I know that this is a fairly common thing to do but sometimes it is these little things that can trip you up or take a while to find out how to do them.</p>
<p>So I thought that each time I come across something that is &#8216;simple&#8217; (only simple after you know it!) that I&#8217;ll try to create a quick blog entry and take note of it.  Each time I create a new &#8216;tip&#8217; post I&#8217;ll link it to the previous/next tip so that it will be quick and easy to browse through a load of tips.<br />
 </p>
<h4>Tip #1</h4>
<p>So for my first tip, this is how to implement your own custom events.</p>
<p>First if you are firing the events from a custom MXML file then you need to create a metadata tag. I make this the first node inside the MXML file.  For example:</p>
<p> </p>

<div class="wp_syntax"><div class="code"><pre class="mxml" style="font-family:monospace;"><span style="color: #000000;">&lt;?xml version=<span style="color: #ff0000;">&quot;1.0&quot;</span> encoding=<span style="color: #ff0000;">&quot;utf-8&quot;</span>?<span style="color: #7400FF;">&gt;</span></span>
<span style="color: #000000;"><span style="color: #7400FF;">&lt;mx:Canvas</span> xmlns:mx=<span style="color: #ff0000;">&quot;http://www.adobe.com/2006/mxml&quot;</span></span>
<span style="color: #000000;">		width=<span style="color: #ff0000;">&quot;500&quot;</span></span>
<span style="color: #000000;">		height=<span style="color: #ff0000;">&quot;300&quot;</span></span>
<span style="color: #000000;">		<span style="color: #7400FF;">&gt;</span></span>
&nbsp;
<span style="color: #000000;"><span style="color: #7400FF;">&lt;mx:Metadata</span><span style="color: #7400FF;">&gt;</span></span>
<span style="color: #000000;"><span style="color: #808080; font-style: italic;">&lt;!-- </span>
<span style="color: #000000;">First two event are plain string events, they do not pass any specific data with them --&gt;</span></span>
<span style="color: #000000;"><span style="color: #808080; font-style: italic;">&lt;!-- </span>
<span style="color: #000000;">The last event is a custom class that extends Event and as such you need to give</span>
<span style="color: #000000;">it its package name + the class name as the type --&gt;</span></span>
	[Event('next')]
	[Event('previous')]
	[Event(name='jump', type='com.kennethsutherland.events.JumpEvent')]
<span style="color: #000000;"><span style="color: #7400FF;">&lt;/mx:Metadata</span><span style="color: #7400FF;">&gt;</span></span>
...</pre></div></div>

<p>If your custom class is an AS3 file then you would put something like the following are the imports</p>

<div class="wp_syntax"><div class="code"><pre class="actionscript3" style="font-family:monospace;"><span style="color: #000000;">&#91;</span><span style="color: #004993;">Event</span><span style="color: #000000;">&#40;</span><span style="color: #004993;">name</span>=<span style="color: #990000;">&quot;previous&quot;</span><span style="color: #000066; font-weight: bold;">,</span> <span style="color: #004993;">type</span>=<span style="color: #990000;">&quot;flash.events.Event&quot;</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">&#93;</span>
<span style="color: #000000;">&#91;</span><span style="color: #004993;">Event</span><span style="color: #000000;">&#40;</span><span style="color: #004993;">name</span>=<span style="color: #990000;">'jump'</span><span style="color: #000066; font-weight: bold;">,</span> <span style="color: #004993;">type</span>=<span style="color: #990000;">'com.kennethsutherland.events.JumpEvent'</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">&#93;</span></pre></div></div>

<p>Then inside the MXML file (script block) or anywhere in the AS3 file to fire the event I&#8217;d do the following:<br />
 </p>

<div class="wp_syntax"><div class="code"><pre class="actionscript3" style="font-family:monospace;"><span style="color: #009900; font-style: italic;">//custom event, the extra value is handled by the JumpEvent class</span>
<span style="color: #004993;">dispatchEvent</span><span style="color: #000000;">&#40;</span><span style="color: #0033ff; font-weight: bold;">new</span> JumpEvent<span style="color: #000000;">&#40;</span><span style="color: #990000;">&quot;jump&quot;</span><span style="color: #000066; font-weight: bold;">,</span> specificValueForTheJumpEventClass<span style="color: #000000;">&#41;</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>
<span style="color: #009900; font-style: italic;">//standard event</span>
<span style="color: #004993;">dispatchEvent</span><span style="color: #000000;">&#40;</span><span style="color: #0033ff; font-weight: bold;">new</span> <span style="color: #004993;">Event</span><span style="color: #000000;">&#40;</span><span style="color: #990000;">&quot;next&quot;</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span></pre></div></div>

<p>If you do the above and lets just say your MXML/AS file is called &#8216;GreatComponent&#8217; then in order to use the new custom event, its as simple as the below bit of code. </p>

<div class="wp_syntax"><div class="code"><pre class="mxml" style="font-family:monospace;"><span style="color: #000000;"><span style="color: #7400FF;">&lt;local:GreatComponent</span></span>
<span style="color: #000000;">    next=<span style="color: #ff0000;">&quot;doSomething()&quot;</span></span>
<span style="color: #000000;">    jump=<span style="color: #ff0000;">&quot;doSomethingElse(event)&quot;</span></span>
<span style="color: #000000;"><span style="color: #7400FF;">/&gt;</span></span></pre></div></div>

<p>That&#8217;s it, now you can fire of any custom event that you wish and make sure that it gets listened to. </p>
<table width="100%">
<tr>
<td>
<p style="text-align: left;">
</td>
<td>
<p style="text-align: right;">
<a title="Simple tip #2" href="http://kennethsutherland.com/2009/06/12/simple-tip-2-random-colours/" target="_self">Next Tip<br />
</a>
</p>
</td>
</tr>
</table>
<p>  </p>
<p style="text-align: center;"><script type="text/javascript"><!--
google_ad_client = "pub-7396620608505330";
google_ad_slot = "1277482570";
google_ad_width = 468;
google_ad_height = 60;
//--></script>
<script type="text/javascript" src="http://pagead2.googlesyndication.com/pagead/show_ads.js"></script>
</p>
]]></content:encoded>
			<wfw:commentRss>http://kennethsutherland.com/2009/05/22/simple-tip-1-custom-events/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

