<?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; utility</title>
	<atom:link href="http://kennethsutherland.com/tag/utility/feed/" rel="self" type="application/rss+xml" />
	<link>http://kennethsutherland.com</link>
	<description>Flex with a hint of cool</description>
	<lastBuildDate>Wed, 28 Sep 2011 14:12:28 +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>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>
	</channel>
</rss>

