<?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>BetaDesigns( Blog ).toString( ); &#187; ActionScript</title>
	<atom:link href="http://www.betadesigns.co.uk/Blog/category/actionscript/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.betadesigns.co.uk/Blog</link>
	<description>Flex and Component Development</description>
	<lastBuildDate>Sat, 10 Jul 2010 13:38:12 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.9.2</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>Converting MX Component to Spark Component ( Part 2 &#8211; a )</title>
		<link>http://www.betadesigns.co.uk/Blog/2010/07/10/converting-mx-component-to-spark-component-part-2-a/</link>
		<comments>http://www.betadesigns.co.uk/Blog/2010/07/10/converting-mx-component-to-spark-component-part-2-a/#comments</comments>
		<pubDate>Sat, 10 Jul 2010 13:13:06 +0000</pubDate>
		<dc:creator>Anthony</dc:creator>
				<category><![CDATA[ActionScript]]></category>
		<category><![CDATA[Components]]></category>
		<category><![CDATA[Flex]]></category>
		<category><![CDATA[custom components]]></category>
		<category><![CDATA[flashbuilder]]></category>
		<category><![CDATA[skinning]]></category>
		<category><![CDATA[spark]]></category>
		<category><![CDATA[spark components]]></category>
		<category><![CDATA[TDD]]></category>

		<guid isPermaLink="false">http://www.betadesigns.co.uk/Blog/?p=271</guid>
		<description><![CDATA[In the previous post we began building our custom Spark colorPicker by creating the preview class and it's corresponding default skin.
In this post we will begin by creating a KeyboardManager class that will allow us to calculate the new index in the dataProvider after a Up/Down/Left/Right keyboard input.
This class can become quite complicated because we [...]]]></description>
			<content:encoded><![CDATA[<p id="top" />In <a href="http://www.betadesigns.co.uk/Blog/2010/06/10/converting-a-mx-component-to-a-spark-component/">the previous post</a> we began building our custom Spark colorPicker by creating the preview class and it's corresponding default skin.<br />
In this post we will begin by creating a KeyboardManager class that will allow us to calculate the new index in the dataProvider after a Up/Down/Left/Right keyboard input.</p>
<p>This class can become quite complicated because we want the following behaviour from our keyboard manager.<br />
The selected index should be able to move up past the top of the dataProvider and move to the bottom row and vice versa, in addition we should be able to go off the left hand side of the columns and appear on the right hand side and vice versa.</p>
<p>For example if the dataProvider has 25 items and each row contains 5 columns.</p>
<p>Up / Down Examples.<br />
If we are at column 1 row 1 ( box 1 ) and we press up we should go to column 1 row 5( box 2 ) and then for every key press we should move up the column until we hit the row 1 column 1 index again. However if we press down then we should go to column 1 row 2  and so forth until we hit  column 1 row 5 ( box 2 ). Then when we press down again we should move to the top of the column again row 1 column 1 ( box 1 ) and this should be the case for each column no matter how many rows it has.</p>
<p>Box 1          Box 2<br />
<img src="http://betadesigns.co.uk/Examples/posts/ConvertingMXtoSparkComponent/Box1.png" alt="Box one" /><img src="http://betadesigns.co.uk/Examples/posts/ConvertingMXtoSparkComponent/Box2.png" alt="Box two" /></p>
<p><span id="more-271"></span><br />
Left / Right Examples<br />
Again if we start in column 1 row 1 ( box 1 ) and we press left then we should end up in column 5 row 1 ( box 3 ) and each subsequent left keyboard event should decrement the column number until it reaches 1 again.<br />
If we press the opposite right key then we should move right along the columns until we hit column 5 row 1 ( box 3 ) then we should loop back to column 1 row 1 ( box 1 ).</p>
<p>Box 1          Box 3<br />
<img src="http://betadesigns.co.uk/Examples/posts/ConvertingMXtoSparkComponent/Box1.png" alt="Box one" /><img src="http://betadesigns.co.uk/Examples/posts/ConvertingMXtoSparkComponent/Box3.png" alt="Box three" /></p>
<p>This is all quite simple however what should happen if we have an odd number in our dataProvider? For example a 5*5 grid with a 19 color dataprovider? like follows.<br />
<img src="http://betadesigns.co.uk/Examples/posts/ConvertingMXtoSparkComponent/19Box0.png" alt="" /><br />
We need to make sure that pressing left and right still stay on the same row no matter how many items are in that row for example if we move from column 1 row 5 ( box 4 ) left we should end up in column 4 row 5 ( box 5 ) and vice versa if we press right from box 5 we should end up in box 4.</p>
<p>Box 4          Box 5<br />
<img src="http://betadesigns.co.uk/Examples/posts/ConvertingMXtoSparkComponent/19Box4.png" alt="Box one" /><img src="http://betadesigns.co.uk/Examples/posts/ConvertingMXtoSparkComponent/19Box5.png" alt="Box three" /><br />
Also if we are in box 5 and we press down we should still go to the first item in the column. Furthermore if we are in position column 5 row 4 ( box 6 ) and we press down we should still go to position column 5 row 1 ( box 3 ). And if we press right then we should go to column 1 row 4 ( box 7 ) and vice versa.<br />
Box 6          Box 7<br />
<img src="http://betadesigns.co.uk/Examples/posts/ConvertingMXtoSparkComponent/19Box6.png" alt="Box one" /><img src="http://betadesigns.co.uk/Examples/posts/ConvertingMXtoSparkComponent/19Box7.png" alt="Box three" /></p>
<p>Ok now we can actually get started writing some code. To begin we will need to know two things<br />
1. The length of the dataProvider and 2. the number of columns to split it into. Next we need to know the current index and the keyboard input the user pressed. Knowing this lets create the following Interface.</p>
<div class="scrolllarge">
<pre class="flex">&nbsp;
<span style="color: #9e12cf; font-weight: bold;">package</span> co.<span style="color: #000000;">uk</span>.<span style="color: #000000;">betadesigns</span>.<span style="color: #000000;">components</span>.<span style="color: #000000;">colorpicker</span>.<span style="color: #000000;">interfaces</span>
<span style="color: #000000;">&#123;</span>
	<span style="color: #5b7bff; font-weight: bold;">import</span> flash.<span style="color: #000000;">events</span>.<span style="color: #000000;">KeyboardEvent</span>;
&nbsp;
	<span style="color: #5b7bff; font-weight: bold;">public</span> interface ISparkColorPickerKeyboardManager
	<span style="color: #000000;">&#123;</span>
		<span style="color: #3f5fc4; font-style: italic;">/**
		 * Set the number of columns that the ColorPicker has this
		 * is used in calculating the new index after keyboard events
		 * are pressed. The number of rows is also automatically calculated
		 * from dataProviderLength / numberOfColumns.
		 *
		 * @param value int representing the number of columns.
		 * @return int representing the number of columns.
		 *
		 */</span>
		<span style="color: #009900; font-weight: bold;">function</span> <span style="color: #5b7bff; font-weight: bold;">set</span> numberOfColumns<span style="color: #000000;">&#40;</span> value : int <span style="color: #000000;">&#41;</span> : <span style="color: #5b7bff; font-weight: bold;">void</span>;
		<span style="color: #009900; font-weight: bold;">function</span> <span style="color: #5b7bff; font-weight: bold;">get</span> numberOfColumns<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span> : int;
&nbsp;
		<span style="color: #3f5fc4; font-style: italic;">/**
		 * Set the length that the ColorPicker dataProvider has.
		 * This is used in calculating the new index after keyboard events
		 * are pressed. The number of rows is also automatically calculated
		 * from dataProviderLength / numberOfColumns.
		 *
		 * @param value int representing the number of columns.
		 * @return int representing the number of columns.
		 *
		 */</span>
		<span style="color: #009900; font-weight: bold;">function</span> <span style="color: #5b7bff; font-weight: bold;">set</span> dataProviderLength<span style="color: #000000;">&#40;</span> value : int <span style="color: #000000;">&#41;</span> : <span style="color: #5b7bff; font-weight: bold;">void</span>;
		<span style="color: #009900; font-weight: bold;">function</span> <span style="color: #5b7bff; font-weight: bold;">get</span> dataProviderLength<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span> : int;
&nbsp;
		<span style="color: #3f5fc4; font-style: italic;">/**
		 * The KeyDown method takes a keyboard event and the current
		 * index in the dataprovider it then calculates the new index
		 * based on the keyboard button pressed UP/DOWN/LEFT/RIGHT
		 * It uses the numberOfColumns and numberOfRows in order to
		 * calculate the the new index.
		 *
		 * @param event the keyboard event.
		 * @param index the current index in the dataProvider.
		 *
		 * @return returns the new index in the dataProvider.
		 *
		 */</span>
		<span style="color: #009900; font-weight: bold;">function</span> keyDown<span style="color: #000000;">&#40;</span> <span style="color: #5b7bff; font-weight: bold;">event</span> : KeyboardEvent, index : int <span style="color: #000000;">&#41;</span> : int;
	<span style="color: #000000;">&#125;</span>
<span style="color: #000000;">&#125;</span>
&nbsp;</pre>
</div>
<p>Next we need to create two classes the first is our empty SparkColorPickerKeyboardManager and the second is the TestCase to go along with it.</p>
<div class="scrolllarge">
<pre class="flex">&nbsp;
<span style="color: #9e12cf; font-weight: bold;">package</span> co.<span style="color: #000000;">uk</span>.<span style="color: #000000;">betadesigns</span>.<span style="color: #000000;">components</span>.<span style="color: #000000;">colorpicker</span>
<span style="color: #000000;">&#123;</span>
	<span style="color: #5b7bff; font-weight: bold;">import</span> co.<span style="color: #000000;">uk</span>.<span style="color: #000000;">betadesigns</span>.<span style="color: #000000;">components</span>.<span style="color: #000000;">colorpicker</span>.<span style="color: #000000;">interfaces</span>.<span style="color: #000000;">ISparkColorPickerKeyboardManager</span>;
&nbsp;
	<span style="color: #5b7bff; font-weight: bold;">import</span> flash.<span style="color: #000000;">events</span>.<span style="color: #000000;">KeyboardEvent</span>;
	<span style="color: #5b7bff; font-weight: bold;">import</span> flash.<span style="color: #000000;">ui</span>.<span style="color: #000000;">Keyboard</span>;
&nbsp;
	<span style="color: #5b7bff; font-weight: bold;">public</span> <span style="color: #9e12cf; font-weight: bold;">class</span> SparkColorPickerKeyboardManager
		<span style="color: #5b7bff; font-weight: bold;">implements</span> ISparkColorPickerKeyboardManager
	<span style="color: #000000;">&#123;</span>
		<span style="color: #5b7bff; font-weight: bold;">private</span> <span style="color: #b7cfe7; font-weight: bold;">var</span> _numberOfColumns : int = <span style="color: #000000;">1</span>;
&nbsp;
		<span style="color: #5b7bff; font-weight: bold;">public</span> <span style="color: #009900; font-weight: bold;">function</span> <span style="color: #5b7bff; font-weight: bold;">get</span> numberOfColumns<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>:int
		<span style="color: #000000;">&#123;</span>
			<span style="color: #5b7bff; font-weight: bold;">return</span> _numberOfColumns;
		<span style="color: #000000;">&#125;</span>
&nbsp;
		<span style="color: #5b7bff; font-weight: bold;">public</span> <span style="color: #009900; font-weight: bold;">function</span> <span style="color: #5b7bff; font-weight: bold;">set</span> numberOfColumns<span style="color: #000000;">&#40;</span>value:int<span style="color: #000000;">&#41;</span>:<span style="color: #5b7bff; font-weight: bold;">void</span>
		<span style="color: #000000;">&#123;</span>
			<span style="color: #5b7bff; font-weight: bold;">if</span><span style="color: #000000;">&#40;</span> value &lt; <span style="color: #000000;">1</span> <span style="color: #000000;">&#41;</span> value = <span style="color: #000000;">1</span>;
			_numberOfColumns = value;
		<span style="color: #000000;">&#125;</span>
&nbsp;
		<span style="color: #5b7bff; font-weight: bold;">private</span> <span style="color: #b7cfe7; font-weight: bold;">var</span> _dataProviderLength : int = <span style="color: #000000;">0</span>;
&nbsp;
		<span style="color: #5b7bff; font-weight: bold;">public</span> <span style="color: #009900; font-weight: bold;">function</span> <span style="color: #5b7bff; font-weight: bold;">get</span> dataProviderLength<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>:int
		<span style="color: #000000;">&#123;</span>
			<span style="color: #5b7bff; font-weight: bold;">return</span> _dataProviderLength;
		<span style="color: #000000;">&#125;</span>
&nbsp;
		<span style="color: #5b7bff; font-weight: bold;">public</span> <span style="color: #009900; font-weight: bold;">function</span> <span style="color: #5b7bff; font-weight: bold;">set</span> dataProviderLength<span style="color: #000000;">&#40;</span>value:int<span style="color: #000000;">&#41;</span>:<span style="color: #5b7bff; font-weight: bold;">void</span>
		<span style="color: #000000;">&#123;</span>
			<span style="color: #5b7bff; font-weight: bold;">if</span><span style="color: #000000;">&#40;</span> value &lt; <span style="color: #000000;">1</span> <span style="color: #000000;">&#41;</span> value = <span style="color: #000000;">1</span>;
			_dataProviderLength = value;
		<span style="color: #000000;">&#125;</span>
&nbsp;
		<span style="color: #5b7bff; font-weight: bold;">public</span> <span style="color: #009900; font-weight: bold;">function</span> keyDown<span style="color: #000000;">&#40;</span> <span style="color: #5b7bff; font-weight: bold;">event</span> : KeyboardEvent, index : int <span style="color: #000000;">&#41;</span> : int
		<span style="color: #000000;">&#123;</span>
			<span style="color: #5b7bff; font-weight: bold;">return</span> index;
		<span style="color: #000000;">&#125;</span>
	<span style="color: #000000;">&#125;</span>
<span style="color: #000000;">&#125;</span>
&nbsp;</pre>
</div>
<p>As you can see from the source above we have put in some simple checks on the setters to make sure the numberOfColumns and the dataProviderLength value can never be set to below 1 this will stop us from returning NaN and Infinity values.<br />
For our TestCase we won't bother testing those two setters as they are quite simple so just setup your empty SparkColorPickerKeyboardMangerTests.as with 4 failing tests for our events Up/Down/Left/Right</p>
<div class="scrolllarge">
<pre class="flex">&nbsp;
<span style="color: #9e12cf; font-weight: bold;">package</span> flexUnitTests.<span style="color: #000000;">co</span>.<span style="color: #000000;">uk</span>.<span style="color: #000000;">betadesigns</span>.<span style="color: #000000;">components</span>.<span style="color: #000000;">colorpicker</span>
<span style="color: #000000;">&#123;</span>
	<span style="color: #5b7bff; font-weight: bold;">import</span> co.<span style="color: #000000;">uk</span>.<span style="color: #000000;">betadesigns</span>.<span style="color: #000000;">components</span>.<span style="color: #000000;">colorpicker</span>.<span style="color: #000000;">SparkColorPickerKeyboardManager</span>;
&nbsp;
	<span style="color: #5b7bff; font-weight: bold;">import</span> flash.<span style="color: #000000;">events</span>.<span style="color: #000000;">KeyboardEvent</span>;
	<span style="color: #5b7bff; font-weight: bold;">import</span> flash.<span style="color: #000000;">ui</span>.<span style="color: #000000;">Keyboard</span>;
&nbsp;
	<span style="color: #5b7bff; font-weight: bold;">import</span> flexunit.<span style="color: #000000;">framework</span>.<span style="color: #000000;">Assert</span>;
&nbsp;
	<span style="color: #5b7bff; font-weight: bold;">public</span> <span style="color: #9e12cf; font-weight: bold;">class</span> SparkColorPickerKeyboardManagerTests
	<span style="color: #000000;">&#123;</span>
		<span style="color: #5b7bff; font-weight: bold;">private</span> <span style="color: #b7cfe7; font-weight: bold;">var</span> _class : SparkColorPickerKeyboardManager;
&nbsp;
		<span style="color: #000000;">&#91;</span>Before<span style="color: #000000;">&#93;</span>
		<span style="color: #5b7bff; font-weight: bold;">public</span> <span style="color: #009900; font-weight: bold;">function</span> setUp<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>:<span style="color: #5b7bff; font-weight: bold;">void</span>
		<span style="color: #000000;">&#123;</span>
			_class = <span style="color: #5b7bff; font-weight: bold;">new</span> SparkColorPickerKeyboardManager<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>;
		<span style="color: #000000;">&#125;</span>
&nbsp;
		<span style="color: #000000;">&#91;</span>After<span style="color: #000000;">&#93;</span>
		<span style="color: #5b7bff; font-weight: bold;">public</span> <span style="color: #009900; font-weight: bold;">function</span> tearDown<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>:<span style="color: #5b7bff; font-weight: bold;">void</span>
		<span style="color: #000000;">&#123;</span>
			_class = <span style="color: #5b7bff; font-weight: bold;">null</span>;
		<span style="color: #000000;">&#125;</span>
&nbsp;
		<span style="color: #000000;">&#91;</span>Test<span style="color: #000000;">&#93;</span>
		<span style="color: #5b7bff; font-weight: bold;">public</span> <span style="color: #009900; font-weight: bold;">function</span> testKeyUp<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>:<span style="color: #5b7bff; font-weight: bold;">void</span>
		<span style="color: #000000;">&#123;</span>
			Assert.<span style="color: #000000;">fail</span><span style="color: #000000;">&#40;</span> <span style="color: #ff0000;">&quot;Test Not implemented yet.&quot;</span> <span style="color: #000000;">&#41;</span>;
		<span style="color: #000000;">&#125;</span>
&nbsp;
		<span style="color: #000000;">&#91;</span>Test<span style="color: #000000;">&#93;</span>
		<span style="color: #5b7bff; font-weight: bold;">public</span> <span style="color: #009900; font-weight: bold;">function</span> testKeyDown<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>:<span style="color: #5b7bff; font-weight: bold;">void</span>
		<span style="color: #000000;">&#123;</span>
			Assert.<span style="color: #000000;">fail</span><span style="color: #000000;">&#40;</span> <span style="color: #ff0000;">&quot;Test Not implemented yet.&quot;</span> <span style="color: #000000;">&#41;</span>;
		<span style="color: #000000;">&#125;</span>
&nbsp;
		<span style="color: #000000;">&#91;</span>Test<span style="color: #000000;">&#93;</span>
		<span style="color: #5b7bff; font-weight: bold;">public</span> <span style="color: #009900; font-weight: bold;">function</span> testKeyLeft<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>:<span style="color: #5b7bff; font-weight: bold;">void</span>
		<span style="color: #000000;">&#123;</span>
			Assert.<span style="color: #000000;">fail</span><span style="color: #000000;">&#40;</span> <span style="color: #ff0000;">&quot;Test Not implemented yet.&quot;</span> <span style="color: #000000;">&#41;</span>;
		<span style="color: #000000;">&#125;</span>
&nbsp;
		<span style="color: #000000;">&#91;</span>Test<span style="color: #000000;">&#93;</span>
		<span style="color: #5b7bff; font-weight: bold;">public</span> <span style="color: #009900; font-weight: bold;">function</span> testKeyRight<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>:<span style="color: #5b7bff; font-weight: bold;">void</span>
		<span style="color: #000000;">&#123;</span>
			Assert.<span style="color: #000000;">fail</span><span style="color: #000000;">&#40;</span> <span style="color: #ff0000;">&quot;Test Not implemented yet.&quot;</span> <span style="color: #000000;">&#41;</span>;
		<span style="color: #000000;">&#125;</span>
&nbsp;
		<span style="color: #5b7bff; font-weight: bold;">private</span> <span style="color: #009900; font-weight: bold;">function</span> up<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span> : KeyboardEvent
		<span style="color: #000000;">&#123;</span>
			<span style="color: #5b7bff; font-weight: bold;">return</span> <span style="color: #5b7bff; font-weight: bold;">new</span> KeyboardEvent<span style="color: #000000;">&#40;</span> KeyboardEvent.<span style="color: #000000;">KEY_DOWN</span>, <span style="color: #5b7bff; font-weight: bold;">true</span>, <span style="color: #5b7bff; font-weight: bold;">false</span>, <span style="color: #000000;">0</span>, Keyboard.<span style="color: #000000;">UP</span> <span style="color: #000000;">&#41;</span>;
		<span style="color: #000000;">&#125;</span>
&nbsp;
		<span style="color: #5b7bff; font-weight: bold;">private</span> <span style="color: #009900; font-weight: bold;">function</span> down<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span> : KeyboardEvent
		<span style="color: #000000;">&#123;</span>
			<span style="color: #5b7bff; font-weight: bold;">return</span> <span style="color: #5b7bff; font-weight: bold;">new</span> KeyboardEvent<span style="color: #000000;">&#40;</span> KeyboardEvent.<span style="color: #000000;">KEY_DOWN</span>, <span style="color: #5b7bff; font-weight: bold;">true</span>, <span style="color: #5b7bff; font-weight: bold;">false</span>, <span style="color: #000000;">0</span>, Keyboard.<span style="color: #000000;">DOWN</span> <span style="color: #000000;">&#41;</span>;
		<span style="color: #000000;">&#125;</span>
		<span style="color: #5b7bff; font-weight: bold;">private</span> <span style="color: #009900; font-weight: bold;">function</span> left<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span> : KeyboardEvent
		<span style="color: #000000;">&#123;</span>
			<span style="color: #5b7bff; font-weight: bold;">return</span> <span style="color: #5b7bff; font-weight: bold;">new</span> KeyboardEvent<span style="color: #000000;">&#40;</span> KeyboardEvent.<span style="color: #000000;">KEY_DOWN</span>, <span style="color: #5b7bff; font-weight: bold;">true</span>, <span style="color: #5b7bff; font-weight: bold;">false</span>, <span style="color: #000000;">0</span>, Keyboard.<span style="color: #000000;">LEFT</span> <span style="color: #000000;">&#41;</span>;
		<span style="color: #000000;">&#125;</span>
		<span style="color: #5b7bff; font-weight: bold;">private</span> <span style="color: #009900; font-weight: bold;">function</span> right<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span> : KeyboardEvent
		<span style="color: #000000;">&#123;</span>
			<span style="color: #5b7bff; font-weight: bold;">return</span> <span style="color: #5b7bff; font-weight: bold;">new</span> KeyboardEvent<span style="color: #000000;">&#40;</span> KeyboardEvent.<span style="color: #000000;">KEY_DOWN</span>, <span style="color: #5b7bff; font-weight: bold;">true</span>, <span style="color: #5b7bff; font-weight: bold;">false</span>, <span style="color: #000000;">0</span>, Keyboard.<span style="color: #000000;">RIGHT</span> <span style="color: #000000;">&#41;</span>;
		<span style="color: #000000;">&#125;</span>
	<span style="color: #000000;">&#125;</span>
<span style="color: #000000;">&#125;</span>
&nbsp;</pre>
</div>
<p>You will notice that I have also included four helper methods at the bottom of the class to simulate keypress' for our tests.<br />
I have also added Assert.fail() to each test so that we can make sure they are working. I always do this just as a sanity check.<br />
We need to test all the boundaries of our keyboard manager so we should test negative numbers as well as numbers that go beyond our dataProvider length to ensure they return expected values. In Addition we need to make sure our grids from above return the expected results.</p>
<p>We will begin fleshing out our tests in part 2-b</p>
]]></content:encoded>
			<wfw:commentRss>http://www.betadesigns.co.uk/Blog/2010/07/10/converting-mx-component-to-spark-component-part-2-a/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Converting a MX component to a Spark Component.</title>
		<link>http://www.betadesigns.co.uk/Blog/2010/06/10/converting-a-mx-component-to-a-spark-component/</link>
		<comments>http://www.betadesigns.co.uk/Blog/2010/06/10/converting-a-mx-component-to-a-spark-component/#comments</comments>
		<pubDate>Wed, 09 Jun 2010 23:27:56 +0000</pubDate>
		<dc:creator>Anthony</dc:creator>
				<category><![CDATA[ActionScript]]></category>
		<category><![CDATA[Components]]></category>
		<category><![CDATA[Flex]]></category>
		<category><![CDATA[Test Driven Design]]></category>
		<category><![CDATA[Advanced Component Development]]></category>
		<category><![CDATA[Color Picker]]></category>
		<category><![CDATA[colorPicker]]></category>
		<category><![CDATA[converting MX to Spark]]></category>
		<category><![CDATA[mx components]]></category>
		<category><![CDATA[mx:colorpicker]]></category>
		<category><![CDATA[spark component architecture]]></category>
		<category><![CDATA[spark components]]></category>

		<guid isPermaLink="false">http://www.betadesigns.co.uk/Blog/?p=237</guid>
		<description><![CDATA[In this brief set of posts I wanted to document how to convert a simple MX component over to a Spark component. I have chosen to convert the MX ColorPicker because it is one of the components that Adobe hasn't moved over to the Spark framework yet as well as being the component that I [...]]]></description>
			<content:encoded><![CDATA[<p id="top" />In this brief set of posts I wanted to document how to convert a simple MX component over to a Spark component. I have chosen to convert the MX ColorPicker because it is one of the components that Adobe hasn't moved over to the Spark framework yet as well as being the component that I used to learn the Flex3 Framework. You can see the outcome and view the source of that in my previous posts from a couple of years ago <a href="http://www.betadesigns.co.uk/Blog/2008/06/24/custom-color-picker-source/">here</a> and <a href="http://www.betadesigns.co.uk/Blog/2008/05/19/custom-kuler-style-color-picker/">here</a></p>
<p>Below you can see the three components.<br />

<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000"
			id="fm_ExampleProject_1892758549"
			class="flashmovie"
			width="500"
			height="350">
	<param name="movie" value="http://www.betadesigns.co.uk/Examples/posts/ConvertingMXtoSparkComponent/SparkColorPicker/ExampleProject.swf" />
	<param name="wmode" value="transparent" />
	<!--[if !IE]>-->
	<object	type="application/x-shockwave-flash"
			data="http://www.betadesigns.co.uk/Examples/posts/ConvertingMXtoSparkComponent/SparkColorPicker/ExampleProject.swf"
			name="fm_ExampleProject_1892758549"
			width="500"
			height="350">
		<param name="wmode" value="transparent" />
	<!--<![endif]-->
		<br />
The Spark component does all the stuff the old MX one does like keyboard movement, selectedIndex, selectedColor, colorLabel, etc.. In addition I also added the ability to set/get the selectedItem and dispatching indexChange events.</p>
<p>To begin with lets look at what the current color picker does.<span id="more-237"></span></p>
<p>From the <a href="http://docs.brajeshwar.com/as3/mx/controls/ColorPicker.html">docs</a> we can see that the color picker has the following properties and events. We are ignoring the <b>Styles</b> because these will be handled by the skins and not the components. I have also decided that the TextField is part of the Skin and not the responsibility of the component so we will be ignoring the <b>showTextField</b> property.</p>
<pre class="flex">&nbsp;
&lt;mx:ColorPicker
    Properties
    colorField=<span style="color: #ff0000;">&quot;color&quot;</span>
    labelField=<span style="color: #ff0000;">&quot;label&quot;</span>
    selectedColor=<span style="color: #ff0000;">&quot;0x000000&quot;</span>
    selectedIndex=<span style="color: #ff0000;">&quot;0&quot;</span>
    showTextField=<span style="color: #ff0000;">&quot;true|false&quot;</span>
&nbsp;
    Styles...
&nbsp;
    <span style="color: #000000;">Events</span>
    change=<span style="color: #ff0000;">&quot;No default&quot;</span>
    close=<span style="color: #ff0000;">&quot;No default&quot;</span>
    enter=<span style="color: #ff0000;">&quot;No default&quot;</span>
    itemRollOut=<span style="color: #ff0000;">&quot;No default&quot;</span>
    itemRollOver=<span style="color: #ff0000;">&quot;No default&quot;</span>
    open=<span style="color: #ff0000;">&quot;No default&quot;</span>
    /&gt;
&nbsp;</pre>
<p>Next if we look at the default MX ColorPicker we can see that there appears to only be 2 visual elements the preview panel and the drop down panel. So we know we need two classes one for each of them and one more to hold them together the actual SparkColorPicker Class. This classes skin will simply hold the other skin parts together and be used for managing the other two classes.<br />
To begin with lets start by building the simplest item so that we can get something on the screen straight away.<br />
We know it should should take a data item and that we should probably pass the colorField and labelField properties to it from the main class incase they are required.<br />
So we have our simple ISparkColorPreviewPanel Interface ( comments omitted but are in the included files )</p>
<div class="scroll">
<pre class="flex">&nbsp;
<span style="color: #5b7bff; font-weight: bold;">public</span> interface ISparkColorPreviewPanel <span style="color: #5b7bff; font-weight: bold;">extends</span> IEventDispatcher
<span style="color: #000000;">&#123;</span>
	<span style="color: #009900; font-weight: bold;">function</span> <span style="color: #5b7bff; font-weight: bold;">get</span> selectedColor<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span> : uint;
	<span style="color: #009900; font-weight: bold;">function</span> <span style="color: #5b7bff; font-weight: bold;">set</span> selectedColor<span style="color: #000000;">&#40;</span> value : uint <span style="color: #000000;">&#41;</span> : <span style="color: #5b7bff; font-weight: bold;">void</span>;
&nbsp;
	<span style="color: #009900; font-weight: bold;">function</span> <span style="color: #5b7bff; font-weight: bold;">get</span> colorField<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span> : String;
	<span style="color: #009900; font-weight: bold;">function</span> <span style="color: #5b7bff; font-weight: bold;">set</span> colorField<span style="color: #000000;">&#40;</span> value : String <span style="color: #000000;">&#41;</span> : <span style="color: #5b7bff; font-weight: bold;">void</span>;
&nbsp;
	<span style="color: #009900; font-weight: bold;">function</span> <span style="color: #5b7bff; font-weight: bold;">get</span> labelField<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span> : String;
	<span style="color: #009900; font-weight: bold;">function</span> <span style="color: #5b7bff; font-weight: bold;">set</span> labelField<span style="color: #000000;">&#40;</span> value : String <span style="color: #000000;">&#41;</span> : <span style="color: #5b7bff; font-weight: bold;">void</span>;
&nbsp;
	<span style="color: #009900; font-weight: bold;">function</span> <span style="color: #5b7bff; font-weight: bold;">get</span> data<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span> : Object;
	<span style="color: #009900; font-weight: bold;">function</span> <span style="color: #5b7bff; font-weight: bold;">set</span> data<span style="color: #000000;">&#40;</span> value : Object <span style="color: #000000;">&#41;</span> : <span style="color: #5b7bff; font-weight: bold;">void</span>;
<span style="color: #000000;">&#125;</span>
&nbsp;</pre>
</div>
<p>I would normally start writing unit tests for this interface now but as this is a rather small class that consists of only getters and setters I won't bother for this example. Lets just write the concrete class.</p>
<div class="scrolllarge">
<pre class="flex">&nbsp;
<span style="color: #5b7bff; font-weight: bold;">public</span> <span style="color: #9e12cf; font-weight: bold;">class</span> SparkColorPickerPreviewPanel <span style="color: #5b7bff; font-weight: bold;">extends</span> SkinnableComponent
		<span style="color: #5b7bff; font-weight: bold;">implements</span> ISparkColorPreviewPanel
<span style="color: #000000;">&#123;</span>
&nbsp;
	<span style="color: #5b7bff; font-weight: bold;">public</span> <span style="color: #009900; font-weight: bold;">function</span> SparkColorPickerPreviewPanel<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>
	<span style="color: #000000;">&#123;</span>
		<span style="color: #5b7bff; font-weight: bold;">super</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>;
		init<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>;
	<span style="color: #000000;">&#125;</span>
&nbsp;
	<span style="color: #5b7bff; font-weight: bold;">private</span> <span style="color: #b7cfe7; font-weight: bold;">var</span> _selectedColor : uint = 0x000000;
&nbsp;
	<span style="color: #000000;">&#91;</span>Bindable<span style="color: #000000;">&#93;</span>
	<span style="color: #3f5fc4; font-style: italic;">/**
	 * @inheritDoc
	 */</span>
	<span style="color: #5b7bff; font-weight: bold;">public</span> <span style="color: #009900; font-weight: bold;">function</span> <span style="color: #5b7bff; font-weight: bold;">get</span> selectedColor<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span> : uint
	<span style="color: #000000;">&#123;</span>
		<span style="color: #5b7bff; font-weight: bold;">return</span> _selectedColor;
	<span style="color: #000000;">&#125;</span>
&nbsp;
	<span style="color: #5b7bff; font-weight: bold;">public</span> <span style="color: #009900; font-weight: bold;">function</span> <span style="color: #5b7bff; font-weight: bold;">set</span> selectedColor<span style="color: #000000;">&#40;</span> value : uint <span style="color: #000000;">&#41;</span> : <span style="color: #5b7bff; font-weight: bold;">void</span>
	<span style="color: #000000;">&#123;</span>
		_selectedColor = value;
		invalidateProperties<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>;
	<span style="color: #000000;">&#125;</span>
&nbsp;
	<span style="color: #5b7bff; font-weight: bold;">private</span> <span style="color: #b7cfe7; font-weight: bold;">var</span> _colorField : String;
&nbsp;
	<span style="color: #3f5fc4; font-style: italic;">/**
	 * @inheritDoc
	 */</span>
	<span style="color: #5b7bff; font-weight: bold;">public</span> <span style="color: #009900; font-weight: bold;">function</span> <span style="color: #5b7bff; font-weight: bold;">get</span> colorField<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>:String
	<span style="color: #000000;">&#123;</span>
		<span style="color: #5b7bff; font-weight: bold;">return</span> _colorField;
	<span style="color: #000000;">&#125;</span>
&nbsp;
	<span style="color: #5b7bff; font-weight: bold;">public</span> <span style="color: #009900; font-weight: bold;">function</span> <span style="color: #5b7bff; font-weight: bold;">set</span> colorField<span style="color: #000000;">&#40;</span>value:String<span style="color: #000000;">&#41;</span>:<span style="color: #5b7bff; font-weight: bold;">void</span>
	<span style="color: #000000;">&#123;</span>
		_colorField = value;
		invalidateProperties<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>;
	<span style="color: #000000;">&#125;</span>
&nbsp;
	<span style="color: #5b7bff; font-weight: bold;">private</span> <span style="color: #b7cfe7; font-weight: bold;">var</span> _labelField : String;
&nbsp;
	<span style="color: #3f5fc4; font-style: italic;">/**
	 * @inheritDoc
	 */</span>
	<span style="color: #5b7bff; font-weight: bold;">public</span> <span style="color: #009900; font-weight: bold;">function</span> <span style="color: #5b7bff; font-weight: bold;">get</span> labelField<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>:String
	<span style="color: #000000;">&#123;</span>
		<span style="color: #5b7bff; font-weight: bold;">return</span> _labelField;
	<span style="color: #000000;">&#125;</span>
&nbsp;
	<span style="color: #5b7bff; font-weight: bold;">public</span> <span style="color: #009900; font-weight: bold;">function</span> <span style="color: #5b7bff; font-weight: bold;">set</span> labelField<span style="color: #000000;">&#40;</span>value:String<span style="color: #000000;">&#41;</span>:<span style="color: #5b7bff; font-weight: bold;">void</span>
	<span style="color: #000000;">&#123;</span>
		_labelField = value;
		invalidateProperties<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>;
	<span style="color: #000000;">&#125;</span>
&nbsp;
	<span style="color: #5b7bff; font-weight: bold;">private</span> <span style="color: #b7cfe7; font-weight: bold;">var</span> _data : Object;
&nbsp;
	<span style="color: #000000;">&#91;</span>Bindable<span style="color: #000000;">&#93;</span>
	<span style="color: #3f5fc4; font-style: italic;">/**
	 * @inheritDoc
	 */</span>
	<span style="color: #5b7bff; font-weight: bold;">public</span> <span style="color: #009900; font-weight: bold;">function</span> <span style="color: #5b7bff; font-weight: bold;">get</span> data<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>:Object
	<span style="color: #000000;">&#123;</span>
		<span style="color: #5b7bff; font-weight: bold;">return</span> _data;
	<span style="color: #000000;">&#125;</span>
&nbsp;
	<span style="color: #5b7bff; font-weight: bold;">public</span> <span style="color: #009900; font-weight: bold;">function</span> <span style="color: #5b7bff; font-weight: bold;">set</span> data<span style="color: #000000;">&#40;</span>value:Object<span style="color: #000000;">&#41;</span>:<span style="color: #5b7bff; font-weight: bold;">void</span>
	<span style="color: #000000;">&#123;</span>
		_data = value;
		invalidateProperties<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>;
	<span style="color: #000000;">&#125;</span>
&nbsp;
	<span style="color: #009900; font-style: italic;">//-------------------------------------------------------</span>
	<span style="color: #009900; font-style: italic;">// PRIVATE METHODS</span>
	<span style="color: #009900; font-style: italic;">//-------------------------------------------------------</span>
&nbsp;
	<span style="color: #5b7bff; font-weight: bold;">private</span> <span style="color: #009900; font-weight: bold;">function</span> init<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span> : <span style="color: #5b7bff; font-weight: bold;">void</span>
	<span style="color: #000000;">&#123;</span>
		buttonMode = <span style="color: #5b7bff; font-weight: bold;">true</span>;
		mouseEnabled = <span style="color: #5b7bff; font-weight: bold;">true</span>;
		useHandCursor = <span style="color: #5b7bff; font-weight: bold;">true</span>;
	<span style="color: #000000;">&#125;</span>
<span style="color: #000000;">&#125;</span>
&nbsp;</pre>
</div>
<p>This class doesn't really do anything except hold data and setup some default values so that it will act like a button it's all pretty self explanatory.</p>
<p>The next class we have to make is the default MX style preview panel as follows.</p>
<div class="scrolllarge" >
<pre class="flex"><ol start="2"><li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp;</div></li><li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp;</div></li><li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&lt;s:Skin xmlns:fx=<span style="color: #ff0000;">&quot;http://ns.adobe.com/mxml/2009&quot;</span></div></li><li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">		xmlns:s=<span style="color: #ff0000;">&quot;library://ns.adobe.com/flex/spark&quot;</span></div></li><li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">		&gt;</div></li><li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">	&lt;!-- host component --&gt;</div></li><li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">	&lt;fx:Metadata&gt;</div></li><li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">		<span style="color: #000000;">&#91;</span>HostComponent<span style="color: #000000;">&#40;</span><span style="color: #ff0000;">&quot;co.uk.betadesigns.components.colorpicker.SparkColorPickerPreviewPanel&quot;</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">&#93;</span></div></li><li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">	&lt;/fx:Metadata&gt;</div></li><li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp;</div></li><li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">	&lt;fx:Script&gt;</div></li><li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">		&lt;!<span style="color: #000000;">&#91;</span>CDATA<span style="color: #000000;">&#91;</span></div></li><li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp;</div></li><li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">			<span style="color: #000000;">&#91;</span>Bindable<span style="color: #000000;">&#93;</span></div></li><li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">			<span style="color: #5b7bff; font-weight: bold;">public</span> <span style="color: #b7cfe7; font-weight: bold;">var</span> borderWidth : Number = <span style="color: #000000;">3</span>;</div></li><li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp;</div></li><li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">			<span style="color: #000000;">&#91;</span>Bindable<span style="color: #000000;">&#93;</span></div></li><li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">			<span style="color: #5b7bff; font-weight: bold;">public</span> <span style="color: #b7cfe7; font-weight: bold;">var</span> arrowBorderWidth : Number = <span style="color: #000000;">2</span>;</div></li><li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp;</div></li><li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">			<span style="color: #000000;">&#91;</span>Bindable<span style="color: #000000;">&#93;</span></div></li><li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">			<span style="color: #5b7bff; font-weight: bold;">public</span> <span style="color: #b7cfe7; font-weight: bold;">var</span> panelWidth : Number = <span style="color: #000000;">22</span>;</div></li><li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp;</div></li><li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">			<span style="color: #000000;">&#91;</span>Bindable<span style="color: #000000;">&#93;</span></div></li><li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">			<span style="color: #5b7bff; font-weight: bold;">public</span> <span style="color: #b7cfe7; font-weight: bold;">var</span> panelHeight : Number = <span style="color: #000000;">22</span>;</div></li><li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp;</div></li><li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">		<span style="color: #000000;">&#93;</span><span style="color: #000000;">&#93;</span>&gt;</div></li><li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">	&lt;/fx:Script&gt;</div></li><li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp;</div></li><li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">	&lt;s:Group&gt;</div></li><li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">		&lt;s:Graphic x=<span style="color: #ff0000;">&quot;0&quot;</span> y=<span style="color: #ff0000;">&quot;0&quot;</span>&gt;</div></li><li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">			&lt;!--BORDER--&gt;</div></li><li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">			&lt;s:Rect height=<span style="color: #ff0000;">&quot;{ panelWidth }&quot;</span> width=<span style="color: #ff0000;">&quot;{ panelHeight }&quot;</span>&gt;</div></li><li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">				&lt;s:stroke&gt;</div></li><li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">					&lt;s:SolidColorStroke color=<span style="color: #ff0000;">&quot;0x000000&quot;</span> weight=<span style="color: #ff0000;">&quot;1&quot;</span>/&gt;</div></li><li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">				&lt;/s:stroke&gt;</div></li><li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">				&lt;s:fill&gt;</div></li><li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">					&lt;s:LinearGradient rotation=<span style="color: #ff0000;">&quot;90&quot;</span>&gt;</div></li><li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">						&lt;s:entries&gt;</div></li><li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">							&lt;s:GradientEntry color=<span style="color: #ff0000;">&quot;0xFFFFFF&quot;</span> ratio=<span style="color: #ff0000;">&quot;0.00&quot;</span> alpha=<span style="color: #ff0000;">&quot;1&quot;</span>/&gt;</div></li><li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">							&lt;s:GradientEntry color=<span style="color: #ff0000;">&quot;0xCCCCCC&quot;</span> ratio=<span style="color: #ff0000;">&quot;0.33&quot;</span> alpha=<span style="color: #ff0000;">&quot;1&quot;</span>/&gt;</div></li><li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">							&lt;s:GradientEntry color=<span style="color: #ff0000;">&quot;0x8E8E8E&quot;</span> ratio=<span style="color: #ff0000;">&quot;0.66&quot;</span> alpha=<span style="color: #ff0000;">&quot;1&quot;</span>/&gt;</div></li><li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">						&lt;/s:entries&gt;</div></li><li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">					&lt;/s:LinearGradient&gt;</div></li><li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">				&lt;/s:fill&gt;</div></li><li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">			&lt;/s:Rect&gt;</div></li><li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">			&lt;!--INNER COLOR--&gt;</div></li><li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">			&lt;s:Rect</div></li><li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">				id=<span style="color: #ff0000;">&quot;innerColor&quot;</span></div></li><li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">				x=<span style="color: #ff0000;">&quot;{ borderWidth }&quot;</span> y=<span style="color: #ff0000;">&quot;{ borderWidth }&quot;</span></div></li><li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">				height=<span style="color: #ff0000;">&quot;{ panelHeight - ( borderWidth * 2 ) }&quot;</span></div></li><li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">				width=<span style="color: #ff0000;">&quot;{ panelWidth - ( borderWidth * 2 ) }&quot;</span>&gt;</div></li><li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">				&lt;s:fill&gt;</div></li><li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">					&lt;s:SolidColor color=<span style="color: #ff0000;">&quot;{ hostComponent.selectedColor }&quot;</span>/&gt;</div></li><li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">				&lt;/s:fill&gt;</div></li><li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">			&lt;/s:Rect&gt;</div></li><li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">			&lt;!--BOTTOM RIGHT ARROW BOX--&gt;</div></li><li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">			&lt;s:Rect</div></li><li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">				id=<span style="color: #ff0000;">&quot;arrowBox&quot;</span></div></li><li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">				x=<span style="color: #ff0000;">&quot;{ panelWidth - ( borderWidth * 3 ) }&quot;</span> y=<span style="color: #ff0000;">&quot;{ panelHeight - ( borderWidth * 3 ) }&quot;</span></div></li><li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">				height=<span style="color: #ff0000;">&quot;{ borderWidth * 3 }&quot;</span> width=<span style="color: #ff0000;">&quot;{ borderWidth * 3 }&quot;</span>&gt;</div></li><li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">				&lt;s:fill&gt;</div></li><li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">					&lt;s:LinearGradient rotation=<span style="color: #ff0000;">&quot;90&quot;</span>&gt;</div></li><li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">						&lt;s:entries&gt;</div></li><li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">							&lt;s:GradientEntry color=<span style="color: #ff0000;">&quot;0xCCCCCC&quot;</span> ratio=<span style="color: #ff0000;">&quot;0.33&quot;</span> alpha=<span style="color: #ff0000;">&quot;1&quot;</span>/&gt;</div></li><li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">							&lt;s:GradientEntry color=<span style="color: #ff0000;">&quot;0x8E8E8E&quot;</span> ratio=<span style="color: #ff0000;">&quot;0.66&quot;</span> alpha=<span style="color: #ff0000;">&quot;1&quot;</span>/&gt;</div></li><li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">						&lt;/s:entries&gt;</div></li><li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">					&lt;/s:LinearGradient&gt;</div></li><li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">				&lt;/s:fill&gt;</div></li><li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">			&lt;/s:Rect&gt;</div></li><li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">			&lt;!--ARROW --&gt;</div></li><li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">			&lt;s:Path data=<span style="color: #ff0000;">&quot;M { arrowBox.x + arrowBorderWidth } { arrowBox.y + arrowBorderWidth }</span></div></li><li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #ff0000;">					L { arrowBox.x + arrowBox.width - arrowBorderWidth } { arrowBox.y + arrowBorderWidth }</span></div></li><li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #ff0000;">					L { arrowBox.x + ( arrowBox.width / 2 ) } { arrowBox.y + ( arrowBox.height - ( arrowBorderWidth * 1.5 ) ) }</span></div></li><li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #ff0000;">					L { arrowBox.x + arrowBorderWidth } { arrowBox.y + arrowBorderWidth }</span></div></li><li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #ff0000;">					&quot;</span>&gt;</div></li><li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">				&lt;s:stroke&gt;</div></li><li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">					&lt;s:SolidColorStroke id=<span style="color: #ff0000;">&quot;arrowStroke&quot;</span> color=<span style="color: #ff0000;">&quot;0x000000&quot;</span> weight=<span style="color: #ff0000;">&quot;1&quot;</span>/&gt;</div></li><li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">				&lt;/s:stroke&gt;</div></li><li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">				&lt;s:fill&gt;</div></li><li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">					&lt;s:SolidColor color=<span style="color: #ff0000;">&quot;0x000000&quot;</span>/&gt;</div></li><li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">				&lt;/s:fill&gt;</div></li><li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">			&lt;/s:Path&gt;</div></li><li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">			&lt;!--INNER BORDER--&gt;</div></li><li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">			&lt;s:Path data=<span style="color: #ff0000;">&quot;M { innerColor.x } { innerColor.y }</span></div></li><li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #ff0000;">					L { innerColor.x + innerColor.width } { innerColor.y }</span></div></li><li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #ff0000;">					L { innerColor.x + innerColor.width } { arrowBox.y - arrowStroke.weight }</span></div></li><li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #ff0000;">					L { arrowBox.x - arrowStroke.weight } { arrowBox.y - arrowStroke.weight }</span></div></li><li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #ff0000;">					L { arrowBox.x - arrowStroke.weight } { innerColor.y + innerColor.height }</span></div></li><li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #ff0000;">					L { innerColor.x } { innerColor.y + innerColor.height }</span></div></li><li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #ff0000;">					L { innerColor.x } { innerColor.y }</span></div></li><li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #ff0000;">					&quot;</span>&gt;</div></li><li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">				&lt;s:stroke&gt;</div></li><li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">					&lt;s:SolidColorStroke color=<span style="color: #ff0000;">&quot;0x000000&quot;</span> weight=<span style="color: #ff0000;">&quot;1&quot;</span> alpha=<span style="color: #ff0000;">&quot;0.5&quot;</span>/&gt;</div></li><li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">				&lt;/s:stroke&gt;</div></li><li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">			&lt;/s:Path&gt;</div></li><li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp;</div></li><li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">		&lt;/s:Graphic&gt;</div></li><li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">		&lt;s:filters&gt;</div></li><li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">			&lt;s:DropShadowFilter</div></li><li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">				distance=<span style="color: #ff0000;">&quot;1&quot;</span></div></li><li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">				/&gt;</div></li><li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">		&lt;/s:filters&gt;</div></li><li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">	&lt;/s:Group&gt;</div></li><li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&lt;/s:Skin&gt;</div></li><li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp;</div></li></ol></pre>
</div>
<p>In this class we are simply setting up the way in which the preview should look using the new Group and Graphic elements. The important things here are that we set the HostComponent to our custom SparkColorPickerPreview class. And that we link our Fill to our host component on the following line.</p>
<div class="scroll">
<pre class="flex"><ol start="51"><li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp;</div></li><li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&lt;s:fill&gt;</div></li><li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">    &lt;s:SolidColor color=<span style="color: #ff0000;">&quot;{ hostComponent.selectedColor }&quot;</span>/&gt;</div></li><li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&lt;/s:fill&gt;</div></li><li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp;</div></li></ol></pre>
</div>
<p>That allows our color to be updated everytime the color is set on the hostComponent.</p>
<p>We can test this by simply putting the following code in an example project.</p>
<div class="scroll">
<pre class="flex">&nbsp;
&lt;colorpicker:SparkColorPickerPreviewPanel selectedColor=<span style="color: #ff0000;">&quot;0xFF0000&quot;</span> /&gt;
&nbsp;</pre>
</div>
<p>I have set my version up with a default.css file and skin so I don't need to reference one here if you want to know how to do that then see this post on <a href="http://www.betadesigns.co.uk/Blog/2010/05/14/default-skin-for-custom-flashbuilder-components/">Default Skin for custom FlashBuilder components.</a> otherwise simply add the skin file as the skinClass like follows.</p>
<div class="scroll">
<pre class="flex">&nbsp;
&lt;colorpicker:SparkColorPickerPreviewPanel selectedColor=<span style="color: #ff0000;">&quot;0xFF0000&quot;</span>
skinClass=<span style="color: #ff0000;">&quot;co.uk.betadesigns.components.colorpicker.skins.mx.MXPreviewSkin&quot;</span>/&gt;
&nbsp;</pre>
</div>
<p>In the next post I will walk through testing and creating a SparkColorPickerDropDownPanel, after that we will look at creating the MxDropDownPanelSkin and a keyboardManager for handling input from the user to move around the dataprovider. Once we have our PreviewPanel and DropDownPanel complete we will then move onto creating the SparkColorPicker class to pull it all together with the skins. Or you can just download the source files here and work your way through them.<br />
I hope this post was useful and I appreciate any comments, suggestions or criticism.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.betadesigns.co.uk/Blog/2010/06/10/converting-a-mx-component-to-a-spark-component/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>Custom FlashBuilder Component Views</title>
		<link>http://www.betadesigns.co.uk/Blog/2010/05/06/custom-flashbuilder-component-views/</link>
		<comments>http://www.betadesigns.co.uk/Blog/2010/05/06/custom-flashbuilder-component-views/#comments</comments>
		<pubDate>Wed, 05 May 2010 23:34:48 +0000</pubDate>
		<dc:creator>Anthony</dc:creator>
				<category><![CDATA[ActionScript]]></category>
		<category><![CDATA[Components]]></category>
		<category><![CDATA[Flex]]></category>
		<category><![CDATA[4]]></category>
		<category><![CDATA[categories]]></category>
		<category><![CDATA[custom components]]></category>
		<category><![CDATA[custom views]]></category>
		<category><![CDATA[design.xml]]></category>
		<category><![CDATA[flashbuilder]]></category>
		<category><![CDATA[manifest.xml]]></category>

		<guid isPermaLink="false">http://www.betadesigns.co.uk/Blog/?p=198</guid>
		<description><![CDATA[I recently discovered that you can create custom components that can appear under your own company/personal folder inside Flash/Flexbuilder design view. Normally any custom component you create will appear under the Custom folder in the Components View and well thats not very good for branding now is it. In addition you also get an actual [...]]]></description>
			<content:encoded><![CDATA[<p id="top" />I recently discovered that you can create custom components that can appear under your own company/personal folder inside Flash/Flexbuilder design view. Normally any custom component you create will appear under the Custom folder in the Components View and well thats not very good for branding now is it. In addition you also get an actual size representation of your component in Design view rather than just an empty box outline. For example the first image is the default and the second the custom.<span id="more-198"></span><br />
<a href="http://www.betadesigns.co.uk/Examples/posts/198/ExampleLibrary.zip">Project FIles</a><br />
<strong>Image 1</strong><br />
<img src="http://www.betadesigns.co.uk/Examples/posts/198/NonCustom.png" alt="Non Custom Component" /><br />
<strong>Image 2</strong><br />
<img src="http://www.betadesigns.co.uk/Examples/posts/198/Custom.png" alt="Custom Component" /></p>
<p>To begin you need to move your custom component into a FlexLibrary.</p>
<p><strong>Adding an Icon to your custom component</strong></p>
<p>Once inside the library if you want to include a custom Icon with your component to accompany it in the Component Explorer simply place an icon in the same folder as the Component. For example my component is in the following package structure.<br />
<img src="http://www.betadesigns.co.uk/Examples/posts/198/PackageStructure.png" alt="Package Structure" /></p>
<p>Next add the following metaData to your component file.</p>
<p><strong>ActionScript </strong></p>
<pre class="flex">&nbsp;
<span style="color: #000000;">&#91;</span>IconFile<span style="color: #000000;">&#40;</span><span style="color: #ff0000;">&quot;Icon.png&quot;</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">&#93;</span>
<span style="color: #5b7bff; font-weight: bold;">public</span> <span style="color: #9e12cf; font-weight: bold;">class</span> ExampleComponent
<span style="color: #000000;">&#123;</span>
   ...
<span style="color: #000000;">&#125;</span>
&nbsp;</pre>
<p>or if it is an <strong>MXML</strong> component</p>
<pre class="flex">&nbsp;
&lt;fx:Metadata&gt;
&nbsp;
<span style="color: #000000;">&#91;</span>IconFile<span style="color: #000000;">&#40;</span><span style="color: #ff0000;">&quot;Icon.png&quot;</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">&#93;</span>
&nbsp;
&lt;/fx:Metadata&gt;
&nbsp;</pre>
<p>The next step is to create a design.xml file.<br />
<strong>Design.xml</strong></p>
<pre class="flex">&nbsp;
&lt;?xml version=<span style="color: #ff0000;">&quot;1.0&quot;</span> ?&gt;
&lt;design&gt;
&nbsp;
&lt;/design&gt;
&nbsp;</pre>
<p>First we add the namespace we would like to appear for our custom component when it is imported into mxml views.</p>
<pre class="flex">&nbsp;
	&lt;namespaces&gt;
&nbsp;
		&lt;namespace
			prefix=<span style="color: #ff0000;">&quot;betadesigns&quot;</span>
			uri=<span style="color: #ff0000;">&quot;http://www.betadesigns.co.uk/Blog&quot;</span>
			/&gt;
&nbsp;
	&lt;/namespaces&gt;
&nbsp;</pre>
<p>The prefix value is what will appear before your component name so for example a spark button has
<pre class="flex">&lt;s:button&gt;</pre>
<p> so our custom component would be
<pre class="flex">&lt;betadesigns:button&gt;</pre>
<p> Next we need to add the folder category we would like to create in the Component view.</p>
<pre class="flex">&nbsp;
&nbsp;
	&lt;categories&gt;
		&lt;category
			id=<span style="color: #ff0000;">&quot;beta&quot;</span>
			label=<span style="color: #ff0000;">&quot;BetaDesigns Components&quot;</span>
			defaultExpand=<span style="color: #ff0000;">&quot;true&quot;</span> /&gt;
	&lt;/categories&gt;
&nbsp;</pre>
<p>I have chosen to give my folder the name BetaDesigns Components, the id value will be used as a reference so that we can tell each component which Category folder we want to place it into.</p>
<p>Finally for the design.xml file we need to add one more node the components node.</p>
<pre class="flex">&lt;components&gt;
		&lt;component
			name=<span style="color: #ff0000;">&quot;loginComponent&quot;</span>
			namespace=<span style="color: #ff0000;">&quot;betadesigns&quot;</span>
			category=<span style="color: #ff0000;">&quot;beta&quot;</span>
			displayName=<span style="color: #ff0000;">&quot;Login Component&quot;</span> /&gt;
	&lt;/components&gt;</pre>
<p>Inside the components node we add our custom component giving it an identifying name ( this doesn't  have to be the same as the mxml file name ) tell it which namespace to use here i am using my betadesigns namespace provided above. we then set which category we wish to include it in and give it a display name.<br />
That is all that is needed for our design.xml file.</p>
<p>We then need one more file the *-manifest.xml this file can be called anything you like but it tends to be appended with the suffix -manifest so that it can be easily identified.</p>
<pre class="flex">&nbsp;
&lt;?xml version=<span style="color: #ff0000;">&quot;1.0&quot;</span>?&gt;
&lt;componentpackage&gt;
    &lt;component
    	id=<span style="color: #ff0000;">&quot;loginComponent&quot;</span>
    	<span style="color: #9e12cf; font-weight: bold;">class</span>=<span style="color: #ff0000;">&quot;co.uk.betadesigns.components.example.ExampleComponent&quot;</span>
    	/&gt;
&lt;/componentpackage&gt;
&nbsp;</pre>
<p>This manifest file contains the id to the item in the design.xml file as well as the absolute path to the file to map to that component id. As you can see from the above i have a component in my library called ExampleComponent however i want this component to appear in the Components viewer as my login component so i give it the id=loginComponent in the manifest file which points to the name=loginComponent in the design.xml file.<br />
The final piece of the puzzle is to open up the library preferences>Flex Library Compiler<br />
<img src="http://www.betadesigns.co.uk/Examples/posts/198/Prefs.png" alt="Flex Library Compiler" /><br />
 </p>
<p>under the namespace url place the same namespace your defined in your design.xml file.<br />
under manifrest file choose your *-manifest.xml file.</p>
<p>Next choose&gt;Flex Library Build Path&gt;Assets<br />
<img src="http://www.betadesigns.co.uk/Examples/posts/198/Assets.png" alt="Flex Library Build Path" /><br />
Make sure your design.xml file and icon file if you are including one are selected.<br />
There is no need to include the -manifest.xml file as it is automatically compiled into the swc by adding it to our Compiler prefs.</p>
<p>Now if you reference your swc in a new project you should see your components appear under your custom folder with your custom icons.</p>
<p>[Icons not appearing issue]<br />
If this happens then try restarting Eclipse/FlashBuilder as it doesn't seem to pick up the changes everytime.</p>
<p><a href="http://www.betadesigns.co.uk/Examples/posts/198/ExampleLibrary.zip">Project FIles</a></p>
]]></content:encoded>
			<wfw:commentRss>http://www.betadesigns.co.uk/Blog/2010/05/06/custom-flashbuilder-component-views/feed/</wfw:commentRss>
		<slash:comments>5</slash:comments>
		</item>
		<item>
		<title>Binary Clock</title>
		<link>http://www.betadesigns.co.uk/Blog/2009/10/16/binary-clock/</link>
		<comments>http://www.betadesigns.co.uk/Blog/2009/10/16/binary-clock/#comments</comments>
		<pubDate>Fri, 16 Oct 2009 22:56:33 +0000</pubDate>
		<dc:creator>Anthony</dc:creator>
				<category><![CDATA[ActionScript]]></category>
		<category><![CDATA[Personal]]></category>
		<category><![CDATA[experiments]]></category>
		<category><![CDATA[binary]]></category>
		<category><![CDATA[binary clock]]></category>
		<category><![CDATA[bits]]></category>
		<category><![CDATA[bytes]]></category>
		<category><![CDATA[Flex]]></category>
		<category><![CDATA[spark]]></category>
		<category><![CDATA[spark skins]]></category>

		<guid isPermaLink="false">http://www.betadesigns.co.uk/Blog/?p=118</guid>
		<description><![CDATA[I have been looking into bits, bytes and bit shifting a lot recently so I thought I would quickly make a small binary clock to help burn it into my mind. In addition it also gave me the chance to experiment with the spark skinning. Below is the result. Not pretty I know but thats [...]]]></description>
			<content:encoded><![CDATA[<p id="top" />I have been looking into bits, bytes and bit shifting a lot recently so I thought I would quickly make a small binary clock to help burn it into my mind. In addition it also gave me the chance to experiment with the spark skinning. Below is the result. Not pretty I know but thats what the skinning is for.</p>
<p>[kml_flashembed publishmethod="static" fversion="10.0.0" movie="http://www.betadesigns.co.uk/Examples/BinaryClock/TestProject.swf" width="169" height="92" targetclass="flashmovie"]</p>
<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><a href="http://www.betadesigns.co.uk/Examples/BinaryClock/srcview/">Full source</a></p>
]]></content:encoded>
			<wfw:commentRss>http://www.betadesigns.co.uk/Blog/2009/10/16/binary-clock/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Forcing the Browser to crash using ActionScript</title>
		<link>http://www.betadesigns.co.uk/Blog/2009/09/28/forcing-the-browser-to-crash-using-actionscript/</link>
		<comments>http://www.betadesigns.co.uk/Blog/2009/09/28/forcing-the-browser-to-crash-using-actionscript/#comments</comments>
		<pubDate>Mon, 28 Sep 2009 22:59:43 +0000</pubDate>
		<dc:creator>Anthony</dc:creator>
				<category><![CDATA[ActionScript]]></category>
		<category><![CDATA[Flex]]></category>

		<guid isPermaLink="false">http://www.betadesigns.co.uk/Blog/?p=84</guid>
		<description><![CDATA[I just discovered this little trick, I'm not sure how useful it is but it works.
Simply create a class that throws an error in the constructor. This will cause the browser to crash and close.
&#160;
&#160;
package
&#123;
   public class BrowserCrasher
   &#123;
      public function BrowserCrasher&#40; &#41;
    [...]]]></description>
			<content:encoded><![CDATA[<p id="top" />I just discovered this little trick, I'm not sure how useful it is but it works.</p>
<p>Simply create a class that throws an error in the constructor. This will cause the browser to crash and close.</p>
<pre class="flex">&nbsp;
&nbsp;
<span style="color: #9e12cf; font-weight: bold;">package</span>
<span style="color: #000000;">&#123;</span>
   <span style="color: #5b7bff; font-weight: bold;">public</span> <span style="color: #9e12cf; font-weight: bold;">class</span> BrowserCrasher
   <span style="color: #000000;">&#123;</span>
      <span style="color: #5b7bff; font-weight: bold;">public</span> <span style="color: #009900; font-weight: bold;">function</span> BrowserCrasher<span style="color: #000000;">&#40;</span> <span style="color: #000000;">&#41;</span>
      <span style="color: #000000;">&#123;</span>
         throw <span style="color: #5b7bff; font-weight: bold;">new</span> Error<span style="color: #000000;">&#40;</span> <span style="color: #ff0000;">'goodbye browser'</span> <span style="color: #000000;">&#41;</span>;
      <span style="color: #000000;">&#125;</span>
   <span style="color: #000000;">&#125;</span>
<span style="color: #000000;">&#125;</span>
&nbsp;</pre>
]]></content:encoded>
			<wfw:commentRss>http://www.betadesigns.co.uk/Blog/2009/09/28/forcing-the-browser-to-crash-using-actionscript/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Enums and static initializers in AS3</title>
		<link>http://www.betadesigns.co.uk/Blog/2009/09/28/enums-and-static-initializers-in-as3/</link>
		<comments>http://www.betadesigns.co.uk/Blog/2009/09/28/enums-and-static-initializers-in-as3/#comments</comments>
		<pubDate>Mon, 28 Sep 2009 21:24:05 +0000</pubDate>
		<dc:creator>Anthony</dc:creator>
				<category><![CDATA[ActionScript]]></category>
		<category><![CDATA[OOP]]></category>
		<category><![CDATA[java]]></category>
		<category><![CDATA[static initializers]]></category>

		<guid isPermaLink="false">http://www.betadesigns.co.uk/Blog/?p=80</guid>
		<description><![CDATA[I just came across the idea of static initializers in Java and was wondering if they are available in ActionScript as well.
I found a couple posts on the subject.
post 1
post 2
]]></description>
			<content:encoded><![CDATA[<p id="top" />I just came across the idea of static initializers in Java and was wondering if they are available in ActionScript as well.</p>
<p>I found a couple posts on the subject.</p>
<p><a href="http://www.barneyb.com/barneyblog/2007/11/02/enums-and-actionscripts-static-initializers/" target="_blank">post 1</a></p>
<p><a href="http://life.neophi.com/danielr/2006/12/static_initializers_in_as3_1.html" target="_self">post 2</a></p>
]]></content:encoded>
			<wfw:commentRss>http://www.betadesigns.co.uk/Blog/2009/09/28/enums-and-static-initializers-in-as3/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Layout Organizers</title>
		<link>http://www.betadesigns.co.uk/Blog/2009/07/16/layout-organizers/</link>
		<comments>http://www.betadesigns.co.uk/Blog/2009/07/16/layout-organizers/#comments</comments>
		<pubDate>Thu, 16 Jul 2009 15:12:58 +0000</pubDate>
		<dc:creator>Anthony</dc:creator>
				<category><![CDATA[3D]]></category>
		<category><![CDATA[ActionScript]]></category>
		<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[AS3]]></category>
		<category><![CDATA[layout manager]]></category>
		<category><![CDATA[layout organizer]]></category>
		<category><![CDATA[opensource]]></category>
		<category><![CDATA[somerandomdude]]></category>

		<guid isPermaLink="false">http://www.betadesigns.co.uk/Blog/?p=56</guid>
		<description><![CDATA[I recently stumbled across this awesome project by somerandomdude and just wanted to give it some exposure as it is open source and even in 3D
]]></description>
			<content:encoded><![CDATA[<p id="top" />I recently stumbled across this awesome project by <a href="http://somerandomdude.com/blog/flash/actionscript-3-layout-organizers-source-code/">somerandomdude</a> and just wanted to give it some exposure as it is open source and even in <a href="http://somerandomdude.com/articles/design-technology/preview-3d-layout-organizers/">3D</a></p>
]]></content:encoded>
			<wfw:commentRss>http://www.betadesigns.co.uk/Blog/2009/07/16/layout-organizers/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Mixin&#8217;s in ActionScript 3</title>
		<link>http://www.betadesigns.co.uk/Blog/2009/07/08/mixins-in-actionscript-3/</link>
		<comments>http://www.betadesigns.co.uk/Blog/2009/07/08/mixins-in-actionscript-3/#comments</comments>
		<pubDate>Wed, 08 Jul 2009 22:48:21 +0000</pubDate>
		<dc:creator>Anthony</dc:creator>
				<category><![CDATA[ActionScript]]></category>
		<category><![CDATA[Flex]]></category>
		<category><![CDATA[Life Cycle]]></category>
		<category><![CDATA[metadata]]></category>
		<category><![CDATA[Mixin]]></category>
		<category><![CDATA[UIcomponent]]></category>
		<category><![CDATA[[AccessibilityClass]]]></category>

		<guid isPermaLink="false">http://www.betadesigns.co.uk/Blog/?p=52</guid>
		<description><![CDATA[I was strolling through the UIComponent source code earlier today when i cam across this line of code.
&#160;
 //--------------------------------------------------------------------------
    //
    //  Class mixins
    //
    //--------------------------------------------------------------------------
&#160;
    /**
     *  @private
     *  [...]]]></description>
			<content:encoded><![CDATA[<p id="top" />I was strolling through the UIComponent source code earlier today when i cam across this line of code.</p>
<pre class="flex">&nbsp;
 <span style="color: #009900; font-style: italic;">//--------------------------------------------------------------------------</span>
    <span style="color: #009900; font-style: italic;">//</span>
    <span style="color: #009900; font-style: italic;">//  Class mixins</span>
    <span style="color: #009900; font-style: italic;">//</span>
    <span style="color: #009900; font-style: italic;">//--------------------------------------------------------------------------</span>
&nbsp;
    <span style="color: #3f5fc4; font-style: italic;">/**
     *  @private
     *  Placeholder for mixin by UIComponentAccImpl.
     */</span>
mx_internal <span style="color: #5b7bff; font-weight: bold;">static</span> <span style="color: #b7cfe7; font-weight: bold;">var</span> createAccessibilityImplementation:<span style="color: #009900; font-weight: bold;">Function</span>;
&nbsp;</pre>
<p>I wasn't entirely sure what a mixin was but after reading up on<a href="http://en.wikipedia.org/wiki/Mixin"> wikipedia</a> I realized they are exactly what they sound like basically just a mix of code bases. There is a really good post over on the <a href="http://www.yswfblog.com/blog/2009/01/12/creating-accessible-components-in-flash-and-flex-part-2/">yahoo flash blog</a> about accessibility and the way in which Flex uses the </p>
<pre class="flex">&nbsp;
<span style="color: #000000;">&#91;</span>AccessibilityClass<span style="color: #000000;">&#40;</span>implementation=<span style="color: #ff0000;">&quot;mx.accessibility.UIComponentAccImpl&quot;</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">&#93;</span>
&nbsp;</pre>
<p>meta data to mixin the Accessibility code into the UIComponent implementation.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.betadesigns.co.uk/Blog/2009/07/08/mixins-in-actionscript-3/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Unable to Catch IOErrorEvent&#8217;s when Loading a ByteArray into an Image</title>
		<link>http://www.betadesigns.co.uk/Blog/2009/03/18/unable-to-catch-ioerrorevents-when-loading-a-bytearray-into-an-image/</link>
		<comments>http://www.betadesigns.co.uk/Blog/2009/03/18/unable-to-catch-ioerrorevents-when-loading-a-bytearray-into-an-image/#comments</comments>
		<pubDate>Wed, 18 Mar 2009 12:07:38 +0000</pubDate>
		<dc:creator>Anthony</dc:creator>
				<category><![CDATA[ActionScript]]></category>
		<category><![CDATA[Bug Fixes]]></category>
		<category><![CDATA[Flex]]></category>
		<category><![CDATA[ByteArray]]></category>
		<category><![CDATA[Flex Bugs]]></category>
		<category><![CDATA[Image]]></category>
		<category><![CDATA[Image Control]]></category>
		<category><![CDATA[IOErrorEvent]]></category>
		<category><![CDATA[Unhandle IOErrorEvent]]></category>

		<guid isPermaLink="false">http://www.betadesigns.co.uk/Blog/?p=49</guid>
		<description><![CDATA[I was trying to load a byteArray into an image control today and would randomly get an Unhandled IOErrorEvent message. Now this shouldn't really happen as the image control uses a default broken image icon to display when there are any loading problems. Well after trying to catch the error unsuccessfully I wanted to know [...]]]></description>
			<content:encoded><![CDATA[<p id="top" />I was trying to load a byteArray into an image control today and would randomly get an Unhandled IOErrorEvent message. Now this shouldn't really happen as the image control uses a default broken image icon to display when there are any loading problems. Well after trying to catch the error unsuccessfully I wanted to know what was going on.<br />
So i went digging and i found in the base class of image, SWFLoader line 1497 the following <span id="more-49"></span></p>
<pre class="flex">&nbsp;
<span style="color: #5b7bff; font-weight: bold;">else</span> <span style="color: #5b7bff; font-weight: bold;">if</span> <span style="color: #000000;">&#40;</span>byteArray<span style="color: #000000;">&#41;</span>
<span style="color: #000000;">&#123;</span>
    loader = <span style="color: #5b7bff; font-weight: bold;">new</span> FlexLoader<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>;
    child = loader;
    addChild<span style="color: #000000;">&#40;</span>child<span style="color: #000000;">&#41;</span>;
&nbsp;
    loader.<span style="color: #000000;">contentLoaderInfo</span>.<span style="color: #000000;">addEventListener</span><span style="color: #000000;">&#40;</span>
     <span style="color: #5b7bff; font-weight: bold;">Event</span>.<span style="color: #000000;">COMPLETE</span>, contentLoaderInfo_completeEventHandler<span style="color: #000000;">&#41;</span>;
    loader.<span style="color: #000000;">contentLoaderInfo</span>.<span style="color: #000000;">addEventListener</span><span style="color: #000000;">&#40;</span>
     <span style="color: #5b7bff; font-weight: bold;">Event</span>.<span style="color: #000000;">INIT</span>, contentLoaderInfo_initEventHandler<span style="color: #000000;">&#41;</span>;
    loader.<span style="color: #000000;">contentLoaderInfo</span>.<span style="color: #000000;">addEventListener</span><span style="color: #000000;">&#40;</span>
     <span style="color: #5b7bff; font-weight: bold;">Event</span>.<span style="color: #000000;">UNLOAD</span>, contentLoaderInfo_unloadEventHandler<span style="color: #000000;">&#41;</span>;
&nbsp;
    <span style="color: #009900; font-style: italic;">// if loaderContext null, it will use default, which is AppDomain</span>
    <span style="color: #009900; font-style: italic;">// of child of Loader's context</span>
    loader.<span style="color: #000000;">loadBytes</span><span style="color: #000000;">&#40;</span>byteArray, loaderContext<span style="color: #000000;">&#41;</span>;
<span style="color: #000000;">&#125;</span>
&nbsp;</pre>
<p>You see the problem? No listener or dispatcher for the IOErrorEvent! So i had to load my bytes using FlexLoader(); and listen for the events myself.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.betadesigns.co.uk/Blog/2009/03/18/unable-to-catch-ioerrorevents-when-loading-a-bytearray-into-an-image/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Flex Cookbook Recipe 5.8 Allow Certain items in a list to be selectable, Doesn&#8217;t quite work correctly</title>
		<link>http://www.betadesigns.co.uk/Blog/2009/03/12/flex-cookbook-recipe-58-allow-certain-items-in-a-list-to-be-selectable-doesnt-quite-work-correctly/</link>
		<comments>http://www.betadesigns.co.uk/Blog/2009/03/12/flex-cookbook-recipe-58-allow-certain-items-in-a-list-to-be-selectable-doesnt-quite-work-correctly/#comments</comments>
		<pubDate>Thu, 12 Mar 2009 10:38:12 +0000</pubDate>
		<dc:creator>Anthony</dc:creator>
				<category><![CDATA[ActionScript]]></category>
		<category><![CDATA[Bug Fixes]]></category>
		<category><![CDATA[Flex]]></category>
		<category><![CDATA[bugFixes]]></category>
		<category><![CDATA[finishKeySelection]]></category>
		<category><![CDATA[Flex Cookbook]]></category>
		<category><![CDATA[IListItemRenderer]]></category>
		<category><![CDATA[List]]></category>
		<category><![CDATA[listItems]]></category>
		<category><![CDATA[mouseEventToItemRenderer]]></category>
		<category><![CDATA[offScreenExtraRowsTop]]></category>

		<guid isPermaLink="false">http://www.betadesigns.co.uk/Blog/?p=48</guid>
		<description><![CDATA[Ok I needed to disable Heading elements inside a List Component in Flex, and i was being too lazy to work it out for myself so i picked up the Flex cookbook Adobe had been kind enough to send me and yes... It was there. Now the Mouse removal was straight forward and worked like [...]]]></description>
			<content:encoded><![CDATA[<p id="top" />Ok I needed to disable Heading elements inside a List Component in Flex, and i was being too lazy to work it out for myself so i picked up the Flex cookbook Adobe had been kind enough to send me and yes... It was there. Now the Mouse removal was straight forward and worked like a charm. But the keyboard events were a different story. The code didn't work for several reasons.<br />
1. Key directions were not being assigned.<br />
2. When a disabled item was at either the top or the bottom of the list it would stop you being able to continue down / up the list.<br />
To fix this i added the following code.<span id="more-48"></span></p>
<pre class="flex">&nbsp;
<span style="color: #3f5fc4; font-style: italic;">/**
* @inheritDoc.
* set our offscreen items to at least 4 so
* that if the last / first visible item
* is disabled we can still move the view
* up or down without getting stuck?
*/</span>
<span style="color: #5b7bff; font-weight: bold;">override</span> <span style="color: #5b7bff; font-weight: bold;">public</span> <span style="color: #009900; font-weight: bold;">function</span> initialize<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>:<span style="color: #5b7bff; font-weight: bold;">void</span>
<span style="color: #000000;">&#123;</span>
   <span style="color: #5b7bff; font-weight: bold;">super</span>.<span style="color: #000000;">initialize</span><span style="color: #000000;">&#40;</span> <span style="color: #000000;">&#41;</span>;
   offscreenExtraRowsOrColumns =
   Math.<span style="color: #000000;">max</span><span style="color: #000000;">&#40;</span> <span style="color: #000000;">4</span>, offscreenExtraRowsOrColumns <span style="color: #000000;">&#41;</span>;
<span style="color: #000000;">&#125;</span>
&nbsp;
<span style="color: #3f5fc4; font-style: italic;">/**
* @inheritDoc.
* capture key directions.
*/</span>
<span style="color: #5b7bff; font-weight: bold;">override</span> <span style="color: #5b7bff; font-weight: bold;">protected</span> <span style="color: #009900; font-weight: bold;">function</span> keyDownHandler<span style="color: #000000;">&#40;</span><span style="color: #5b7bff; font-weight: bold;">event</span>:KeyboardEvent<span style="color: #000000;">&#41;</span>:<span style="color: #5b7bff; font-weight: bold;">void</span>
<span style="color: #000000;">&#123;</span>
  <span style="color: #5b7bff; font-weight: bold;">if</span><span style="color: #000000;">&#40;</span> <span style="color: #5b7bff; font-weight: bold;">event</span>.<span style="color: #000000;">keyCode</span> == Keyboard.<span style="color: #000000;">UP</span> <span style="color: #000000;">&#41;</span>
  <span style="color: #000000;">&#123;</span>
     _selectionIsAbove = <span style="color: #5b7bff; font-weight: bold;">true</span>;
&nbsp;
  <span style="color: #000000;">&#125;</span><span style="color: #5b7bff; font-weight: bold;">else</span> <span style="color: #5b7bff; font-weight: bold;">if</span><span style="color: #000000;">&#40;</span> <span style="color: #5b7bff; font-weight: bold;">event</span>.<span style="color: #000000;">keyCode</span> == Keyboard.<span style="color: #000000;">DOWN</span> <span style="color: #000000;">&#41;</span>
  <span style="color: #000000;">&#123;</span>
    _selectionIsAbove = <span style="color: #5b7bff; font-weight: bold;">false</span>;
  <span style="color: #000000;">&#125;</span>
    <span style="color: #5b7bff; font-weight: bold;">super</span>.<span style="color: #000000;">keyDownHandler</span><span style="color: #000000;">&#40;</span> <span style="color: #5b7bff; font-weight: bold;">event</span> <span style="color: #000000;">&#41;</span>;
<span style="color: #000000;">&#125;</span>
&nbsp;</pre>
<p>And then I changed the finishKeySelection( ) method as follows.</p>
<pre class="flex">&nbsp;
<span style="color: #3f5fc4; font-style: italic;">/**
* @inheritDoc.
* check to see if our selected item is
* allowed to be selected or not.
*/</span>
<span style="color: #5b7bff; font-weight: bold;">override</span> <span style="color: #5b7bff; font-weight: bold;">protected</span> <span style="color: #009900; font-weight: bold;">function</span> finishKeySelection<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>:<span style="color: #5b7bff; font-weight: bold;">void</span>
<span style="color: #000000;">&#123;</span>
  <span style="color: #5b7bff; font-weight: bold;">super</span>.<span style="color: #000000;">finishKeySelection</span><span style="color: #000000;">&#40;</span> <span style="color: #000000;">&#41;</span>;
&nbsp;
  <span style="color: #b7cfe7; font-weight: bold;">var</span> i : int;
  <span style="color: #b7cfe7; font-weight: bold;">var</span> rowCount : int = listItems.<span style="color: #000000;">length</span>;
  <span style="color: #b7cfe7; font-weight: bold;">var</span> count : Number = <span style="color: #000000;">0</span>;
&nbsp;
  <span style="color: #b7cfe7; font-weight: bold;">var</span> item : IListItemRenderer = listItems<span style="color: #000000;">&#91;</span> caretIndex -
		verticalScrollPosition + offscreenExtraRowsTop <span style="color: #000000;">&#93;</span><span style="color: #000000;">&#91;</span> <span style="color: #000000;">0</span> <span style="color: #000000;">&#93;</span>;
&nbsp;
  <span style="color: #5b7bff; font-weight: bold;">if</span><span style="color: #000000;">&#40;</span> item <span style="color: #000000;">&#41;</span>
  <span style="color: #000000;">&#123;</span>
    <span style="color: #5b7bff; font-weight: bold;">if</span><span style="color: #000000;">&#40;</span> item.<span style="color: #000000;">data</span> <span style="color: #000000;">&#41;</span>
    <span style="color: #000000;">&#123;</span>
      <span style="color: #5b7bff; font-weight: bold;">if</span><span style="color: #000000;">&#40;</span> disabledFilterFunction<span style="color: #000000;">&#40;</span> item.<span style="color: #000000;">data</span> <span style="color: #000000;">&#41;</span> <span style="color: #000000;">&#41;</span>
      <span style="color: #000000;">&#123;</span>
	<span style="color: #009900; font-style: italic;">//trace( 'ITEM IS DISABLED : ' + disabledFilterFunction( item.data ) );</span>
	<span style="color: #009900; font-style: italic;">//trace( 'SELECTION IS ABOVE : ' + _selectionIsAbove );</span>
	<span style="color: #b7cfe7; font-weight: bold;">var</span> currIndex : int = caretIndex - verticalScrollPosition;
	<span style="color: #5b7bff; font-weight: bold;">if</span><span style="color: #000000;">&#40;</span> _selectionIsAbove <span style="color: #000000;">&#41;</span>
	<span style="color: #000000;">&#123;</span>
	  <span style="color: #009900; font-style: italic;">//LookUp</span>
	  i = currIndex + offscreenExtraRowsTop;
	  count = <span style="color: #000000;">0</span>;
	  while<span style="color: #000000;">&#40;</span> i &gt; <span style="color: #000000;">0</span> <span style="color: #000000;">&#41;</span>
	  <span style="color: #000000;">&#123;</span>
	    item = listItems<span style="color: #000000;">&#91;</span> i <span style="color: #000000;">&#93;</span><span style="color: #000000;">&#91;</span> <span style="color: #000000;">0</span> <span style="color: #000000;">&#93;</span>;
	    <span style="color: #5b7bff; font-weight: bold;">if</span><span style="color: #000000;">&#40;</span> !disabledFilterFunction<span style="color: #000000;">&#40;</span> item.<span style="color: #000000;">data</span> <span style="color: #000000;">&#41;</span> <span style="color: #000000;">&#41;</span>
	    <span style="color: #000000;">&#123;</span>
	      selectedIndex = selectedIndex + count;
	      <span style="color: #5b7bff; font-weight: bold;">return</span>;
	    <span style="color: #000000;">&#125;</span>
	      count --;
	      i--;
	    <span style="color: #000000;">&#125;</span>
	    selectedIndex = selectedIndex <span style="color: #000000;">+1</span>;
	    <span style="color: #009900; font-style: italic;">//trace( 'CANT GO UP ANYMORE' );</span>
	    <span style="color: #5b7bff; font-weight: bold;">return</span>;
&nbsp;
	    <span style="color: #000000;">&#125;</span><span style="color: #5b7bff; font-weight: bold;">else</span><span style="color: #000000;">&#123;</span>
	    <span style="color: #009900; font-style: italic;">//Look down.</span>
	    i = currIndex + offscreenExtraRowsTop;
	    count = <span style="color: #000000;">0</span>;
	    while<span style="color: #000000;">&#40;</span> i &lt; rowCount <span style="color: #000000;">&#41;</span>
	    <span style="color: #000000;">&#123;</span>
	      item = listItems<span style="color: #000000;">&#91;</span> i <span style="color: #000000;">&#93;</span><span style="color: #000000;">&#91;</span> <span style="color: #000000;">0</span> <span style="color: #000000;">&#93;</span>;
	      <span style="color: #5b7bff; font-weight: bold;">if</span><span style="color: #000000;">&#40;</span> !disabledFilterFunction<span style="color: #000000;">&#40;</span> item.<span style="color: #000000;">data</span> <span style="color: #000000;">&#41;</span> <span style="color: #000000;">&#41;</span>
	      <span style="color: #000000;">&#123;</span>
		selectedIndex = selectedIndex + count;
		<span style="color: #5b7bff; font-weight: bold;">return</span>;
	      <span style="color: #000000;">&#125;</span>
	      count ++;
	      i++;
	    <span style="color: #000000;">&#125;</span>
&nbsp;
	    selectedIndex = selectedIndex <span style="color: #000000;">-1</span>;
	    <span style="color: #009900; font-style: italic;">//trace( 'CANT GO DOWN ANYMORE' );</span>
	    <span style="color: #5b7bff; font-weight: bold;">return</span>;
        <span style="color: #000000;">&#125;</span>
      <span style="color: #000000;">&#125;</span>
    <span style="color: #000000;">&#125;</span>
  <span style="color: #000000;">&#125;</span>
<span style="color: #000000;">&#125;</span>
&nbsp;</pre>
<p>I dont know if this will help anyone but im sure glad i got it working.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.betadesigns.co.uk/Blog/2009/03/12/flex-cookbook-recipe-58-allow-certain-items-in-a-list-to-be-selectable-doesnt-quite-work-correctly/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
