<?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>Fri, 30 Apr 2010 11:17:21 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0.1</generator>
		<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[Flex]]></category>
		<category><![CDATA[actionscript]]></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: #000000; 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: #004993;">random</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span> <span style="color: #000000; font-weight: bold;">*</span> <span style="color: #004993;">uint</span>.<span style="color: #004993;">MAX_VALUE</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[Flex]]></category>
		<category><![CDATA[actionscript]]></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;">
</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[Flex]]></category>
		<category><![CDATA[actionscript]]></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: #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: #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;">//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>, specificValueForTheJumpEventClass<span style="color: #000000;">&#41;</span><span style="color: #000000;">&#41;</span>;
<span style="color: #009900;">//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>;</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>
