<?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; Components</title>
	<atom:link href="http://www.betadesigns.co.uk/Blog/category/components/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_1088760879"
			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_1088760879"
			width="500"
			height="350">
		<param name="wmode" value="transparent" />
	<!--<![endif]-->
		
	<!--[if !IE]>-->
	</object>
	<!--<![endif]-->
</object><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>Custom Color Picker Source</title>
		<link>http://www.betadesigns.co.uk/Blog/2008/06/24/custom-color-picker-source/</link>
		<comments>http://www.betadesigns.co.uk/Blog/2008/06/24/custom-color-picker-source/#comments</comments>
		<pubDate>Mon, 23 Jun 2008 23:56:17 +0000</pubDate>
		<dc:creator>Anthony</dc:creator>
				<category><![CDATA[ActionScript]]></category>
		<category><![CDATA[Components]]></category>
		<category><![CDATA[Flex]]></category>
		<category><![CDATA[buzzword color picker]]></category>
		<category><![CDATA[Color Picker]]></category>
		<category><![CDATA[Flex component development]]></category>
		<category><![CDATA[Kuler]]></category>
		<category><![CDATA[kuler rss]]></category>
		<category><![CDATA[open source]]></category>
		<category><![CDATA[Sourc code]]></category>

		<guid isPermaLink="false">http://www.betadesigns.co.uk/Blog/?p=21</guid>
		<description><![CDATA[Some time ago now I decided as a self improvement mechanism to re-write one of the Flex components from scratch so that I could get my head around the Flex Component Framework. So I set my eyes on the ColorPicker Brave or stupid you decide as this was going to be one of my first [...]]]></description>
			<content:encoded><![CDATA[<p id="top" />Some time ago now I decided as a self improvement mechanism to re-write one of the Flex components from scratch so that I could get my head around the Flex Component Framework. So I set my eyes on the ColorPicker Brave or stupid you decide as this was going to be one of my first components ever, I should have probably started somewhere a bit smaller.. But hey.. It works and I learnt a hell of a lot. and now it's time to share.<span id="more-21"></span> I haven't looked at the code for this in a long long time so be gentle.. In addition there are many improvements that could be made, and I fully intended on implementing them, unfortunately time has got the better of me and I have no real reason to implement such things as multiple rss feeds ( kuler is really slow and not 100% reliable ). A choice to use squares / balls .. anything else you like as the renderer for the colors.</p>
<p>However it does have lots of other cool features like::</p>
<p>Color grouping</p>
<p>Nice shiny 3D balls for the color swatches.</p>
<p>Kuler Lookup facility ( optional just set Kuler = true/false );</p>
<p>Can be used exactly the same as the Flex Color picker so you can just swap it into existing projects.</p>
<p>OK Just right click to view the source</p>
<p>This is mostly based on the Flex Color Picker so feel free to use it in your own projects improve it and just give me a shout as I would love to see it implemented in real life projects personal or otherwise.</p>

<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000"
			id="fm_CCPicker_1622604411"
			class="flashmovie"
			width="500"
			height="400">
	<param name="movie" value="/Examples/CCPicker/CCPicker.swf" />
	<param name="wmode" value="transparent" />
	<!--[if !IE]>-->
	<object	type="application/x-shockwave-flash"
			data="/Examples/CCPicker/CCPicker.swf"
			name="fm_CCPicker_1622604411"
			width="500"
			height="400">
		<param name="wmode" value="transparent" />
	<!--<![endif]-->
		
	<!--[if !IE]>-->
	</object>
	<!--<![endif]-->
</object>
]]></content:encoded>
			<wfw:commentRss>http://www.betadesigns.co.uk/Blog/2008/06/24/custom-color-picker-source/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
	</channel>
</rss>
