<?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; actionscript 3</title>
	<atom:link href="http://kennethsutherland.com/tag/actionscript-3/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>Show dual coloured highlight for a DG</title>
		<link>http://kennethsutherland.com/2009/06/11/show-dual-coloured-highlight-for-a-dg/</link>
		<comments>http://kennethsutherland.com/2009/06/11/show-dual-coloured-highlight-for-a-dg/#comments</comments>
		<pubDate>Thu, 11 Jun 2009 15:02:48 +0000</pubDate>
		<dc:creator>Kenneth</dc:creator>
				<category><![CDATA[actionscript]]></category>
		<category><![CDATA[Flex]]></category>
		<category><![CDATA[actionscript 3]]></category>
		<category><![CDATA[advanceddatagrid]]></category>
		<category><![CDATA[datagrid]]></category>
		<category><![CDATA[drawHighlightIndicator]]></category>

		<guid isPermaLink="false">http://kennethsutherland.com/?p=491</guid>
		<description><![CDATA[If you have a datagrid that has different coloured columns, then why should you have to do with only using a single colour for the highlight. Below is a simple soloution using actionscript to solve this. First I should state that you need to use the AdvancedDataGrid even if you only need a normal DataGrid. [...]]]></description>
			<content:encoded><![CDATA[<p>If you have a datagrid that has different coloured columns, then why should you have to do with only using a single colour for the highlight.</p>
<p>Below is a simple soloution using actionscript to solve this.</p>
<p>First I should state that you need to use the AdvancedDataGrid even if you only need a normal DataGrid.  This is because the AdvancedDataGrid has a method called drawHighlightIndicator(&#8230;), which as you&#8217;d expect from the name draws the highlight.  Normally this is a single colour, but with a little overriding you&#8217;ll be able to change this.</p>
<p>Below is the main snippet of code from the extended AdvancedDataGrid.</p>

<div class="wp_syntax"><div class="code"><pre class="actionscript3" style="font-family:monospace;">override <span style="color: #0033ff; font-weight: bold;">protected</span> <span style="color: #339966; font-weight: bold;">function</span> drawHighlightIndicator<span style="color: #000000;">&#40;</span>  indicator<span style="color: #000066; font-weight: bold;">:</span><span style="color: #004993;">Sprite</span><span style="color: #000066; font-weight: bold;">,</span> <span style="color: #004993;">x</span><span style="color: #000066; font-weight: bold;">:</span><span style="color: #004993;">Number</span><span style="color: #000066; font-weight: bold;">,</span> <span style="color: #004993;">y</span><span style="color: #000066; font-weight: bold;">:</span><span style="color: #004993;">Number</span><span style="color: #000066; font-weight: bold;">,</span>
	<span style="color: #004993;">width</span><span style="color: #000066; font-weight: bold;">:</span><span style="color: #004993;">Number</span><span style="color: #000066; font-weight: bold;">,</span> <span style="color: #004993;">height</span><span style="color: #000066; font-weight: bold;">:</span><span style="color: #004993;">Number</span><span style="color: #000066; font-weight: bold;">,</span> <span style="color: #004993;">color</span><span style="color: #000066; font-weight: bold;">:</span><span style="color: #004993;">uint</span><span style="color: #000066; font-weight: bold;">,</span>  itemRenderer<span style="color: #000066; font-weight: bold;">:</span>IListItemRenderer<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>
	<span style="color: #009900; font-style: italic;">//The indicator is the highlight, so grab its graphics and clear them</span>
	<span style="color: #6699cc; font-weight: bold;">var</span> g<span style="color: #000066; font-weight: bold;">:</span><span style="color: #004993;">Graphics</span> = <span style="color: #004993;">Sprite</span><span style="color: #000000;">&#40;</span>indicator<span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">graphics</span><span style="color: #000066; font-weight: bold;">;</span>
	g<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">clear</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>
&nbsp;
	<span style="color: #6699cc; font-weight: bold;">var</span> xPos <span style="color: #000066; font-weight: bold;">:</span> <span style="color: #004993;">Number</span> = <span style="color: #000000; font-weight:bold;">0</span><span style="color: #000066; font-weight: bold;">;</span>
	<span style="color: #6699cc; font-weight: bold;">var</span> yPos <span style="color: #000066; font-weight: bold;">:</span> <span style="color: #004993;">Number</span> = <span style="color: #000000; font-weight:bold;">0</span><span style="color: #000066; font-weight: bold;">;</span>
	<span style="color: #009900; font-style: italic;">//loop through the number of columns in the datagrid</span>
	<span style="color: #0033ff; font-weight: bold;">for</span><span style="color: #000000;">&#40;</span><span style="color: #6699cc; font-weight: bold;">var</span> i <span style="color: #000066; font-weight: bold;">:</span> <span style="color: #004993;">uint</span> = <span style="color: #000000; font-weight:bold;">0</span><span style="color: #000066; font-weight: bold;">;</span> i <span style="color: #000066; font-weight: bold;">&amp;</span>lt<span style="color: #000066; font-weight: bold;">;</span> <span style="color: #0033ff; font-weight: bold;">this</span><span style="color: #000066; font-weight: bold;">.</span>columnCount<span style="color: #000066; font-weight: bold;">;</span> i<span style="color: #000066; font-weight: bold;">++</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">&#123;</span>
		<span style="color: #009900; font-style: italic;">//get a random colour</span>
		g<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">beginFill</span><span style="color: #000000;">&#40;</span>randColour<span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>
		<span style="color: #009900; font-style: italic;">//draw the rectanlge that fills the first column</span>
		g<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">drawRect</span><span style="color: #000000;">&#40;</span>xPos<span style="color: #000066; font-weight: bold;">,</span> <span style="color: #004993;">y</span><span style="color: #000066; font-weight: bold;">,</span> <span style="color: #0033ff; font-weight: bold;">this</span><span style="color: #000066; font-weight: bold;">.</span>columns<span style="color: #000000;">&#91;</span>i<span style="color: #000000;">&#93;</span><span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">width</span><span style="color: #000066; font-weight: bold;">,</span> <span style="color: #004993;">height</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>
		<span style="color: #009900; font-style: italic;">//update the starting X position so that it starts at the begin of the</span>
		<span style="color: #009900; font-style: italic;">//next column</span>
		xPos = xPos <span style="color: #000066; font-weight: bold;">+</span> <span style="color: #0033ff; font-weight: bold;">this</span><span style="color: #000066; font-weight: bold;">.</span>columns<span style="color: #000000;">&#91;</span>i<span style="color: #000000;">&#93;</span><span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">width</span><span style="color: #000066; font-weight: bold;">;</span>
	<span style="color: #000000;">&#125;</span>
	g<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">endFill</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>
<span style="color: #000000;">&#125;</span></pre></div></div>

<p>using the above you could create a DataGrid like the below which has some left hand columns in light purple and the rest in white. Then on highlight that same light purple colour is used for the white cells and the existing light purple becomes a slightly darker purple.</p>
<p><img class="aligncenter" title="Twin DG colour example" src="/flex/june09/TwinHighlight/twinDGColour.JPG" alt="Twin DG colour example" width="389" height="175" /></p>
<p>Check out this <a title="Twin coloured DG highlight" href="http://www.kennethsutherland.com/flex/june09/TwinHighlight/demoTwinHighlight.html" target="_blank">link to see a very simple/colourful demo</a>. As ever right click app for full source code.</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/06/11/show-dual-coloured-highlight-for-a-dg/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Flex &amp; Version control</title>
		<link>http://kennethsutherland.com/2009/05/25/flex-version-control/</link>
		<comments>http://kennethsutherland.com/2009/05/25/flex-version-control/#comments</comments>
		<pubDate>Mon, 25 May 2009 10:38:08 +0000</pubDate>
		<dc:creator>Kenneth</dc:creator>
				<category><![CDATA[actionscript]]></category>
		<category><![CDATA[Flex]]></category>
		<category><![CDATA[actionscript 3]]></category>
		<category><![CDATA[debug]]></category>
		<category><![CDATA[swc]]></category>
		<category><![CDATA[version control]]></category>

		<guid isPermaLink="false">http://kennethsutherland.com/?p=356</guid>
		<description><![CDATA[Ever had a project where your client has some kind of odd/unusual caching issue with their servers that you have absoulutly zero control over? Well if you have (which I have had) then the following swc file may help you to diagnose the problem. Its a very simple swc file that you can place inside [...]]]></description>
			<content:encoded><![CDATA[<p>Ever had a project where your client has some kind of odd/unusual caching issue with their servers that you have absoulutly zero control over?</p>
<p>Well if you have (which I have had) then the following swc file may help you to diagnose the problem.  Its a very simple swc file that you can place inside your code and pass it a version number.  Next time you build your app and deploy it to your clients servers you can type &#8216;version&#8217; then whatever number you gave inside your code will appear inside an Alert box.</p>
<p>This has helped me sooooo many times, as after deploying some code, if they (client) appear to be seeing something different to what I&#8217;m seeing then I can get them to type &#8216;version&#8217; and if it&#8217;s the old version number I have to tell them to clear their cache &amp; wait for their internal servers to refresh (again I/they have no control over this), then a few hours later they will have the correct version.</p>
<p>So it just helps when you roll out a minor update and you say its fixed, then they come back and say that they can&#8217;t see the changes, you can then show that its the internal hardware and that they just have to wait to get the new swf.</p>
<p>As a little extra feature on the version SWC I&#8217;ve given it the ability to listen to your own functions should you wish.  It works by listening to the keypress event on the stage (so their is nothing visual to worry about).  By default the version number is shown by typing &#8216;version&#8217; when the app has focus.   If you wished it to do something else on a certain word or set of key presses (a-z, 0-9) then you would do the following:</p>

<div class="wp_syntax"><div class="code"><pre class="actionscript3" style="font-family:monospace;">&nbsp;
<span style="color: #009900; font-style: italic;">//There is a addKeyListenerFunction and a removeKeyListenerFunction</span>
addKeyListenerFunction<span style="color: #000000;">&#40;</span><span style="color: #990000;">'whateverSetOfKeyPressesYouWantToListenTo'</span><span style="color: #000066; font-weight: bold;">,</span> someFunction<span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>
<span style="color: #009900; font-style: italic;">//remove listener by passing in the word that you where listening for</span>
removeKeyListenerFunction<span style="color: #000000;">&#40;</span><span style="color: #990000;">'whateverSetOfKeyPressesYouWantToListenTo'</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span></pre></div></div>

<p><a title="SWC version file" href="http://www.kennethsutherland.com/flex/version/VersionExample.html" target="_blank">Click here for runnable demo, right click for source code.</a> (just make sure app has focus for it to work)</p>
<p>If you&#8217;re interested in file size, using the above example with and without the version SWC changed the file size by just under 3K (3057 bytes).</p>
<p>The version SWC is case insensitive, so if you ask it to listen to HELLOWORLD, this is the same as helloworld.</p>
<p>Get the <a title="SWC version file" href="http://www.kennethsutherland.com/flex/version/version.swc" target="_blank">SWC file here</a>.</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/25/flex-version-control/feed/</wfw:commentRss>
		<slash:comments>1</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>

