<?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; Flex</title>
	<atom:link href="http://www.betadesigns.co.uk/Blog/category/flex/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>Custom XCode Logger</title>
		<link>http://www.betadesigns.co.uk/Blog/2010/07/03/custom-xcode-logger/</link>
		<comments>http://www.betadesigns.co.uk/Blog/2010/07/03/custom-xcode-logger/#comments</comments>
		<pubDate>Sat, 03 Jul 2010 11:09:28 +0000</pubDate>
		<dc:creator>Anthony</dc:creator>
				<category><![CDATA[Flex]]></category>
		<category><![CDATA[objective-c]]></category>
		<category><![CDATA[shortcuts]]></category>
		<category><![CDATA[tips]]></category>
		<category><![CDATA[xcode]]></category>

		<guid isPermaLink="false">http://www.betadesigns.co.uk/Blog/?p=294</guid>
		<description><![CDATA[I came across this method for creating a Debug Logger for XCode projects.
Basically you create a macro that says only process this piece of code if we are running in debug mode. This allows you to create logging throughout your application without having to worry about removing it before you do a release build as [...]]]></description>
			<content:encoded><![CDATA[<p id="top" />I came across this method for creating a Debug Logger for XCode projects.<br />
Basically you create a macro that says only process this piece of code if we are running in debug mode. This allows you to create logging throughout your application without having to worry about removing it before you do a release build as it won't be included in the release code.</p>
<p>To begin you need to add a GCC_PREPROCESSOR_DEFINITIONS | DEBUG=1 to your projects TARGET>Get Info>BUILD settings.</p>
<p>Next go into YOUR_APPLICATION_NAME_Prefix.pch file ( located under Other Sources ) and place the following macro.</p>
<div class="scroll">
<pre class="flex">&nbsp;
<span style="color: #009900; font-style: italic;">#ifdef DEBUG</span>
<span style="color: #009900; font-style: italic;"># define trace(fmt, ...) NSLog((@&quot;%s [Line %d] &quot; fmt), __PRETTY_FUNCTION__, __LINE__, ##__VA_ARGS__);</span>
<span style="color: #009900; font-style: italic;">#else</span>
<span style="color: #009900; font-style: italic;"># define trace(...)</span>
<span style="color: #009900; font-style: italic;">#endif</span>
&nbsp;</pre>
</div>
<p>This will create a custom Logger that can be used in the same way as NSLog except that it will output a more descriptive message showing the location and line number of where the log item is located.<br />
edit: I have cheekily renamed it to trace();</p>
<pre class="flex">&nbsp;
trace<span style="color: #000000;">&#40;</span> @<span style="color: #ff0000;">&quot; Does my debug tracer appear in production code?  %@&quot;</span>,
@<span style="color: #ff0000;">&quot;NO!&quot;</span>  <span style="color: #000000;">&#41;</span>;
&nbsp;</pre>
]]></content:encoded>
			<wfw:commentRss>http://www.betadesigns.co.uk/Blog/2010/07/03/custom-xcode-logger/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_79075850"
			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_79075850"
			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>1 Million Items to Trash!</title>
		<link>http://www.betadesigns.co.uk/Blog/2010/05/15/1-million-items-to-trash/</link>
		<comments>http://www.betadesigns.co.uk/Blog/2010/05/15/1-million-items-to-trash/#comments</comments>
		<pubDate>Sat, 15 May 2010 00:11:34 +0000</pubDate>
		<dc:creator>Anthony</dc:creator>
				<category><![CDATA[Flex]]></category>

		<guid isPermaLink="false">http://www.betadesigns.co.uk/Blog/?p=43</guid>
		<description><![CDATA[I tried emptying my trash can the other day only to find that i had over One and a half million items in there! after leaving it for the weekend i still had more than a million to delete so i had to resort to the Terminal. And gained myself an extra 10 gig in [...]]]></description>
			<content:encoded><![CDATA[<p id="top" />I tried emptying my trash can the other day only to find that i had over One and a half million items in there! after leaving it for the weekend i still had more than a million to delete so i had to resort to the Terminal. And gained myself an extra 10 gig in the process!<br />
<img src="http://www.betadesigns.co.uk/Examples/posts/1-million-items-to-trash/trash.png" alt="1 Million items to trash!" /></p>
<p>So i thought i would write a quick reminder to myself how to quickly empty the trash can instead of using the Finder tool which takes ages!</p>
<p>&gt;&gt; cd ~/.Trash</p>
<p>&gt;&gt; sudo rm -r *</p>
]]></content:encoded>
			<wfw:commentRss>http://www.betadesigns.co.uk/Blog/2010/05/15/1-million-items-to-trash/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Default Skin for custom FlashBuilder components.</title>
		<link>http://www.betadesigns.co.uk/Blog/2010/05/14/default-skin-for-custom-flashbuilder-components/</link>
		<comments>http://www.betadesigns.co.uk/Blog/2010/05/14/default-skin-for-custom-flashbuilder-components/#comments</comments>
		<pubDate>Fri, 14 May 2010 22:08:11 +0000</pubDate>
		<dc:creator>Anthony</dc:creator>
				<category><![CDATA[Flex]]></category>
		<category><![CDATA[Advanced Component Development]]></category>
		<category><![CDATA[default skin]]></category>
		<category><![CDATA[defaults.css]]></category>
		<category><![CDATA[flashbuilder]]></category>
		<category><![CDATA[skinClass]]></category>
		<category><![CDATA[SkinnableComponent]]></category>

		<guid isPermaLink="false">http://www.betadesigns.co.uk/Blog/?p=228</guid>
		<description><![CDATA[In a recent post on Custom FlashBuilder Component Views I showed how to create a swc file with your custom component.
This raised a question by one of the commenters on how to create default custom skins for your components so that when you ship them a user can use your default skins without having to [...]]]></description>
			<content:encoded><![CDATA[<p id="top" />In a recent post on <a href="http://www.betadesigns.co.uk/Blog/2010/05/06/custom-flashbuilder-component-views/">Custom FlashBuilder Component Views</a> I showed how to create a swc file with your custom component.<br />
This raised a question by one of the commenters on how to create default custom skins for your components so that when you ship them a user can use your default skins without having to explicitly set them.<br />
Normally you have to do something like this</p>
<pre class="flex">&nbsp;
&lt;clock:BinaryClock
   skinClass=<span style="color: #ff0000;">&quot;co.uk.betadesigns.binaryclock.BinaryClockSkin&quot;</span>
   /&gt;
&nbsp;</pre>
<p>Setting up my custom component with my custom skin, however if a user of my component doesn't know that they have to set this style they will get a runtime error something like this</p>
<pre class="flex">&nbsp;
Error:
   Skin <span style="color: #5b7bff; font-weight: bold;">for</span>
   TestProject.<span style="color: #000000;">ApplicationSkin2</span>._ApplicationSkin_Group1.
   <span style="color: #000000;">contentGroup</span>.<span style="color: #000000;">BinaryClock5</span>
   cannot be found.
&nbsp;</pre>
<p>The way to get around this is to tell the library.swc file that you want to set a default style for your components in case one is not set. This allows you to provide one as well as allowing it to be overridden by anyone that wants to.</p>
<p>All you have to do is create a defaults.css file</p>
<pre class="css">&nbsp;
<span style="color: #808080; font-style: italic;">/* CSS file */</span>
<span style="color: #a1a100;">@namespace &quot;co.uk.betadesigns.components.binaryclock.*&quot;;</span>
BinaryCounter
<span style="color: #66cc66;">&#123;</span>
   skinClass : ClassReference<span style="color: #66cc66;">&#40;</span>
   <span style="color: #ff0000;">&quot;co.uk.betadesigns.components.binaryclock.BinaryCounterSkin&quot;</span>
   <span style="color: #66cc66;">&#41;</span>;
<span style="color: #66cc66;">&#125;</span>
&nbsp;
BinaryClock
<span style="color: #66cc66;">&#123;</span>
   skinClass : ClassReference<span style="color: #66cc66;">&#40;</span>
   <span style="color: #ff0000;">&quot;co.uk.betadesigns.components.binaryclock.BinaryClockSkin&quot;</span>
   <span style="color: #66cc66;">&#41;</span>;
<span style="color: #66cc66;">&#125;</span>
&nbsp;</pre>
<p>You need to create this in the top level package of your swc file under ( default package for FlashBuilder or src for Flex3 ).<br />
The First element<br />
@namespace is the namespace to the component you want to reference ( you can include multiple namespaces for multiple components in different packages ).<br />
From this you can see that my BinaryClock is in the package co.uk.betadesigns.components.binaryclock.*<br />
You then setup selectors for all the SkinnableComponents you want to give default skins for.<br />
Next you simply need to include the defaults.css file in the compiler arguments.Properties>Flex Library Build Path>Assets></p>
<p>Then in the Flex Library Compiler>Additional Compiler Arguments set -defaults-css-url defaults.css This will set the defaults.css file as the default css for all components in the swc</p>
<p>All Done.<br />
<a href="http://www.betadesigns.co.uk/Examples/posts/default-skin-for-custom-flashbuilder-components/ExampleLibrary.swc">Example Project files here.</a> ( Right click save as )</p>
]]></content:encoded>
			<wfw:commentRss>http://www.betadesigns.co.uk/Blog/2010/05/14/default-skin-for-custom-flashbuilder-components/feed/</wfw:commentRss>
		<slash:comments>6</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>FlexUnit4 &amp; Parsley</title>
		<link>http://www.betadesigns.co.uk/Blog/2010/04/29/flexunit4-parsley/</link>
		<comments>http://www.betadesigns.co.uk/Blog/2010/04/29/flexunit4-parsley/#comments</comments>
		<pubDate>Thu, 29 Apr 2010 22:14:28 +0000</pubDate>
		<dc:creator>Anthony</dc:creator>
				<category><![CDATA[Flex]]></category>
		<category><![CDATA[Test Driven Design]]></category>
		<category><![CDATA[ActionScript]]></category>
		<category><![CDATA[flashbuilder]]></category>
		<category><![CDATA[FlexUnit]]></category>
		<category><![CDATA[FlexUnit4]]></category>
		<category><![CDATA[Parsley]]></category>
		<category><![CDATA[TDD]]></category>
		<category><![CDATA[Test Driven Developement]]></category>
		<category><![CDATA[Unit Test]]></category>
		<category><![CDATA[UnitTest]]></category>
		<category><![CDATA[UnitTesting]]></category>

		<guid isPermaLink="false">http://www.betadesigns.co.uk/Blog/?p=177</guid>
		<description><![CDATA[For the last six months I have been working on a rather large enterprise application that uses parsley as it's main Dependency Injection Framework. This has led to many complex class' that contain multiple injected models, VO and other elements. Recreating these items inside test harness can become very cumbersome if you have to create [...]]]></description>
			<content:encoded><![CDATA[<p id="top" />For the last six months I have been working on a rather large enterprise application that uses parsley as it's main Dependency Injection Framework. This has led to many complex class' that contain multiple injected models, VO and other elements. Recreating these items inside test harness can become very cumbersome if you have to create a large injection heirarchy. Consider the following example.<span id="more-177"></span></p>
<pre class="flex"><span style="color: #5b7bff; font-weight: bold;">private</span> <span style="color: #b7cfe7; font-weight: bold;">var</span> _testClass : MyTestPM;
&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>
   _testClass = <span style="color: #5b7bff; font-weight: bold;">new</span> MyTestPM<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>;
   _testClass.<span style="color: #000000;">myFirstInjectedItem</span> = <span style="color: #5b7bff; font-weight: bold;">new</span> MyFirstInjectedItem<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>;
   _testClass.<span style="color: #000000;">mySecondInjectedItem</span> = <span style="color: #5b7bff; font-weight: bold;">new</span> MySecondInjectedItem<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>;
   _testClass.<span style="color: #000000;">myFirstInjectedItem</span>.<span style="color: #000000;">mySecondInjectedItem</span> =
         _testClass.<span style="color: #000000;">mySecondInjectedItem</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>;
<span style="color: #000000;">&#125;</span></pre>
<p>As you can see this can become complicated with the more injected items you have that can then have references to other injected items!</p>
<p>However there is a way to use the Parsley DI Framework to do all that work for you!.</p>
<p>1. Create a TestContext File that contains all the Injectable objects your test class/suite needs.</p>
<pre class="flex">&nbsp;
&lt;?xml version=<span style="color: #ff0000;">&quot;1.0&quot;</span> encoding=<span style="color: #ff0000;">&quot;utf-8&quot;</span>?&gt;
&lt;fx:Object xmlns:fx=<span style="color: #ff0000;">&quot;http://ns.adobe.com/mxml/2009&quot;</span>
    xmlns:s=<span style="color: #ff0000;">&quot;library://ns.adobe.com/flex/spark&quot;</span>
    xmlns:mx=<span style="color: #ff0000;">&quot;library://ns.adobe.com/flex/mx&quot;</span>
	xmlns:spicefactory=<span style="color: #ff0000;">&quot;http://www.spicefactory.org/parsley&quot;</span>&gt;
	&lt;fx:Script&gt;
		&lt;!<span style="color: #000000;">&#91;</span>CDATA<span style="color: #000000;">&#91;</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;">domain</span>.<span style="color: #000000;">TestModel</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;">domain</span>.<span style="color: #000000;">TestModel2</span>;
		<span style="color: #000000;">&#93;</span><span style="color: #000000;">&#93;</span>&gt;
	&lt;/fx:Script&gt;
	&lt;fx:Declarations&gt;
		&lt;spicefactory:Object type=<span style="color: #ff0000;">&quot;{ TestModel }&quot;</span> /&gt;
		&lt;spicefactory:Object type=<span style="color: #ff0000;">&quot;{ TestModel2 }&quot;</span> /&gt;
	&lt;/fx:Declarations&gt;
&nbsp;
&lt;/fx:Object&gt;
&nbsp;</pre>
<p>2. Next Create your TestClass.</p>
<pre class="flex"><span style="color: #9e12cf; font-weight: bold;">package</span> flexUnitTests
<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;">domain</span>.<span style="color: #000000;">TestModel</span>;
   <span style="color: #5b7bff; font-weight: bold;">import</span> flexUnitTests.<span style="color: #000000;">context</span>.<span style="color: #000000;">TestContext</span>;
   <span style="color: #5b7bff; font-weight: bold;">import</span> flexunit.<span style="color: #000000;">framework</span>.<span style="color: #000000;">Assert</span>;
   <span style="color: #5b7bff; font-weight: bold;">import</span> org.<span style="color: #000000;">spicefactory</span>.<span style="color: #000000;">parsley</span>.<span style="color: #000000;">core</span>.<span style="color: #000000;">context</span>.<span style="color: #000000;">Context</span>;
   <span style="color: #5b7bff; font-weight: bold;">import</span> org.<span style="color: #000000;">spicefactory</span>.<span style="color: #000000;">parsley</span>.<span style="color: #000000;">flex</span>.<span style="color: #000000;">FlexContextBuilder</span>;
&nbsp;
<span style="color: #5b7bff; font-weight: bold;">public</span> <span style="color: #9e12cf; font-weight: bold;">class</span> InjectableTestCase
<span style="color: #000000;">&#123;</span>
<span style="color: #009900; font-style: italic;">//Begin by injecting the class you want to test.</span>
<span style="color: #000000;">&#91;</span>Inject<span style="color: #000000;">&#93;</span>
<span style="color: #5b7bff; font-weight: bold;">public</span> <span style="color: #b7cfe7; font-weight: bold;">var</span> model : TestModel;
&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>
	<span style="color: #009900; font-style: italic;">//In the setup use the FlexContextBuilder to build</span>
	<span style="color: #009900; font-style: italic;">//your testContext that you created in step 1.</span>
	<span style="color: #b7cfe7; font-weight: bold;">var</span> cont : Context = FlexContextBuilder.<span style="color: #000000;">build</span><span style="color: #000000;">&#40;</span> TestContext <span style="color: #000000;">&#41;</span>;
	<span style="color: #009900; font-style: italic;">//Then add this test case to the context which will begin the</span>
	<span style="color: #009900; font-style: italic;">//Injection Process. This will be called before every test</span>
	<span style="color: #009900; font-style: italic;">//so your injected items will all be fresh and new.</span>
	cont.<span style="color: #000000;">createDynamicContext</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>.<span style="color: #000000;">addObject</span><span style="color: #000000;">&#40;</span> this <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>
	model = <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> AddMultipleModels1<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: #009900; font-style: italic;">//Simple tests to show that the models are re-create</span>
	<span style="color: #009900; font-style: italic;">//every time a new test is run.</span>
	Assert.<span style="color: #000000;">assertEquals</span><span style="color: #000000;">&#40;</span> <span style="color: #ff0000;">&quot;Should only ever have one count.&quot;</span>,
		model.<span style="color: #000000;">counter</span>, <span style="color: #000000;">0</span> <span style="color: #000000;">&#41;</span>;
	Assert.<span style="color: #000000;">assertEquals</span><span style="color: #000000;">&#40;</span> <span style="color: #ff0000;">&quot;Should only ever have one count.&quot;</span>,
		model.<span style="color: #000000;">model2</span>.<span style="color: #000000;">counter</span>, <span style="color: #000000;">0</span> <span style="color: #000000;">&#41;</span>;
	model.<span style="color: #000000;">counter</span> ++;
	model.<span style="color: #000000;">model2</span>.<span style="color: #000000;">counter</span> ++;
	Assert.<span style="color: #000000;">assertEquals</span><span style="color: #000000;">&#40;</span> <span style="color: #ff0000;">&quot;Should only ever have one count.&quot;</span>,
		model.<span style="color: #000000;">counter</span>, <span style="color: #000000;">1</span> <span style="color: #000000;">&#41;</span>;
	Assert.<span style="color: #000000;">assertEquals</span><span style="color: #000000;">&#40;</span> <span style="color: #ff0000;">&quot;Should only ever have one count.&quot;</span>,
		model.<span style="color: #000000;">model2</span>.<span style="color: #000000;">counter</span>, <span style="color: #000000;">1</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> AddMultipleModels2<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: #009900; font-style: italic;">//Simple tests to show that the models are re-create</span>
	<span style="color: #009900; font-style: italic;">//every time a new test is run.</span>
	Assert.<span style="color: #000000;">assertEquals</span><span style="color: #000000;">&#40;</span> <span style="color: #ff0000;">&quot;Should only ever have one count.&quot;</span>,
		model.<span style="color: #000000;">counter</span>, <span style="color: #000000;">0</span> <span style="color: #000000;">&#41;</span>;
	Assert.<span style="color: #000000;">assertEquals</span><span style="color: #000000;">&#40;</span> <span style="color: #ff0000;">&quot;Should only ever have one count.&quot;</span>,
		model.<span style="color: #000000;">model2</span>.<span style="color: #000000;">counter</span>, <span style="color: #000000;">0</span> <span style="color: #000000;">&#41;</span>;
	model.<span style="color: #000000;">counter</span> ++;
	model.<span style="color: #000000;">model2</span>.<span style="color: #000000;">counter</span> ++;
	Assert.<span style="color: #000000;">assertEquals</span><span style="color: #000000;">&#40;</span> <span style="color: #ff0000;">&quot;Should only ever have one count.&quot;</span>,
		model.<span style="color: #000000;">counter</span>, <span style="color: #000000;">1</span> <span style="color: #000000;">&#41;</span>;
	Assert.<span style="color: #000000;">assertEquals</span><span style="color: #000000;">&#40;</span> <span style="color: #ff0000;">&quot;Should only ever have one count.&quot;</span>,
		model.<span style="color: #000000;">model2</span>.<span style="color: #000000;">counter</span>, <span style="color: #000000;">1</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></pre>
<p>Here is an <a href="http://www.betadesigns.co.uk/Examples/FlexUnit/FlexUnitParsleyExample.zip">example</a> FlashBuilder Project to show this in action.<br />
Hope this relives some stress when unit testing.</p>
<p>Of course you should remember that if you have hundreds or even thousands of tests that this probably isn't an ideal solution as parsley will parse the context file each and every time a test is run and although the overhead is minimal it will add up if you have soo many tests.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.betadesigns.co.uk/Blog/2010/04/29/flexunit4-parsley/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Custom Eclipse Style XCode shortcuts</title>
		<link>http://www.betadesigns.co.uk/Blog/2010/02/03/custom-xcode-shortcuts/</link>
		<comments>http://www.betadesigns.co.uk/Blog/2010/02/03/custom-xcode-shortcuts/#comments</comments>
		<pubDate>Wed, 03 Feb 2010 23:52:05 +0000</pubDate>
		<dc:creator>Anthony</dc:creator>
				<category><![CDATA[Flex]]></category>
		<category><![CDATA[XCode tips]]></category>
		<category><![CDATA[iphone]]></category>
		<category><![CDATA[ecliplse]]></category>
		<category><![CDATA[shortcuts]]></category>
		<category><![CDATA[xcode]]></category>

		<guid isPermaLink="false">http://www.betadesigns.co.uk/Blog/?p=164</guid>
		<description><![CDATA[After using eclipse for so long i have become a custom to my shortcuts and xcode just doesn't stand up to the job as far as i am concerned so here is a small list of the custom key bindings i have setup for myself. I will add more as I create them.
To create a [...]]]></description>
			<content:encoded><![CDATA[<p id="top" />After using eclipse for so long i have become a custom to my shortcuts and xcode just doesn't stand up to the job as far as i am concerned so here is a small list of the custom key bindings i have setup for myself. I will add more as I create them.</p>
<p>To create a custom key bindings file goto XCode&gt;Preferences&gt;Bindings&gt; Duplicate an existing binding and name it whatever you want then go to and open the file you just created in a text editor so you can see the xml output.</p>
<p><em>~/Library/Application Support/Xcode/Key Bindings/*.pbxkeys</em></p>
<p>A good list of available commands can be found <a href="http://www.erasetotheleft.com/post/mac-os-x-key-bindings/#comment-101" target="_blank">here</a></p>
<p><strong>1. Duplicate code!</strong></p>
<p>I can't believe xcode doesn't have this in Eclipse you simple select your text and press Ctrl + Alt and either Up or Down on the keypad and it will duplicate your code placing it either above or below the current selection. It will also reselect the newly duplicated code so that you can duplicate it as many times as you like.</p>
<div id="_mcePaste">&lt;key&gt;^~\U700&lt;/key&gt;</div>
<div id="_mcePaste">&lt;array&gt;</div>
<div id="_mcePaste">&lt;string&gt;copy:&lt;/string&gt;</div>
<div id="_mcePaste">&lt;string&gt;moveUp:&lt;/string&gt;</div>
<div id="_mcePaste">&lt;string&gt;moveToEndOfLine:&lt;/string&gt;</div>
<div id="_mcePaste">&lt;string&gt;insertLineBreak:&lt;/string&gt;</div>
<div id="_mcePaste">&lt;string&gt;insertNewLine:&lt;/string&gt;</div>
<div id="_mcePaste">&lt;string&gt;setMark:&lt;/string&gt;</div>
<div id="_mcePaste">&lt;string&gt;paste:&lt;/string&gt;</div>
<div id="_mcePaste">&lt;string&gt;selectToMark:&lt;/string&gt;</div>
<div id="_mcePaste">&lt;/array&gt;</div>
<div id="_mcePaste">&lt;key&gt;^~\U701&lt;/key&gt;</div>
<div id="_mcePaste">&lt;array&gt;</div>
<div id="_mcePaste">&lt;string&gt;copy:&lt;/string&gt;</div>
<div id="_mcePaste">&lt;string&gt;moveDown:&lt;/string&gt;</div>
<div id="_mcePaste">&lt;string&gt;moveToBeginningOfLine:&lt;/string&gt;</div>
<div id="_mcePaste">&lt;string&gt;insertLineBreak:&lt;/string&gt;</div>
<div id="_mcePaste">&lt;string&gt;insertNewLine:&lt;/string&gt;</div>
<div id="_mcePaste">&lt;string&gt;moveUp:&lt;/string&gt;</div>
<div id="_mcePaste">&lt;string&gt;setMark:&lt;/string&gt;</div>
<div id="_mcePaste">&lt;string&gt;paste:&lt;/string&gt;</div>
<div id="_mcePaste">&lt;string&gt;selectToMark:&lt;/string&gt;</div>
<div id="_mcePaste">&lt;/array&gt;</div>
<div><strong>2. Delete Line.</strong></div>
<div>Deletes the current line your cursor is on. press Ctrl + D.</div>
<div>
<div><span style="white-space: pre;">&lt;key&gt;^d&lt;/key&gt; </span></div>
<div><span style="white-space: pre;">&lt;array&gt; </span></div>
<div><span style="white-space: pre;">&lt;string&gt;cut:&lt;/string&gt; </span></div>
<div><span style="white-space: pre;">&lt;string&gt;selectLine:&lt;/string&gt; </span></div>
<div><span style="white-space: pre;">&lt;string&gt;cut:&lt;/string&gt; </span></div>
<div><span style="white-space: pre;">&lt;/array&gt;</span></div>
</div>
]]></content:encoded>
			<wfw:commentRss>http://www.betadesigns.co.uk/Blog/2010/02/03/custom-xcode-shortcuts/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Forcing Firefox to open Flex in the same window</title>
		<link>http://www.betadesigns.co.uk/Blog/2009/11/16/forcing-firefox-to-open-flex-in-the-same-window/</link>
		<comments>http://www.betadesigns.co.uk/Blog/2009/11/16/forcing-firefox-to-open-flex-in-the-same-window/#comments</comments>
		<pubDate>Mon, 16 Nov 2009 10:44:01 +0000</pubDate>
		<dc:creator>Anthony</dc:creator>
				<category><![CDATA[Flex]]></category>

		<guid isPermaLink="false">http://www.betadesigns.co.uk/Blog/?p=126</guid>
		<description><![CDATA[Using FireFox as your main browser when developing on Windows means that by default you end up getting loads of tabs for all your canceled debug sessions. In order to prevent this behavior simply type in
about:config
into the address bar and do a search for
browser.link.open_external
then change it's value from 3 to 1; this will make your [...]]]></description>
			<content:encoded><![CDATA[<p id="top" />Using FireFox as your main browser when developing on Windows means that by default you end up getting loads of tabs for all your canceled debug sessions. In order to prevent this behavior simply type in<br />
about:config<br />
into the address bar and do a search for<br />
browser.link.open_external<br />
then change it's value from 3 to 1; this will make your flex debug session always appear in one tab.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.betadesigns.co.uk/Blog/2009/11/16/forcing-firefox-to-open-flex-in-the-same-window/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Code Optimization tricks</title>
		<link>http://www.betadesigns.co.uk/Blog/2009/10/14/code-optimization-tricks/</link>
		<comments>http://www.betadesigns.co.uk/Blog/2009/10/14/code-optimization-tricks/#comments</comments>
		<pubDate>Wed, 14 Oct 2009 08:03:37 +0000</pubDate>
		<dc:creator>Anthony</dc:creator>
				<category><![CDATA[Flex]]></category>
		<category><![CDATA[bits]]></category>
		<category><![CDATA[bitswise]]></category>
		<category><![CDATA[maths]]></category>
		<category><![CDATA[optimization]]></category>

		<guid isPermaLink="false">http://www.betadesigns.co.uk/Blog/?p=100</guid>
		<description><![CDATA[Collapse literal values
&#160;
  var a : uint = b + &#40; 10024-200 &#41; / 2;//195ms
√ var a : uint = b + 412;//47ms
&#160;
Multiplication is faster than Division
nice explanation of using multiplication for division here
&#160;
  result = num / 4;//382ms
√ result = num * 0.25;//132ms
&#160;
Use Implicit type casting
&#160;
  var a : Point = [...]]]></description>
			<content:encoded><![CDATA[<p id="top" /><strong>Collapse literal values</strong></p>
<pre class="flex">&nbsp;
  <span style="color: #b7cfe7; font-weight: bold;">var</span> a : uint = b + <span style="color: #000000;">&#40;</span> <span style="color: #000000;">10024</span><span style="color: #000000;">-200</span> <span style="color: #000000;">&#41;</span> / <span style="color: #000000;">2</span>;<span style="color: #009900; font-style: italic;">//195ms</span>
√ <span style="color: #b7cfe7; font-weight: bold;">var</span> a : uint = b + <span style="color: #000000;">412</span>;<span style="color: #009900; font-style: italic;">//47ms</span>
&nbsp;</pre>
<p><strong>Multiplication is faster than Division</strong><br />
nice explanation of using multiplication for division <a href="http://gmplib.org/~tege/divcnst-pldi94.pdf">here</a></p>
<pre class="flex">&nbsp;
  result = num / <span style="color: #000000;">4</span>;<span style="color: #009900; font-style: italic;">//382ms</span>
√ result = num * <span style="color: #000000;">0.25</span>;<span style="color: #009900; font-style: italic;">//132ms</span>
&nbsp;</pre>
<p><strong>Use Implicit type casting</strong></p>
<pre class="flex">&nbsp;
  <span style="color: #b7cfe7; font-weight: bold;">var</span> a : Point = points<span style="color: #000000;">&#91;</span> i <span style="color: #000000;">&#93;</span> <span style="color: #5b7bff; font-weight: bold;">as</span> Point;<span style="color: #009900; font-style: italic;">//179ms</span>
√ <span style="color: #b7cfe7; font-weight: bold;">var</span> a : Point = points<span style="color: #000000;">&#91;</span> i <span style="color: #000000;">&#93;</span>;<span style="color: #009900; font-style: italic;">//109ms</span>
&nbsp;</pre>
<p><strong>Test variables before methods in statements</strong></p>
<pre class="flex">&nbsp;
  <span style="color: #5b7bff; font-weight: bold;">if</span><span style="color: #000000;">&#40;</span>method<span style="color: #000000;">&#40;</span> <span style="color: #000000;">&#41;</span> &amp;&amp; variable <span style="color: #000000;">&#41;</span><span style="color: #009900; font-style: italic;">//211ms</span>
√ <span style="color: #5b7bff; font-weight: bold;">if</span><span style="color: #000000;">&#40;</span> variable &amp;&amp; method<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span> <span style="color: #000000;">&#41;</span><span style="color: #009900; font-style: italic;">//7ms</span>
&nbsp;</pre>
<p><strong>Declare varialbes outside of loops</strong></p>
<pre class="flex">&nbsp;
<span style="color: #5b7bff; font-weight: bold;">for</span><span style="color: #000000;">&#40;</span> <span style="color: #b7cfe7; font-weight: bold;">var</span> i : int = <span style="color: #000000;">0</span>; i &lt; arr.<span style="color: #000000;">length</span>; i ++ <span style="color: #000000;">&#41;</span><span style="color: #009900; font-style: italic;">//515ms</span>
  <span style="color: #b7cfe7; font-weight: bold;">var</span> i : int = <span style="color: #000000;">0</span>;
  <span style="color: #b7cfe7; font-weight: bold;">var</span> arrLength : int = arr.<span style="color: #000000;">length</span>;
√ <span style="color: #5b7bff; font-weight: bold;">for</span><span style="color: #000000;">&#40;</span> ; i &lt; arr.<span style="color: #000000;">length</span>; i ++ <span style="color: #000000;">&#41;</span><span style="color: #009900; font-style: italic;">//39ms</span>
&nbsp;</pre>
<p><strong>Thowing erors takes time.</strong></p>
<pre class="flex">&nbsp;
  <span style="color: #5b7bff; font-weight: bold;">try</span><span style="color: #000000;">&#123;</span> isNull.<span style="color: #000000;">x</span> = <span style="color: #000000;">3</span>; <span style="color: #000000;">&#125;</span><span style="color: #5b7bff; font-weight: bold;">catch</span><span style="color: #000000;">&#40;</span> e : Error <span style="color: #000000;">&#41;</span><span style="color: #000000;">&#123;</span> <span style="color: #000000;">&#125;</span><span style="color: #009900; font-style: italic;">//78ms</span>
√ <span style="color: #5b7bff; font-weight: bold;">if</span><span style="color: #000000;">&#40;</span> isNull <span style="color: #000000;">&#41;</span> <span style="color: #000000;">&#123;</span> isNull.<span style="color: #000000;">x</span> = <span style="color: #000000;">3</span>; <span style="color: #000000;">&#125;</span><span style="color: #009900; font-style: italic;">//0ms</span>
&nbsp;</pre>
<p><strong>Use references instead of full paths or the with operator.</strong></p>
<pre class="flex">&nbsp;
  with<span style="color: #000000;">&#40;</span> sprite.<span style="color: #000000;">graphics</span> <span style="color: #000000;">&#41;</span><span style="color: #000000;">&#123;</span> ...<span style="color: #000000;">&#125;</span>;<span style="color: #009900; font-style: italic;">//164ms</span>
√ <span style="color: #b7cfe7; font-weight: bold;">var</span> g : Graphics = sprite.<span style="color: #000000;">graphics</span>;<span style="color: #009900; font-style: italic;">//23ms</span>
&nbsp;</pre>
<p><strong><a href="http://lab.polygonal.de/2008/06/18/using-object-pools/">Use Object Pools</a></strong></p>
<p><strong>Bitwise tricks</strong><br />
<a href="http://http://en.wikipedia.org/wiki/Binary_numeral_system">Bitwise maths on wikipedia</a> <a href="http://en.wikipedia.org/wiki/Boolean_algebra_(logic)">Boolean algebra on wikipedia</a><br />
<a href="http://lab.polygonal.de/2007/05/10/bitwise-gems-fast-integer-math/">polygonal labs bitwise gems</a></p>
<pre class="flex">&nbsp;
val = num | <span style="color: #000000;">0</span>; <span style="color: #009900; font-style: italic;">//Same as Math.floor();</span>
val = num + <span style="color: #000000;">0.5</span> | <span style="color: #000000;">0</span>; <span style="color: #009900; font-style: italic;">// Rounds positive numbers.</span>
<span style="color: #009900; font-style: italic;">//Divide by power of two</span>
val = num &gt;&gt;<span style="color: #000000;">1</span>; <span style="color: #009900; font-style: italic;">//Divide by 2 and floor.</span>
val = num / <span style="color: #000000;">32</span> is the same <span style="color: #5b7bff; font-weight: bold;">as</span> val = num &gt;&gt; <span style="color: #000000;">5</span>
val = <span style="color: #000000;">65535</span> &gt;&gt; <span style="color: #000000;">8</span>; <span style="color: #009900; font-style: italic;">//255</span>
<span style="color: #009900; font-style: italic;">//actual value is 255.996...</span>
<span style="color: #009900; font-style: italic;">//But it is being floored as well</span>
i = <span style="color: #000000;">&#40;</span>x^<span style="color: #000000;">&#40;</span>x&gt;&gt;<span style="color: #000000;">31</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">&#41;</span> - <span style="color: #000000;">&#40;</span>x&gt;&gt;<span style="color: #000000;">31</span><span style="color: #000000;">&#41;</span>;<span style="color: #009900; font-style: italic;">//about 2700% faster than Maths.abs();</span>
&nbsp;
<span style="color: #5b7bff; font-weight: bold;">if</span><span style="color: #000000;">&#40;</span>++count&amp;<span style="color: #000000;">1</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">&#123;</span><span style="color: #000000;">&#125;</span><span style="color: #009900; font-style: italic;">//alternation i need to check this one.</span>
&nbsp;</pre>
]]></content:encoded>
			<wfw:commentRss>http://www.betadesigns.co.uk/Blog/2009/10/14/code-optimization-tricks/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
