<?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</title>
	<atom:link href="http://kennethsutherland.com/tag/actionscript/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>Searching a string &#8211; do you need to start with a period?</title>
		<link>http://kennethsutherland.com/2012/04/18/searching-a-string-do-you-need-to-start-with-a-period/</link>
		<comments>http://kennethsutherland.com/2012/04/18/searching-a-string-do-you-need-to-start-with-a-period/#comments</comments>
		<pubDate>Wed, 18 Apr 2012 21:20:09 +0000</pubDate>
		<dc:creator>Kenneth</dc:creator>
				<category><![CDATA[actionscript]]></category>
		<category><![CDATA[Flex]]></category>
		<category><![CDATA[period]]></category>
		<category><![CDATA[search]]></category>
		<category><![CDATA[string]]></category>

		<guid isPermaLink="false">http://kennethsutherland.com/?p=817</guid>
		<description><![CDATA[Today I had to write some code to search for text that matched various file extensions, this should have been a no brainer of a task. But like some things that sound stupidly simple it caught me out. If you have a string and you use the search method then when it finds something it [...]]]></description>
			<content:encoded><![CDATA[<p>Today I had to write some code to search for text that matched various file extensions, this should have been a <em>no brainer</em> of a task. But like some things that sound stupidly simple it caught me out.</p>
<p>If you have a string and you use the search method then when it finds something it will return the position. If it doesn&#8217;t then it will return -1. So far so good.</p>
<p>Now I could go into huge detail (I did, but it ended up to wordy/dull, so I just deleted it!).<br />
So if you <strong>EVER </strong>have to search for a string and your string starts with a period &#8216;.&#8217; then add a double backslash &#8216;\\&#8217;.<br />
If you don&#8217;t then the period will match anything! e.g. you want to match &#8216;.ra&#8217; and the string contains the word brain then &#8216;brain&#8217;.search( &#8216;.ra&#8217; )<strong> DOES NOT</strong> return -1!</p>
<p>use &#8216;\\.ra&#8217; for correct results.</p>
<p>Not sure why &#8216;.ra&#8217; doesn&#8217;t work, maybe it&#8217;s treating the string like a regEx, I know search can take both a string and a regEx so maybe its not looking at its type and guessing that it should be a regEx?? You can&#8217;t step into the code either to see why, so just use the \\</p>
<p>Very annoying!</p>
<table width="100%">
<tr>
<td>
<p style="text-align: left;">
<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">Previous Tip<br />
</a>
</p>
</td>
<td>
<p style="text-align: right;">
<p></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/2012/04/18/searching-a-string-do-you-need-to-start-with-a-period/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>Linear and Radial gradients &#8211; visually explained</title>
		<link>http://kennethsutherland.com/2011/02/24/linear-and-radial-gradients-visually-explained/</link>
		<comments>http://kennethsutherland.com/2011/02/24/linear-and-radial-gradients-visually-explained/#comments</comments>
		<pubDate>Thu, 24 Feb 2011 15:53:17 +0000</pubDate>
		<dc:creator>Kenneth</dc:creator>
				<category><![CDATA[Flex]]></category>
		<category><![CDATA[Flex 4]]></category>
		<category><![CDATA[actionscript]]></category>
		<category><![CDATA[explorer]]></category>
		<category><![CDATA[flex 4]]></category>
		<category><![CDATA[gradient]]></category>
		<category><![CDATA[linear]]></category>
		<category><![CDATA[radial]]></category>

		<guid isPermaLink="false">http://kennethsutherland.com/?p=633</guid>
		<description><![CDATA[I was playing around with some code recently (Flex 4 code) and I went to create a simple background and not having Catalyst or similar to output a fxg file I went to create my own gradients with some code. After a couple of goes and not getting anything resembeling what I expect I decided [...]]]></description>
			<content:encoded><![CDATA[<p>I was playing around with some code recently (Flex 4 code) and I went to create a simple background and not having Catalyst or similar to output a fxg file I went to create my own gradients with some code. After a couple of goes and not getting anything resembeling what I expect I decided to write a quick explorer.</p>
<p>I&#8217;ve done something similar ages ago with flex 3, so I thought I&#8217;d do this with flex 4 and perhaps look to expand it as an example of reskining an app with different skins. (source code may follow when I do this)  So here is the first step. A simple explorer to help understand the values that are used to make a Linear or Radial gradient along with the entries that make the look how they look.</p>
<p>I think it should be self explanatory, but if not just post a comment.</p>
<p>Follow the <a title="Flex 4, gradients explorer" href="http://www.kennethsutherland.com/flex/graphic_flex_4/GradientFlex4.html" target="_newtab">link to open the explorer</a>.</p>
<p><a href="http://www.kennethsutherland.com/flex/graphic_flex_4/GradientFlex4.html" target="_newtab" ><img class="aligncenter size-full wp-image-654" title="Explorer screenshot" src="http://kennethsutherland.com/wordpress1/wp-content/uploads/2011/02/flex4Gradient1.png" alt="Explorer screenshot" width="431" height="378" /></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/2011/02/24/linear-and-radial-gradients-visually-explained/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Doom and gloom or a new beginning</title>
		<link>http://kennethsutherland.com/2009/06/23/doom-and-gloom-or-a-new-beginning/</link>
		<comments>http://kennethsutherland.com/2009/06/23/doom-and-gloom-or-a-new-beginning/#comments</comments>
		<pubDate>Tue, 23 Jun 2009 14:52:33 +0000</pubDate>
		<dc:creator>Kenneth</dc:creator>
				<category><![CDATA[actionscript]]></category>
		<category><![CDATA[Flex]]></category>
		<category><![CDATA[adobe]]></category>
		<category><![CDATA[contractor]]></category>
		<category><![CDATA[work]]></category>

		<guid isPermaLink="false">http://kennethsutherland.com/?p=537</guid>
		<description><![CDATA[Redundancy… world shrinking economy… depression… company cutbacks… is this a bleak time or is it a time to make and face new challenges in the RIA world (particularly in the Flex and Actionscript areas)? Well after the unfortunate news that the company I work for are no longer wishing to partake in the RIA party [...]]]></description>
			<content:encoded><![CDATA[<p>Redundancy… world shrinking economy… depression… company cutbacks… is this a bleak time or is it a time to make and face new challenges in the RIA world (particularly in the Flex and Actionscript areas)?</p>
<p>Well after the unfortunate news that the company I work for are no longer wishing to partake in the RIA party that&#8217;s changing the way we look at and use the web/desktop and hence are making myself redundant. I&#8217;m looking at this as a great opportunity to expand my knowledge so that I can work with as many forward thinking companies as possible that deal with Flex/Actionscript/AIR or for that matter any RIA technology.<br />
Also I should now have more time to create and sell my own components, of which I had a cracking idea this morning (more on this later hopefully).</p>
<p>Hect I’ll event look at Silverlight or JavaFX <img src='http://kennethsutherland.com/wordpress1/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' />  if I get the time or the chance. So anyone out there fancy taking on a new contractor with 4 years+ experience in Flex as well as a bunch of other languages I’ve used along the way before I even heard of Flex.</p>
<p>Feel free to contact me at this address.<br />

<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000"
			id="fm_Contact_59422588"
			class="flashmovie"
			width="300"
			height="50">
	<param name="movie" value="/flex/contact/Contact.swf" />
	<!--[if !IE]>-->
	<object	type="application/x-shockwave-flash"
			data="/flex/contact/Contact.swf"
			name="fm_Contact_59422588"
			width="300"
			height="50">
	<!--<![endif]-->
		
<p><a href="http://adobe.com/go/getflashplayer"><img src="http://www.adobe.com/images/shared/download_buttons/get_flash_player.gif" alt="Get Adobe Flash player" /></a></p>

	<!--[if !IE]>-->
	</object>
	<!--<![endif]-->
</object>
<p>I’m going to continue to post hints and tips on anything I do as well as posting any new components so watch this space and feel free to contact me if you need any work done in the UK, remote working is always an option as well.</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/23/doom-and-gloom-or-a-new-beginning/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>FormItem, adding an icon</title>
		<link>http://kennethsutherland.com/2009/05/27/formitem-adding-an-icon/</link>
		<comments>http://kennethsutherland.com/2009/05/27/formitem-adding-an-icon/#comments</comments>
		<pubDate>Wed, 27 May 2009 13:07:13 +0000</pubDate>
		<dc:creator>Kenneth</dc:creator>
				<category><![CDATA[actionscript]]></category>
		<category><![CDATA[Flex]]></category>
		<category><![CDATA[extend]]></category>
		<category><![CDATA[form]]></category>
		<category><![CDATA[formItem]]></category>
		<category><![CDATA[image]]></category>
		<category><![CDATA[override]]></category>

		<guid isPermaLink="false">http://kennethsutherland.com/?p=425</guid>
		<description><![CDATA[Adding an icon to a form item is (yet another) one of those really annoying things in flex. I&#8217;m sure its something that loads of people wish to do but you can&#8217;t. Well just to see if I could, I set about and extended the FormItem class so that I could add an image/icon. After [...]]]></description>
			<content:encoded><![CDATA[<p>Adding an icon to a form item is (yet another) one of those really annoying things in flex.  I&#8217;m sure its something that loads of people wish to do but you can&#8217;t.</p>
<p>Well just to see if I could, I set about and extended the FormItem class so that I could add an image/icon.</p>
<p>After a quick look at the source code of the FormItem you can see that it only has two children. One, the label and two, the indicator.  So if you do wish to add anything else you&#8217;re going to have to extend the FormItem.</p>
<p>Thankfully the FormItem is based on the Container which makes adding anything fairly straight forward. I prefer to do any extending in actionscript but you could do the below in MXML with a bit of actionscript code at the same time.</p>
<p>There are 3 steps you need to make.</p>
<ol>
<li>Override the createChildren method</li>
<li>Set the image source</li>
<li>Override the label</li>
</ol>
<h4>Override the createChildren</h4>

<div class="wp_syntax"><div class="code"><pre class="actionscript3" style="font-family:monospace;"><span style="color: #0033ff; font-weight: bold;">protected</span> override <span style="color: #339966; font-weight: bold;">function</span> createChildren<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>
    <span style="color: #0033ff; font-weight: bold;">super</span><span style="color: #000066; font-weight: bold;">.</span>createChildren<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>
    <span style="color: #009900; font-style: italic;">//you could move the image creation into a seperate function when and if the imagesource has been set</span>
	<span style="color: #009900; font-style: italic;">//but for this example I've kept it simple.</span>
	<span style="color: #0033ff; font-weight: bold;">this</span><span style="color: #000066; font-weight: bold;">.</span>image = <span style="color: #0033ff; font-weight: bold;">new</span> Image<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>
	image<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">width</span> = <span style="color: #000000; font-weight:bold;">16</span><span style="color: #000066; font-weight: bold;">;</span>
	image<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">height</span> = <span style="color: #000000; font-weight:bold;">16</span><span style="color: #000066; font-weight: bold;">;</span>
	<span style="color: #009900; font-style: italic;">//again I've hardcoded these values for simplicity</span>
	<span style="color: #009900; font-style: italic;">//You could if you wanted to create a versitile custom component load these values in from a CSS file</span>
	image<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">setStyle</span><span style="color: #000000;">&#40;</span><span style="color: #990000;">'verticalCenter'</span><span style="color: #000066; font-weight: bold;">,</span> <span style="color: #000000; font-weight:bold;">0</span> <span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>
	image<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">setStyle</span><span style="color: #000000;">&#40;</span><span style="color: #990000;">'left'</span><span style="color: #000066; font-weight: bold;">,</span> <span style="color: #000000; font-weight:bold;">5</span> <span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>
	image<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">source</span> = _imageSource<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>rawChildren<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">addChild</span><span style="color: #000000;">&#40;</span>image<span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>
	<span style="color: #009900; font-style: italic;">//bind the string property to the image source property.</span>
	BindingUtils<span style="color: #000066; font-weight: bold;">.</span>bindProperty<span style="color: #000000;">&#40;</span>image<span style="color: #000066; font-weight: bold;">,</span> <span style="color: #990000;">'source'</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> <span style="color: #990000;">'imageSource'</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>from the above code you&#8217;ll see that all I&#8217;ve done is create an image, set its various properties and add it to the form.</p>
<p>most of this could and probably should be moved to a separate function (but for this demo I haven&#8217;t) so that you only add the image if it is actually required.  Also the style settings should come from a CSS file but for simplicity of the demo I haven&#8217;t done this.</p>
<h4>Set the image source</h4>

<div class="wp_syntax"><div class="code"><pre class="actionscript3" style="font-family:monospace;"><span style="color: #0033ff; font-weight: bold;">private</span> <span style="color: #6699cc; font-weight: bold;">var</span> _imageSource <span style="color: #000066; font-weight: bold;">:</span> <span style="color: #004993;">String</span> = <span style="color: #990000;">''</span><span style="color: #000066; font-weight: bold;">;</span>
&nbsp;
<span style="color: #000000;">&#91;</span>Bindable<span style="color: #000000;">&#93;</span>
<span style="color: #0033ff; font-weight: bold;">public</span> <span style="color: #339966; font-weight: bold;">function</span> <span style="color: #0033ff; font-weight: bold;">get</span> imageSource<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span> <span style="color: #000066; font-weight: bold;">:</span> <span style="color: #004993;">String</span> <span style="color: #000000;">&#123;</span>
	<span style="color: #0033ff; font-weight: bold;">return</span> _imageSource<span style="color: #000066; font-weight: bold;">;</span>
<span style="color: #000000;">&#125;</span> 
&nbsp;
<span style="color: #009900; font-style: italic;">//Sets the imageSource and I've added a number of spaces at the start to offset the </span>
<span style="color: #009900; font-style: italic;">//width of the image.</span>
<span style="color: #009900; font-style: italic;">//The overall form width will be calculated from the width of the label (this is done inside the FormItem) </span>
<span style="color: #0033ff; font-weight: bold;">public</span> <span style="color: #339966; font-weight: bold;">function</span> <span style="color: #0033ff; font-weight: bold;">set</span> imageSource<span style="color: #000000;">&#40;</span>str <span style="color: #000066; font-weight: bold;">:</span> <span style="color: #004993;">String</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>
  _imageSource = str<span style="color: #000066; font-weight: bold;">;</span>
  <span style="color: #0033ff; font-weight: bold;">if</span><span style="color: #000000;">&#40;</span>_imageSource<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">length</span> <span style="color: #000066; font-weight: bold;">&gt;</span> <span style="color: #000000; font-weight:bold;">0</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">&#123;</span><span style="color: #009900; font-style: italic;">//setting the label (not using _label) will resize the form/formItems</span>
  <span style="color: #009900; font-style: italic;">//add spaces to the trimed version to make sure you don't end up with 100's of spaces at the start.</span>
	label = <span style="color: #990000;">&quot;   &quot;</span> <span style="color: #000066; font-weight: bold;">+</span> StringUtil<span style="color: #000066; font-weight: bold;">.</span>trim<span style="color: #000000;">&#40;</span>_label<span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>
  <span style="color: #000000;">&#125;</span> <span style="color: #0033ff; font-weight: bold;">else</span> <span style="color: #000000;">&#123;</span>
	label = StringUtil<span style="color: #000066; font-weight: bold;">.</span>trim<span style="color: #000000;">&#40;</span>_label<span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>
  <span style="color: #000000;">&#125;</span>
<span style="color: #000000;">&#125;</span></pre></div></div>

<p>In the above code you can see that I set the variable _imageSource (which bound to the images source &#8211; see first snippet of code).  If the source is not &#8220;&#8221; then I add spaces to the label, make sure you set label and not _label.  This makes sure that the label width gets recalcualted.</p>
<h4>Override the label</h4>

<div class="wp_syntax"><div class="code"><pre class="actionscript3" style="font-family:monospace;"><span style="color: #009900; font-style: italic;">//Sets the label.</span>
<span style="color: #009900; font-style: italic;">//If the imageSource has been set already then this will add spaces to the label</span>
<span style="color: #0033ff; font-weight: bold;">public</span> override <span style="color: #339966; font-weight: bold;">function</span> <span style="color: #0033ff; font-weight: bold;">set</span> label<span style="color: #000000;">&#40;</span>str <span style="color: #000066; font-weight: bold;">:</span> <span style="color: #004993;">String</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>
  _label = str<span style="color: #000066; font-weight: bold;">;</span>
  <span style="color: #0033ff; font-weight: bold;">if</span><span style="color: #000000;">&#40;</span>_imageSource<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">length</span> <span style="color: #000066; font-weight: bold;">&gt;</span> <span style="color: #000000; font-weight:bold;">0</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">&#123;</span>
	_label = <span style="color: #990000;">&quot;   &quot;</span> <span style="color: #000066; font-weight: bold;">+</span> str<span style="color: #000066; font-weight: bold;">;</span>
  <span style="color: #000000;">&#125;</span> <span style="color: #0033ff; font-weight: bold;">else</span> <span style="color: #000000;">&#123;</span>
	_label = StringUtil<span style="color: #000066; font-weight: bold;">.</span>trim<span style="color: #000000;">&#40;</span>str<span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>
  <span style="color: #000000;">&#125;</span>
  <span style="color: #009900; font-style: italic;">// call the super last, this will also force the remeausing of the formItem and Form</span>
  <span style="color: #0033ff; font-weight: bold;">super</span><span style="color: #000066; font-weight: bold;">.</span>label = _label<span style="color: #000066; font-weight: bold;">;</span>
<span style="color: #000000;">&#125;</span></pre></div></div>

<p>The above code is very similar to the setter that set the imageSource but this time it sets _label then makes sure that the super function gets the new label.</p>
<p>Check out the <a title="FormItem demo" href="http://kennethsutherland.com/flex/formItem/FormItemDemo.html" target="_blank">simple demo here</a>. (Right click for source)</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/27/formitem-adding-an-icon/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Exploding pie charts, part 2</title>
		<link>http://kennethsutherland.com/2009/05/27/exploding-pie-charts-part-2/</link>
		<comments>http://kennethsutherland.com/2009/05/27/exploding-pie-charts-part-2/#comments</comments>
		<pubDate>Wed, 27 May 2009 09:32:02 +0000</pubDate>
		<dc:creator>Kenneth</dc:creator>
				<category><![CDATA[AIR]]></category>
		<category><![CDATA[charts]]></category>
		<category><![CDATA[Flex]]></category>
		<category><![CDATA[actionscript]]></category>
		<category><![CDATA[effects]]></category>
		<category><![CDATA[explode]]></category>
		<category><![CDATA[legend]]></category>
		<category><![CDATA[Pie charts]]></category>
		<category><![CDATA[pie series]]></category>
		<category><![CDATA[SeriesInterpolate]]></category>

		<guid isPermaLink="false">http://kennethsutherland.com/?p=404</guid>
		<description><![CDATA[In one of my first blogs I demoed a pie chart that made each of the wedges from the pie explode out the way when its item in the legend was rolled over by the mouse. The pie chart also had a nice effect when it was shown in that it filled up in a [...]]]></description>
			<content:encoded><![CDATA[<p>In one of my <a title="Exploding Pie Charts" href="http://kennethsutherland.com/2009/04/02/exploding-pie-charts/" target="_self">first blogs</a> I demoed a pie chart that made each of the wedges from the pie explode out the way when its item in the legend was rolled over by the mouse.<br />
The pie chart also had a nice effect when it was shown in that it filled up in a circular manor.</p>
<p>You can check out the <a title="Exploding Pie Charts" href="http://kennethsutherland.com/flex/pies/main.html" target="_blank">app here</a>.</p>
<p>After a comment/question from the previous post asking about something I didn&#8217;t explain, I thought that it deservered its own post rather than just an edit of the original.</p>
<p>So the question was how do you get the circular effect, and how do you do &#8216;(&#8230; %)&#8217; in the legend?</p>
<h5>The effect</h5>
<p>Firstly set up the effect</p>

<div class="wp_syntax"><div class="code"><pre class="xml" style="font-family:monospace;"><span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;mx:SeriesInterpolate</span> <span style="color: #000066;">id</span>=<span style="color: #ff0000;">&quot;doughnut&quot;</span> <span style="color: #000066;">duration</span>=<span style="color: #ff0000;">&quot;1000&quot;</span> <span style="color: #000000; font-weight: bold;">/&gt;</span></span></pre></div></div>

<p>Then whatever ID you have given your pie series you&#8217;d do the following (I called my one &#8216;seriesOne&#8217;)</p>

<div class="wp_syntax"><div class="code"><pre class="actionscript3" style="font-family:monospace;">seriesOne<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">setStyle</span><span style="color: #000000;">&#40;</span><span style="color: #990000;">'showDataEffect'</span><span style="color: #000066; font-weight: bold;">,</span> doughnut<span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span></pre></div></div>

<p>(I did this set up in the script block on creation complete or show + I nulled the effect/DP&#8217;s on hide so that you get the full effect each time) </p>
<p>If you wish to get the full opening of the circle effect then the data must be empty to start with as the effect just changes between the current and the new values.</p>
<p>The second part of the question was to do with the labels on the legend.  This one is all to do with how you set up your dataprovider for the pie chart.</p>
<h5>The label</h5>
<p>I start of with loading in the data from an XML file (if you use some HTTP tool you should be able to see the data).  It goes something like the following</p>

<div class="wp_syntax"><div class="code"><pre class="xml" style="font-family:monospace;"><span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;chartOne<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
  <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;chartName<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>blah<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/chartName<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
  <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;data<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;section<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
      <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;name<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>item 1<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/name<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
      <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;value<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>37.55<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/value<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/section<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;section<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
      <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;name<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>item 2<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/name<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
      <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;value<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>13.33<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/value<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/section<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>               
  <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/data<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/chartOne<span style="color: #000000; font-weight: bold;">&gt;</span></span></span></pre></div></div>

<p>As you&#8217;ll see from the data there is no &#8216;%&#8217;. So what I do is when I load the data I construct an object VO (value object).</p>
<p>This VO contains the name, item and a label.  The label is just the name + &#8216;(&#8216; + value +&#8217;%)&#8217;.  Then the arrayCollection I use for the dataprovider is just a collection of these object VO&#8217;s.</p>
<p>Essentially my VO is this,</p>

<div class="wp_syntax"><div class="code"><pre class="actionscript3" style="font-family:monospace;"><span style="color: #6699cc; font-weight: bold;">var</span> obj <span style="color: #000066; font-weight: bold;">:</span> <span style="color: #004993;">Object</span> =<span style="color: #0033ff; font-weight: bold;">new</span> <span style="color: #004993;">Object</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>
obj<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">name</span> = <span style="color: #990000;">'item 1'</span><span style="color: #000066; font-weight: bold;">;</span>
obj<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">value</span> = <span style="color: #000000; font-weight:bold;">37.55</span><span style="color: #000066; font-weight: bold;">;</span>
obj<span style="color: #000066; font-weight: bold;">.</span>label = obj<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">name</span> <span style="color: #000066; font-weight: bold;">+</span> <span style="color: #990000;">'('</span> <span style="color: #000066; font-weight: bold;">+</span> obj<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">value</span> <span style="color: #000066; font-weight: bold;">+</span><span style="color: #990000;">'%)'</span><span style="color: #000066; font-weight: bold;">;</span></pre></div></div>

<p>The legend looks at the data for the pie chart and sees the label property and uses that as it is.</p>
<p>This may make you ask about the datatip for the actual pie chart as it doesn&#8217;t contain the brackets. Well for that I had to implement a <i>dataTipFunction</i>.</p>
<p>This function took the form,</p>

<div class="wp_syntax"><div class="code"><pre class="actionscript3" style="font-family:monospace;"><span style="color: #0033ff; font-weight: bold;">private</span> <span style="color: #339966; font-weight: bold;">function</span> returnToolTip<span style="color: #000000;">&#40;</span>hitData<span style="color: #000066; font-weight: bold;">:</span>HitData<span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">:</span><span style="color: #004993;">String</span> <span style="color: #000000;">&#123;</span>
    <span style="color: #0033ff; font-weight: bold;">return</span> hitData<span style="color: #000066; font-weight: bold;">.</span>item<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">name</span> <span style="color: #000066; font-weight: bold;">+</span> <span style="color: #990000;">' '</span> <span style="color: #000066; font-weight: bold;">+</span>hitData<span style="color: #000066; font-weight: bold;">.</span>item<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">value</span> <span style="color: #000066; font-weight: bold;">+</span> <span style="color: #990000;">'%'</span><span style="color: #000066; font-weight: bold;">;</span>
<span style="color: #000000;">&#125;</span></pre></div></div>

<p>and you just can set this in the MXML of the pie chart.</p>
<p>Well hopefully thats explained in a reasonable way, I&#8217;d love to open the entire source for this but without reworking it (commercial reasons) I can&#8217;t.</p>
<p>Check out <a title="Exploding Pie Charts" href="http://kennethsutherland.com/2009/04/02/exploding-pie-charts/" target="_self">part one of the blog 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/27/exploding-pie-charts-part-2/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
		<item>
		<title>Dates, how many days? (DateValidator)</title>
		<link>http://kennethsutherland.com/2009/05/25/dates-how-many-days-datevalidator/</link>
		<comments>http://kennethsutherland.com/2009/05/25/dates-how-many-days-datevalidator/#comments</comments>
		<pubDate>Mon, 25 May 2009 15:43:51 +0000</pubDate>
		<dc:creator>Kenneth</dc:creator>
				<category><![CDATA[actionscript]]></category>
		<category><![CDATA[Flex]]></category>
		<category><![CDATA[Dates]]></category>
		<category><![CDATA[DateValidator]]></category>
		<category><![CDATA[ValidationResultEvent]]></category>

		<guid isPermaLink="false">http://kennethsutherland.com/?p=389</guid>
		<description><![CDATA[It&#8217;s been a while since I last looked at this, and it annoys me that there isn&#8217;t a simple function to do this. So if you are wishing to find out how many days are in a month for a given year then feel free to use the below. Of course it&#8217;s going to be [...]]]></description>
			<content:encoded><![CDATA[<p>It&#8217;s been a while since I last looked at this, and it annoys me that there isn&#8217;t a simple function to do this. So if you are wishing to find out how many days are in a month for a given year then feel free to use the below.</p>
<p>Of course it&#8217;s going to be virtually the same result for most years, but I still think it should be a function inside the Date class (or maybe a DateUtil class).</p>
<p>Start off with a standard Switch statement as all months (apart from February) have a fixed number of days.  This of course isn&#8217;t exactly rocket science but how do we figure out how many days February has?</p>
<p>Well the solution still isn&#8217;t rocket science but I like it, if you create a DateValidator and you give it a date of 29/02/2003 (yes this is a UK date &#8211; date at the start) and get it to validate that, then it will fail as 2003 isn&#8217;t a leap year. So February for 2003 must only have 28 days.</p>
<p>That’s it.  You could of course just divide the year by 4 and check to see if there is a modulus of 0, if so then it is a leap year.  If you chose to use this approach you&#8217;d need to make sure that the date range you are using doesn&#8217;t include anything unusual (I&#8217;m not sure how constant the leap year really is, if it&#8217;s anything like the clocks going forward or back 1 or 2 hours then you&#8217;re best just using the internal date validation).  The flash player gets its time from the operation system, so (AFAIK) its rules for working out if a date is valid is also comes from the operating system.</p>
<p>the below code also shows an example of using the DateValidator that doesn&#8217;t use the month/date/year input, which is another reason why I like it.</p>

<div class="wp_syntax"><div class="code"><pre class="actionscript3" style="font-family:monospace;"><span style="color: #0033ff; font-weight: bold;">public</span> <span style="color: #339966; font-weight: bold;">function</span> getNumberOfDaysInMonth<span style="color: #000000;">&#40;</span><span style="color: #004993;">month</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;">year</span> <span style="color: #000066; font-weight: bold;">:</span> <span style="color: #004993;">Number</span><span style="color: #000000;">&#41;</span> <span style="color: #000066; font-weight: bold;">:</span> <span style="color: #004993;">Number</span><span style="color: #000000;">&#123;</span>
&nbsp;
  <span style="color: #0033ff; font-weight: bold;">switch</span><span style="color: #000000;">&#40;</span><span style="color: #004993;">month</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">&#123;</span>
&nbsp;
    <span style="color: #0033ff; font-weight: bold;">case</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;">//January</span>
    <span style="color: #0033ff; font-weight: bold;">case</span> <span style="color: #000000; font-weight:bold;">2</span><span style="color: #000066; font-weight: bold;">:</span><span style="color: #009900; font-style: italic;">//March</span>
    <span style="color: #0033ff; font-weight: bold;">case</span> <span style="color: #000000; font-weight:bold;">4</span><span style="color: #000066; font-weight: bold;">:</span><span style="color: #009900; font-style: italic;">//May</span>
    <span style="color: #0033ff; font-weight: bold;">case</span> <span style="color: #000000; font-weight:bold;">6</span><span style="color: #000066; font-weight: bold;">:</span><span style="color: #009900; font-style: italic;">//July</span>
    <span style="color: #0033ff; font-weight: bold;">case</span> <span style="color: #000000; font-weight:bold;">7</span><span style="color: #000066; font-weight: bold;">:</span><span style="color: #009900; font-style: italic;">//August</span>
    <span style="color: #0033ff; font-weight: bold;">case</span> <span style="color: #000000; font-weight:bold;">9</span><span style="color: #000066; font-weight: bold;">:</span><span style="color: #009900; font-style: italic;">//October</span>
    <span style="color: #0033ff; font-weight: bold;">case</span> <span style="color: #000000; font-weight:bold;">11</span><span style="color: #000066; font-weight: bold;">:</span><span style="color: #009900; font-style: italic;">//December</span>
    <span style="color: #0033ff; font-weight: bold;">return</span> <span style="color: #000000; font-weight:bold;">31</span><span style="color: #000066; font-weight: bold;">;</span>
    <span style="color: #0033ff; font-weight: bold;">break</span><span style="color: #000066; font-weight: bold;">;</span>
&nbsp;
    <span style="color: #0033ff; font-weight: bold;">case</span> <span style="color: #000000; font-weight:bold;">3</span><span style="color: #000066; font-weight: bold;">:</span><span style="color: #009900; font-style: italic;">//April</span>
    <span style="color: #0033ff; font-weight: bold;">case</span> <span style="color: #000000; font-weight:bold;">5</span><span style="color: #000066; font-weight: bold;">:</span><span style="color: #009900; font-style: italic;">//June</span>
    <span style="color: #0033ff; font-weight: bold;">case</span> <span style="color: #000000; font-weight:bold;">8</span><span style="color: #000066; font-weight: bold;">:</span><span style="color: #009900; font-style: italic;">//September</span>
    <span style="color: #0033ff; font-weight: bold;">case</span> <span style="color: #000000; font-weight:bold;">10</span><span style="color: #000066; font-weight: bold;">:</span><span style="color: #009900; font-style: italic;">//November </span>
    <span style="color: #0033ff; font-weight: bold;">return</span> <span style="color: #000000; font-weight:bold;">30</span><span style="color: #000066; font-weight: bold;">;</span>
    <span style="color: #0033ff; font-weight: bold;">break</span><span style="color: #000066; font-weight: bold;">;</span>
&nbsp;
    <span style="color: #0033ff; font-weight: bold;">case</span> <span style="color: #000000; font-weight:bold;">1</span><span style="color: #000066; font-weight: bold;">:</span><span style="color: #009900; font-style: italic;">//February</span>
    <span style="color: #0033ff; font-weight: bold;">return</span> getNumberOfDaysInFebruary<span style="color: #000000;">&#40;</span><span style="color: #004993;">year</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span><span style="color: #009900; font-style: italic;">//</span>
    <span style="color: #0033ff; font-weight: bold;">break</span><span style="color: #000066; font-weight: bold;">;</span>
&nbsp;
    <span style="color: #0033ff; font-weight: bold;">default</span><span style="color: #000066; font-weight: bold;">:</span>
    <span style="color: #0033ff; font-weight: bold;">return</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;">//should never reach this - if it does then 0 is an error</span>
  <span style="color: #000000;">&#125;</span>
<span style="color: #000000;">&#125;</span>
&nbsp;
<span style="color: #0033ff; font-weight: bold;">private</span> <span style="color: #339966; font-weight: bold;">function</span> getNumberOfDaysInFebruary<span style="color: #000000;">&#40;</span><span style="color: #004993;">year</span>  <span style="color: #000066; font-weight: bold;">:</span> <span style="color: #004993;">Number</span> <span style="color: #000000;">&#41;</span> <span style="color: #000066; font-weight: bold;">:</span> <span style="color: #004993;">Number</span> <span style="color: #000000;">&#123;</span>
&nbsp;
  <span style="color: #6699cc; font-weight: bold;">var</span> isValid <span style="color: #000066; font-weight: bold;">:</span> DateValidator = <span style="color: #0033ff; font-weight: bold;">new</span> DateValidator<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>
  isValid<span style="color: #000066; font-weight: bold;">.</span>inputFormat = <span style="color: #990000;">&quot;DD/MM/YYYY&quot;</span><span style="color: #000066; font-weight: bold;">;</span>
  isValid<span style="color: #000066; font-weight: bold;">.</span>allowedFormatChars = <span style="color: #990000;">&quot;/&quot;</span><span style="color: #000066; font-weight: bold;">;</span>
  <span style="color: #6699cc; font-weight: bold;">var</span> result <span style="color: #000066; font-weight: bold;">:</span> ValidationResultEvent = isValid<span style="color: #000066; font-weight: bold;">.</span>validate<span style="color: #000000;">&#40;</span><span style="color: #990000;">&quot;29/02/&quot;</span><span style="color: #000066; font-weight: bold;">+</span> <span style="color: #004993;">year</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>
  <span style="color: #0033ff; font-weight: bold;">if</span><span style="color: #000000;">&#40;</span>result<span style="color: #000066; font-weight: bold;">.</span>results == <span style="color: #0033ff; font-weight: bold;">null</span> <span style="color: #000000;">&#41;</span><span style="color: #000000;">&#123;</span><span style="color: #009900; font-style: italic;">//29th is a valid date</span>
    <span style="color: #0033ff; font-weight: bold;">return</span> <span style="color: #000000; font-weight:bold;">29</span><span style="color: #000066; font-weight: bold;">;</span>
  <span style="color: #000000;">&#125;</span> <span style="color: #0033ff; font-weight: bold;">else</span> <span style="color: #000000;">&#123;</span><span style="color: #009900; font-style: italic;">//29th is NOT a valid date</span>
    <span style="color: #0033ff; font-weight: bold;">return</span> <span style="color: #000000; font-weight:bold;">28</span><span style="color: #000066; font-weight: bold;">;</span>
  <span style="color: #000000;">&#125;</span>
<span style="color: #000000;">&#125;</span></pre></div></div>

<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/dates-how-many-days-datevalidator/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Custom Class &amp; Custom Itemrenderer</title>
		<link>http://kennethsutherland.com/2009/05/20/custom-class-custom-itemrenderer/</link>
		<comments>http://kennethsutherland.com/2009/05/20/custom-class-custom-itemrenderer/#comments</comments>
		<pubDate>Wed, 20 May 2009 14:02:05 +0000</pubDate>
		<dc:creator>Kenneth</dc:creator>
				<category><![CDATA[actionscript]]></category>
		<category><![CDATA[Flex]]></category>
		<category><![CDATA[Itemrenderer]]></category>
		<category><![CDATA[custom class]]></category>

		<guid isPermaLink="false">http://kennethsutherland.com/?p=322</guid>
		<description><![CDATA[Today (not for the first time &#8211; but it&#8217;s been a while) I needed to create a custom class that took a custom itemRenderer. Having used itemRenderers for ages I thought it was going to be straight forward, but I&#8217;d forgotten a few little bits of info needed to implement them from scratch (i.e. not [...]]]></description>
			<content:encoded><![CDATA[<p>Today (not for the first time &#8211; but it&#8217;s been a while) I needed to create a custom class that took a custom itemRenderer.</p>
<p>Having used itemRenderers for ages I thought it was going to be straight forward, but I&#8217;d forgotten a few little bits of info needed to implement them from scratch (i.e. not using say a menu or datagrids itemRenderers). It&#8217;s all very well to just give a flex component a class name in the MXML but how does the class that contains the itemrenderer implement it?</p>
<h4>Test app</h4>
<p><span style="font-weight: normal;">So I created a very small test app to make sure that I could create a custom itemRenderer for my custom class.</span></p>
<ul>
<li>Step 1, create the custom itemRenderer.  For the test I just made this a Canvas and made it 100% * 100% and the background colour was red.</li>
<li>step 2, display the class that you are going use as an itemRenderer as a normal display object (place custom class inside a Canvas)</li>
<li>step 3, create a custom class that will take and display an itemRenderer. Once created assign your new custom itemRenderer to the new custom class.</li>
<li>View the test app, all going well you should now see two instances of your itemRenderer. One is the actual class as a displayObject and the other as an itemRenderer inside your custom class.</li>
</ul>
<p>I&#8217;ve placed my <a title="Test itemRenderer" href="http://www.kennethsutherland.com/flex/itemRender/ItemRendererTest.html" target="_blank">small test app here</a> purely so that you can look at the source code (right click app).  The app does NOTHING and is not interactive, it&#8217;s just to show the source code and how to make sure you set things up correctly.</p>
<p> </p>
<p>Once you&#8217;ve looked at the code this bit will make sense.</p>
<ul>
<li>step 1 &amp; 2, display a canvas in the top left. This canvas contains only the custom class that is to be used as an itemRenderer.  This just proves that the itemRender will display what you think it should.</li>
<li>step 3,  create a custom class that will contain your itemRenderer. Then place custom class into app and set the itemRenderer to your custom itemRenderer class.  </li>
</ul>
<p>All you need to do now is create a itemRenderer slighty more complex than a red box, but as long as it&#8217;s a DisplayObject then its going to be the same.</p>
<p>That&#8217;s it, as ever feel free to comment (<span><span>especially</span></span><span><span> </span></span>if you&#8217;ve found this helpful).</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/20/custom-class-custom-itemrenderer/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Tiles and the packing problem</title>
		<link>http://kennethsutherland.com/2009/05/18/tiles-and-the-packing-problem/</link>
		<comments>http://kennethsutherland.com/2009/05/18/tiles-and-the-packing-problem/#comments</comments>
		<pubDate>Mon, 18 May 2009 13:32:21 +0000</pubDate>
		<dc:creator>Kenneth</dc:creator>
				<category><![CDATA[actionscript]]></category>
		<category><![CDATA[Flex]]></category>
		<category><![CDATA[packing problem]]></category>
		<category><![CDATA[tilelist]]></category>
		<category><![CDATA[tiles]]></category>

		<guid isPermaLink="false">http://kennethsutherland.com/?p=303</guid>
		<description><![CDATA[On more than one occasion in the past I&#8217;ve been wishing to create a custom component that is totally dynamic so that I don&#8217;t have to worry about hardcoding any sizes. So lets just say I have a list/tilelist and it contains pictures. Normally what I&#8217;d do is make sure that the pictures are a [...]]]></description>
			<content:encoded><![CDATA[<p>On more than one occasion in the past I&#8217;ve been wishing to create a custom component that is totally dynamic so that I don&#8217;t have to worry about hardcoding any sizes.<br />
So lets just say I have a list/tilelist and it contains pictures. Normally what I&#8217;d do is make sure that the pictures are a set size and I&#8217;d just make the list dynamic in one direction so it may end up showing 4.5 tiles which is normally fine as it&#8217;s a scrollable list.</p>
<p>But what if you have a list that will only ever contain say 10 items and you wish to use as much of the users screen as possible then each time the user changes the screen size you need to work out the optimal size of a tile/item.</p>
<p><a title="Packing problem demo" href="http://www.kennethsutherland.com/flex/packing/SlideSorter.html" target="_blank"><img class="aligncenter" title="packing demo image" src="/flex/packing/packing.png" alt="" width="600" height="299" /></a></p>
<p>Check out the <a title="Packing problem demo" href="http://www.kennethsutherland.com/flex/packing/SlideSorter.html" target="_blank">demo here</a>.  This actually took me quiet a while to figure out how to do, I think the function to work out the size has gone through several iterations. (the example is based on the Tile class as that handles the layout and lets me do the nice animation moves when one tile moves around the screen on resize)</p>
<p>Here is the actionscript code that will work out the optimal size.  I know that this function can be optimised further, but this will do to show you how its done. (possible optimisations: SQRT is not a nice function to call for the processor, use it sparingly, reducing number by just -1 each time isn&#8217;t great either, could reduce it by larger amounts then swing back a forth until I get the best fit).</p>

<div class="wp_syntax"><div class="code"><pre class="actionscript3" style="font-family:monospace;"><span style="color: #009900; font-style: italic;">//total number of tiles</span>
<span style="color: #6699cc; font-weight: bold;">var</span> tile_count <span style="color: #000066; font-weight: bold;">:</span> <span style="color: #004993;">Number</span> = numberOfSlides<span style="color: #000066; font-weight: bold;">;</span>
<span style="color: #009900; font-style: italic;">//height of rectangle</span>
<span style="color: #6699cc; font-weight: bold;">var</span> <span style="color: #004993;">b</span> <span style="color: #000066; font-weight: bold;">:</span> <span style="color: #004993;">Number</span> = unscaledHeight<span style="color: #000066; font-weight: bold;">;</span>
<span style="color: #009900; font-style: italic;">//width of rectanlge</span>
<span style="color: #6699cc; font-weight: bold;">var</span> a <span style="color: #000066; font-weight: bold;">:</span> <span style="color: #004993;">Number</span> = unscaledWidth<span style="color: #000066; font-weight: bold;">;</span>
&nbsp;
<span style="color: #009900; font-style: italic;">//divide the area but the number of tiles to get the max area a tile could cover</span>
<span style="color: #009900; font-style: italic;">//this optimal size for a tile will more often than not make the tiles overlap, but</span>
<span style="color: #009900; font-style: italic;">//a tile can never be bigger than this size</span>
<span style="color: #6699cc; font-weight: bold;">var</span> maxSize <span style="color: #000066; font-weight: bold;">:</span> <span style="color: #004993;">Number</span> = <span style="color: #004993;">Math</span><span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">sqrt</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#40;</span><span style="color: #004993;">b</span> <span style="color: #000066; font-weight: bold;">*</span> a<span style="color: #000000;">&#41;</span> <span style="color: #000066; font-weight: bold;">/</span> tile_count<span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>
<span style="color: #009900; font-style: italic;">//find the number of whole tiles that can fit into the height</span>
<span style="color: #6699cc; font-weight: bold;">var</span> numberOfPossibleWholeTilesH <span style="color: #000066; font-weight: bold;">:</span> <span style="color: #004993;">Number</span> = <span style="color: #004993;">Math</span><span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">floor</span><span style="color: #000000;">&#40;</span><span style="color: #004993;">b</span> <span style="color: #000066; font-weight: bold;">/</span> maxSize<span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>
<span style="color: #009900; font-style: italic;">//find the number of whole tiles that can fit into the width</span>
<span style="color: #6699cc; font-weight: bold;">var</span> numberOfPossibleWholeTilesW <span style="color: #000066; font-weight: bold;">:</span> <span style="color: #004993;">Number</span> = <span style="color: #004993;">Math</span><span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">floor</span><span style="color: #000000;">&#40;</span>a <span style="color: #000066; font-weight: bold;">/</span> maxSize<span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>
<span style="color: #009900; font-style: italic;">//works out how many whole tiles this configuration can hold</span>
<span style="color: #6699cc; font-weight: bold;">var</span> total <span style="color: #000066; font-weight: bold;">:</span> <span style="color: #004993;">Number</span> = numberOfPossibleWholeTilesH <span style="color: #000066; font-weight: bold;">*</span> numberOfPossibleWholeTilesW<span style="color: #000066; font-weight: bold;">;</span>
&nbsp;
<span style="color: #009900; font-style: italic;">//if the number of number of whole tiles that the max size tile ends up with is less than the require number of</span>
<span style="color: #009900; font-style: italic;">//tiles, make the maxSize smaller and recaluate</span>
<span style="color: #0033ff; font-weight: bold;">while</span><span style="color: #000000;">&#40;</span>total <span style="color: #000066; font-weight: bold;">&amp;</span>lt<span style="color: #000066; font-weight: bold;">;</span> tile_count<span style="color: #000000;">&#41;</span><span style="color: #000000;">&#123;</span>
	maxSize<span style="color: #000066; font-weight: bold;">--;</span>
	numberOfPossibleWholeTilesH = <span style="color: #004993;">Math</span><span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">floor</span><span style="color: #000000;">&#40;</span><span style="color: #004993;">b</span> <span style="color: #000066; font-weight: bold;">/</span> maxSize<span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>
	numberOfPossibleWholeTilesW = <span style="color: #004993;">Math</span><span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">floor</span><span style="color: #000000;">&#40;</span>a <span style="color: #000066; font-weight: bold;">/</span> maxSize<span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>
	total = numberOfPossibleWholeTilesH <span style="color: #000066; font-weight: bold;">*</span> numberOfPossibleWholeTilesW<span style="color: #000066; font-weight: bold;">;</span>
<span style="color: #000000;">&#125;</span>
&nbsp;
<span style="color: #0033ff; font-weight: bold;">return</span> maxSize<span style="color: #000066; font-weight: bold;">;</span></pre></div></div>

<p style="text-align: left;">If anyone else has a solution or knows of a better solution using actionscript (or anything else for that matter) I&#8217;d love to see it as although this works I&#8217;m thinking there must be a faster solution.</p>
<p style="text-align: left;">Looking at links like the following <a title="Packing problem" href="http://www.combinatorics.org/Surveys/ds7.html" target="_blank">http://www.combinatorics.org/Surveys/ds7.html</a> these problems can be pretty complicated!</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/18/tiles-and-the-packing-problem/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
		<item>
		<title>Flex and Google Maps</title>
		<link>http://kennethsutherland.com/2009/05/08/flex-and-maps/</link>
		<comments>http://kennethsutherland.com/2009/05/08/flex-and-maps/#comments</comments>
		<pubDate>Fri, 08 May 2009 08:18:31 +0000</pubDate>
		<dc:creator>Kenneth</dc:creator>
				<category><![CDATA[Flex]]></category>
		<category><![CDATA[google maps]]></category>
		<category><![CDATA[actionscript]]></category>
		<category><![CDATA[InfoWindowOptions]]></category>
		<category><![CDATA[panning]]></category>

		<guid isPermaLink="false">http://kennethsutherland.com/?p=249</guid>
		<description><![CDATA[I started to try out some flex with Google maps and it’s refreshingly straight forward. Virtually all of the information to do the below can be found here http://code.google.com/apis/maps/documentation/flash/reference.html   So I’m just going to highlight a couple of things I did that were not in the docs. Panning Panning, well there is an example [...]]]></description>
			<content:encoded><![CDATA[<p>I started to try out some flex with Google maps and it’s refreshingly straight forward.</p>
<p class="MsoNormal"><span>Virtually all of the information to do the below can be found here <a href="http://code.google.com/apis/maps/documentation/flash/reference.html">http://code.google.com/apis/maps/documentation/flash/reference.html</a></span></p>
<p class="MsoNormal"><span> <a title="Google Map" href="http://www.kennethsutherland.com/flex/maps/MapTest.html" target="_blank"><img class="aligncenter" title="click to see app" src="/flex/maps/maps (Small).jpg" alt="" width="640" height="332" /></a><br />
</span></p>
<p class="MsoNormal"><span>So I’m just going to highlight a couple of things I did that were not in the docs.</span></p>
<h4><span>Panning</span></h4>
<ul>
<li>
<p class="MsoListParagraph"><span>Panning, well there is an example on how to do panning in ‘tour de flex’ but it uses a very basic method to work out difference between 2 points, divide by 100 and just add difference to starting point using the timer function.</span></p>
</li>
</ul>
<p class="MsoListParagraph"><span>A much better way would be to use a Tween so that you can implement an easing function, but a tween will only do one value at a time and a point has two values.</span></p>
<p class="MsoListParagraph"><span>So I used the Move class. It moves an object from point A to point B which is exactly what I was after, but I just wanted the values as I’m not moving an object.</span></p>
<p class="MsoListParagraph"><span> Here is the actionscript code to implement it</span></p>

<div class="wp_syntax"><div class="code"><pre class="actionscript3" style="font-family:monospace;"><span style="color: #009900; font-style: italic;">//The move effect needs a target  otherwise it will NOT tween</span>
<span style="color: #009900; font-style: italic;">//so just create a temporary target</span>
<span style="color: #6699cc; font-weight: bold;">var</span> uiTemp <span style="color: #000066; font-weight: bold;">:</span> UIComponent = <span style="color: #0033ff; font-weight: bold;">new</span> UIComponent<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>
moveEffect = <span style="color: #0033ff; font-weight: bold;">new</span> Move<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>
<span style="color: #009900; font-style: italic;">//set up the move effect</span>
moveEffect<span style="color: #000066; font-weight: bold;">.</span>xFrom = currentLatLng<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">x</span><span style="color: #000066; font-weight: bold;">;</span>
moveEffect<span style="color: #000066; font-weight: bold;">.</span>yFrom = currentLatLng<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">y</span><span style="color: #000066; font-weight: bold;">;</span>
moveEffect<span style="color: #000066; font-weight: bold;">.</span>duration = <span style="color: #000000; font-weight:bold;">1500</span><span style="color: #000066; font-weight: bold;">;</span>
moveEffect<span style="color: #000066; font-weight: bold;">.</span>easingFunction = moveMap<span style="color: #000066; font-weight: bold;">;</span>
moveEffect<span style="color: #000066; font-weight: bold;">.</span>xTo = <span style="color: #004993;">Number</span><span style="color: #000000;">&#40;</span>mapDetails<span style="color: #000066; font-weight: bold;">.</span>lat<span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>
moveEffect<span style="color: #000066; font-weight: bold;">.</span>yTo = <span style="color: #004993;">Number</span><span style="color: #000000;">&#40;</span>mapDetails<span style="color: #000066; font-weight: bold;">.</span>long<span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>
&nbsp;
<span style="color: #009900; font-style: italic;">//on each update move the map</span>
<span style="color: #009900; font-style: italic;">//calls the map.setCenter method</span>
moveEffect<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">addEventListener</span><span style="color: #000000;">&#40;</span>TweenEvent<span style="color: #000066; font-weight: bold;">.</span>TWEEN_UPDATE<span style="color: #000066; font-weight: bold;">,</span> updateMapPosition<span style="color: #000066; font-weight: bold;">,</span> <span style="color: #0033ff; font-weight: bold;">false</span><span style="color: #000066; font-weight: bold;">,</span> <span style="color: #000000; font-weight:bold;">0</span><span style="color: #000066; font-weight: bold;">,</span> <span style="color: #0033ff; font-weight: bold;">true</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>
<span style="color: #009900; font-style: italic;">//at the end I open up the marker window</span>
moveEffect<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">addEventListener</span><span style="color: #000000;">&#40;</span>TweenEvent<span style="color: #000066; font-weight: bold;">.</span>TWEEN_END<span style="color: #000066; font-weight: bold;">,</span> showMarker<span style="color: #000066; font-weight: bold;">,</span> <span style="color: #0033ff; font-weight: bold;">false</span><span style="color: #000066; font-weight: bold;">,</span> <span style="color: #000000; font-weight:bold;">0</span><span style="color: #000066; font-weight: bold;">,</span> <span style="color: #0033ff; font-weight: bold;">true</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>
<span style="color: #009900; font-style: italic;">//Play effect, give it the target so that it actually plays</span>
moveEffect<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">play</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#91;</span>uiTemp<span style="color: #000000;">&#93;</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span></pre></div></div>

<h4>Marker Windows</h4>
<ul>
<li>
<p class="MsoListParagraph"><span>The information window that pops up beside the marker on the map needed to be an image with some text.<span>  </span>I never noticed any examples in the docs for this but I did see an example online so I thought I’d stick into this post as well to increase its coverage.</span></p>
<p class="MsoListParagraph"><span>Again very straight forward (Google really makes it easy for developers) check out the code below.</span></p>
</li>
</ul>
<p> </p>

<div class="wp_syntax"><div class="code"><pre class="actionscript3" style="font-family:monospace;"><span style="color: #009900; font-style: italic;">//In order to open a window beside a marker you need a InfoWindowOptions</span>
<span style="color: #6699cc; font-weight: bold;">var</span> options<span style="color: #000066; font-weight: bold;">:</span>InfoWindowOptions = <span style="color: #0033ff; font-weight: bold;">new</span> InfoWindowOptions<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#123;</span>
    <span style="color: #009900; font-style: italic;">//This is the key line for making it into a custom window</span>
    <span style="color: #009900; font-style: italic;">//uiHolder is a Canvas (but it can be any UIComponent) and I'm sure you know what you can put into</span>
    <span style="color: #009900; font-style: italic;">//a UIComponent, anything you like :)</span>
    customContent<span style="color: #000066; font-weight: bold;">:</span> uiHolder<span style="color: #000066; font-weight: bold;">,</span>
&nbsp;
    padding <span style="color: #000066; font-weight: bold;">:</span> <span style="color: #000000; font-weight:bold;">7</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; font-weight:bold;">262</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: #000000; font-weight:bold;">262</span><span style="color: #000066; font-weight: bold;">,</span>
    drawDefaultFrame<span style="color: #000066; font-weight: bold;">:</span> <span style="color: #0033ff; font-weight: bold;">true</span>
<span style="color: #000000;">&#125;</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>
<span style="color: #009900; font-style: italic;">//Take the marker that you wish the window to appear above and</span>
<span style="color: #009900; font-style: italic;">//call openInfoWindow and pass in the InfoWindowOptions you just created</span>
currentOpenMarker<span style="color: #000066; font-weight: bold;">.</span>openInfoWindow<span style="color: #000000;">&#40;</span>options<span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span></pre></div></div>

<p class="MsoNormal"><span> <a title="Google Map" href="http://kennethsutherland.com/flex/wendy/PaintingMaps.html" target="_blank">Click to open app in new window</a></span></p>
<p class="MsoNormal"><span><a title="Google Map" href="http://www.kennethsutherland.com/flex/maps/MapTest.html" target="_blank">Click to open app2 in new window</a><br />
</span></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/08/flex-and-maps/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
	</channel>
</rss>

