<?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"
	>

<channel>
	<title>AH:</title>
	<atom:link href="http://www.hulstkamp.com/feed" rel="self" type="application/rss+xml" />
	<link>http://www.hulstkamp.com</link>
	<description>andy hulstkamp blog about rich internet applications, flex, flash, java, webapps, web, code, experiments</description>
	<pubDate>Fri, 14 Aug 2009 13:41:13 +0000</pubDate>
	<generator>http://wordpress.org/?v=2.6.1</generator>
	<language>en</language>
			<item>
		<title>Custom PopUp Rating Component in Spark Flex 4 (Gumbo)</title>
		<link>http://www.hulstkamp.com/2009/07/09/custom-popup-rating-component-in-spark-flex-4-gumbo/464</link>
		<comments>http://www.hulstkamp.com/2009/07/09/custom-popup-rating-component-in-spark-flex-4-gumbo/464#comments</comments>
		<pubDate>Thu, 09 Jul 2009 08:12:08 +0000</pubDate>
		<dc:creator>Andy Hulstkamp</dc:creator>
		
		<category><![CDATA[FXG]]></category>

		<category><![CDATA[Gumbo (Flex 4 beta)]]></category>

		<category><![CDATA[custom component]]></category>

		<category><![CDATA[effects]]></category>

		<category><![CDATA[masking]]></category>

		<category><![CDATA[popup]]></category>

		<category><![CDATA[rating]]></category>

		<category><![CDATA[skin parts]]></category>

		<category><![CDATA[Spark]]></category>

		<category><![CDATA[states]]></category>

		<category><![CDATA[Transitions]]></category>

		<guid isPermaLink="false">http://www.hulstkamp.com/?p=464</guid>
		<description><![CDATA[I was experimenting a little with the PopUpAnchor in Spark Flex 4 and came up with a new custom component for ratings. The new component has the following characteristics:

Show a placeholder-icon that reflects the current rating and serves as an interactive element to open the ratings
ratings pop up for adjustment
both the placeholder-icon and the ratings-icons [...]]]></description>
			<content:encoded><![CDATA[<p>I was experimenting a little with the PopUpAnchor in Spark Flex 4 and came up with a new custom component for ratings. The new component has the following characteristics:</p>
<ul>
<li>Show a placeholder-icon that reflects the current rating and serves as an interactive element to open the ratings</li>
<li>ratings pop up for adjustment</li>
<li>both the placeholder-icon and the ratings-icons will be gradually filled with color when adjustments are being made</li>
<li>the icons are defined in FXG</li>
<li>the icons are not defined in the skin but can be passed as a style for generic use (one skin for different icons and ratings)</li>
<li>there is colorization of the icons based on styles</li>
<li>smooth transitions when opening the ratings</li>
</ul>
<p><a href="http://www.hulstkamp.com/byard/gumbo/cityRating/AHPopUpAnchorTest.html">Here&#8217;s a pseudo city-rating demo</a> that shows variations of the component using different icons and color settings for different ratings.</p>
<p><a href="http://www.hulstkamp.com/byard/gumbo/cityRating/AHPopUpAnchorTest.html"><img src="http://www.hulstkamp.com/byard/gumbo/cityRating/cityRatingComponent.png" alt="City Rating Component" /></a></p>
<p>You&#8217;ll find the source at the end of this post. It is <span id="more-464"></span>fully documented but here&#8217;s an overview of the key-concept nonetheless.</p>
<h3>Skin-Parts</h3>
<p>There are skin-parts for the open-button (which is actually a group that works as a button), the drop-down which is a group that holds the entire pop-up, the active-group and the passive-group that hold the icons for adjustments of the rating and the label-element to show the rating as text.</p>
<h3>Building the View</h3>
<p>The icons are not part of the skin. They will be set at run time and are pushed down to the skin when the component loads the different skin-parts.</p>
<p>In partAdded() of the component, the active-group and the passive-group are filled with the icons. Five icons in a colorized version are pushed down to the active part.  Five default icons are pushed down to the passive-group.</p>
<h3>Masking and Fill Effect</h3>
<p>To create an effect that gives the impression of gradually filling the icons when the rating is adjusted, masks are used.  When skin-parts are loaded, the component applies a mask to the active-group.  When the mouse is dragged to adjust the rating, the width of the mask is updated and the (colorized) icons of the active-group are revealed.</p>
<p>The mask is not part of the skin. It is created at run-time by the component and applied to the relevant skin-part.</p>
<h3>FXG Icons passed via Styles</h3>
<p>The Icons are defined in FXG. Basically each Icon is a MXML-Component. The Icons are passed as a ClassReference to the component via styles. The ClassReference is then used to create an instance of this class at run-time. The instances of the icon are then added to their respective groups.<br />
An Icon is basically a mxml-component that extends from Group. You can create your own and reference it via the rating Icon style.</p>
<h3>Colorization based on Styles</h3>
<p>The Icons are colorized at run-time. Based on some colors that are passed as styles the icons get colorized using a ColorTransform.</p>
<h3>Effects on PopUp</h3>
<p>There is a resize and a fade effect when the pop up is openend. These are defined on the skin - you can remove them by simply commenting out the transition part in the skin.</p>
<h3>Separation of Concerns</h3>
<p>Spark promotes a clean separation of concerns. The Component should keep track of the data/state and work as a controller, the skin is there for the view.  I decided to create and update the mask in the component, because the masking effect is an inherent part of this implementation and setting up the masking infrastructure in the component helps to keep the skin cleaner. Another approach would be to define the mask in the skin, then pull the value for the rating from the component and adjust the mask accordingly.<br />
Still, every aspect of the look (gap, background-colors, borders, effects etc.) is controlled by the skin.</p>
<h3>Usage</h3>
<p>Setting the basic styles for the AHPopUpRatingComponent:</p>

<div class="wp_syntax"><div class="code"><pre class="css css" style="font-family:monospace;">ah|AHPopUpRatingComponent <span style="color: #00AA00;">&#123;</span>
	skinClass<span style="color: #00AA00;">:</span> ClassReference<span style="color: #00AA00;">&#40;</span><span style="color: #ff0000;">'AHPopUpRatingComponentSkin'</span><span style="color: #00AA00;">&#41;</span>;
	passiveIconColor<span style="color: #00AA00;">:</span> <span style="color: #ff0000;">&quot;0x808080&quot;</span>;
	activeIconColor<span style="color: #00AA00;">:</span> <span style="color: #ff0000;">&quot;0xc0c0c0&quot;</span>;
	baseColor<span style="color: #00AA00;">:</span> <span style="color: #ff0000;">&quot;0xb0b0b0&quot;</span>;
<span style="color: #00AA00;">&#125;</span></pre></div></div>

<p>Using a variation of style values: For this example use styleName=&#8217;medicareRating&#8217; on the component to set the css-class. It uses the Icon under myLibrary.HealthCross and has a light blue color for the active icons.</p>

<div class="wp_syntax"><div class="code"><pre class="css css" style="font-family:monospace;">ah|AHPopUpRatingComponent<span style="color: #6666ff;">.medicareRating</span> <span style="color: #00AA00;">&#123;</span>
	ratingIcon<span style="color: #00AA00;">:</span> ClassReference<span style="color: #00AA00;">&#40;</span><span style="color: #ff0000;">'myLibrary.HealthCross'</span><span style="color: #00AA00;">&#41;</span>;
	activeIconColor<span style="color: #00AA00;">:</span> <span style="color: #ff0000;">&quot;0xCAEAFF&quot;</span>;
<span style="color: #00AA00;">&#125;</span></pre></div></div>

<p>The icons are mxml-components, that extend from Group. Use the fully qualified class-path in the ClassReference of the ratingIcon-style to reference the icon. Here&#8217;s an example:</p>

<div class="wp_syntax"><div class="code"><pre class="mxml mxml" style="font-family:monospace;"><span style="color: #000000;"><span style="color: #7400FF;">&lt;s:Group</span> horizontalCenter=<span style="color: #ff0000;">&quot;0&quot;</span> verticalCenter=<span style="color: #ff0000;">&quot;0&quot;</span> width=<span style="color: #ff0000;">&quot;25&quot;</span> height=<span style="color: #ff0000;">&quot;25&quot;</span>  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><span style="color: #7400FF;">&gt;</span></span>
	<span style="color: #000000;"><span style="color: #7400FF;">&lt;s:Path</span>  x=<span style="color: #ff0000;">&quot;5&quot;</span> winding=<span style="color: #ff0000;">&quot;nonZero&quot;</span> ai:knockout=<span style="color: #ff0000;">&quot;0&quot;</span> data=<span style="color: #ff0000;">&quot;M 9.404 0.01 C 9.051 8.355 -1.506 9.232 3.065 16.324 C 1.835 17.4 0.006 19.866 0.006 25.01 L 1.886 25.01 C 1.886 20.554 3.357 18.569 4.244 17.776 C 18.309 18.361 13.558 4.163 9.404 0.01 Z&quot;</span> <span style="color: #7400FF;">&gt;</span></span>
		<span style="color: #000000;"><span style="color: #7400FF;">&lt;s:fill</span><span style="color: #7400FF;">&gt;</span></span>
			<span style="color: #000000;"><span style="color: #7400FF;">&lt;s:LinearGradient</span> x=<span style="color: #ff0000;">&quot;6.82861&quot;</span> y=<span style="color: #ff0000;">&quot;0.00683594&quot;</span> scaleX=<span style="color: #ff0000;">&quot;25&quot;</span> rotation=<span style="color: #ff0000;">&quot;90&quot;</span><span style="color: #7400FF;">&gt;</span></span>
				<span style="color: #000000;"><span style="color: #7400FF;">&lt;s:GradientEntry</span> color=<span style="color: #ff0000;">&quot;0xfbfbfb&quot;</span> ratio=<span style="color: #ff0000;">&quot;0&quot;</span><span style="color: #7400FF;">/&gt;</span></span>
				<span style="color: #000000;"><span style="color: #7400FF;">&lt;s:GradientEntry</span> color=<span style="color: #ff0000;">&quot;0xdcdcdc&quot;</span> ratio=<span style="color: #ff0000;">&quot;0.5&quot;</span><span style="color: #7400FF;">/&gt;</span></span>
				<span style="color: #000000;"><span style="color: #7400FF;">&lt;s:GradientEntry</span> color=<span style="color: #ff0000;">&quot;0xcccccc&quot;</span> ratio=<span style="color: #ff0000;">&quot;0.5&quot;</span><span style="color: #7400FF;">/&gt;</span></span>
				<span style="color: #000000;"><span style="color: #7400FF;">&lt;s:GradientEntry</span> color=<span style="color: #ff0000;">&quot;0x909090&quot;</span> ratio=<span style="color: #ff0000;">&quot;1&quot;</span><span style="color: #7400FF;">/&gt;</span></span>
			<span style="color: #000000;"><span style="color: #7400FF;">&lt;/s:LinearGradient</span><span style="color: #7400FF;">&gt;</span></span>
		<span style="color: #000000;"><span style="color: #7400FF;">&lt;/s:fill</span><span style="color: #7400FF;">&gt;</span></span>
		<span style="color: #000000;"><span style="color: #7400FF;">&lt;s:stroke</span><span style="color: #7400FF;">&gt;</span></span>
			<span style="color: #000000;"><span style="color: #7400FF;">&lt;s:SolidColorStroke</span> color=<span style="color: #ff0000;">&quot;0xd8d8d8&quot;</span> caps=<span style="color: #ff0000;">&quot;none&quot;</span> weight=<span style="color: #ff0000;">&quot;1&quot;</span> joints=<span style="color: #ff0000;">&quot;miter&quot;</span> miterLimit=<span style="color: #ff0000;">&quot;4&quot;</span><span style="color: #7400FF;">/&gt;</span></span>
		<span style="color: #000000;"><span style="color: #7400FF;">&lt;/s:stroke</span><span style="color: #7400FF;">&gt;</span></span>
	<span style="color: #000000;"><span style="color: #7400FF;">&lt;/s:Path</span><span style="color: #7400FF;">&gt;</span></span>
<span style="color: #000000;"><span style="color: #7400FF;">&lt;/s:Group</span><span style="color: #7400FF;">&gt;</span></span></pre></div></div>

<p>Get the source (sdk: 7282) <a href="http://www.hulstkamp.com/byard/gumbo/cityRating/srcview/index.html">here</a>.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.hulstkamp.com/2009/07/09/custom-popup-rating-component-in-spark-flex-4-gumbo/464/feed</wfw:commentRss>
		</item>
		<item>
		<title>Advanced FXG Spark Icon Buttons with one generic skin in Flex4 (Gumbo)</title>
		<link>http://www.hulstkamp.com/2009/06/20/advanced-fxg-spark-icon-buttons-with-one-generic-skin-in-flex4-gumbo/439</link>
		<comments>http://www.hulstkamp.com/2009/06/20/advanced-fxg-spark-icon-buttons-with-one-generic-skin-in-flex4-gumbo/439#comments</comments>
		<pubDate>Sat, 20 Jun 2009 17:49:25 +0000</pubDate>
		<dc:creator>Andy Hulstkamp</dc:creator>
		
		<category><![CDATA[Actionscript 3]]></category>

		<category><![CDATA[FXG]]></category>

		<category><![CDATA[Gumbo (Flex 4 beta)]]></category>

		<category><![CDATA[effects]]></category>

		<category><![CDATA[generic]]></category>

		<category><![CDATA[Icons]]></category>

		<category><![CDATA[pseudo selectors]]></category>

		<category><![CDATA[skinning]]></category>

		<category><![CDATA[states]]></category>

		<category><![CDATA[Transitions]]></category>

		<guid isPermaLink="false">http://www.hulstkamp.com/?p=439</guid>
		<description><![CDATA[For the past couple of days I&#8217;ve had a look at creating Spark Icon Buttons. In this post I&#8217;ve created an FXG Icon Button with some transitions, leveraging pseudo selectors for states. The Icon was &#8216;hardcoded&#8217; into the skin. For another Icon I would need to duplicate the skin and introduce another graphic. Not exactly [...]]]></description>
			<content:encoded><![CDATA[<p>For the past couple of days I&#8217;ve had a look at creating Spark Icon Buttons. In <a href="http://www.hulstkamp.com/2009/06/18/spark-icon-button-with-gradient-effects-and-filter-animation-colorized-by-styles-flex-4-gumbo/403">this post</a> I&#8217;ve created an FXG Icon Button with some transitions, leveraging pseudo selectors for states. The Icon was &#8216;hardcoded&#8217; into the skin. For another Icon I would need to duplicate the skin and introduce another graphic. Not exactly generic. There are <a href="http://www.hulstkamp.com/?p=433">other ways</a> to bring graphics into Spark Skins but none of them work with FXG Elements directly.</p>
<p>What I want is:</p>
<ul>
<li>work with FXG Graphic Elements for simpler manipulation and scaling</li>
<li>easily export the FXG-Definitions for the icons from a tool and/or be able to change them in FB directly</li>
<li>colorize the icons based on a color style-property and do this per state</li>
<li>change the icons based on a style-property and do this per state</li>
<li>change icons at runtime</li>
<li>scaling effect on icon</li>
<li>have ONE generic skin, so no duplicates for different icons are necessary</li>
</ul>
<p>Most of the trouble with generic skins comes from the fact that there is no way to access the FXG Library-Definitions at run-time  (as far as I know) - like getting an instance of a symbol in the library, the way we had in flash. Here&#8217;s a <a href="http://www.hulstkamp.com/2009/05/28/creating-fxg-library-elements-at-runtime-in-flex-4-gumbo/337">hack</a> but I&#8217;d rather not use it.</p>
<p>After some headaches I finally managed to get a solution I can live with:</p>
<p><a href="http://www.hulstkamp.com/byard/gumbo/GenericFXGIconButtons/AHFXGIconTest.html"><img class="alignnone" title="Generic FXG Icon Buttons" src="http://www.hulstkamp.com/byard/gumbo/GenericFXGIconButtons/GenericFXGIconButtons.png" alt="" width="512" height="193" /></a></p>
<p>Click <a href="http://www.hulstkamp.com/byard/gumbo/GenericFXGIconButtons/AHFXGIconTest.html">here</a> for a test.</p>
<p>You&#8217;ll find the source at the end of this post.</p>
<p>The solution regarding the work flow mainly comes down to<span id="more-439"></span></p>
<ul>
<li>Create Icons in Illustrator and convert them to symbols. One symbol per icon, name them. Save from Illustrator as ai.</li>
<li>Load the Illustrator-File in Flash Catalyst and go to the Code-View</li>
<li>You&#8217;ll see that FC creates mxml-files with the graphical content per icon</li>
<li>Copy these files over to Flex-Builder or set the source path so that the catalyst export is in your flex project</li>
</ul>
<p>In the code there are some key concepts:</p>
<ul>
<li>In the skin there is a group where the icons will get attached at run time</li>
<li>The skin listens for state changes and creates an instance of an icon component based on the iconName that is passed via styles.</li>
<li>There is some caching involved, so that there will be no instantiation when an icon/state has allready been created</li>
<li>The Icons get colorized based on a style property and - if defined  - per state.</li>
<li>The colorization occurs recursively, diving through the nested elements and setting the color of any nested FilledElement</li>
<li>There is some code involved that manages the scaling of the new instances for the transitions</li>
<li>Icons, colors and baseColors can be set via styles (and using pseudo selectors for over and down states)</li>
</ul>
<p>Here&#8217;s the <a href="http://www.hulstkamp.com/byard/gumbo/GenericFXGIconButtons/srcview/index.html">source </a>(sdk 4.0.0.7282)</p>
<p>Note: As a variation to instantiate the icons you could put all the FXG-Definition in the Skin inside the library and create them at runtime using the hack mentioned at the beginning of this post.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.hulstkamp.com/2009/06/20/advanced-fxg-spark-icon-buttons-with-one-generic-skin-in-flex4-gumbo/439/feed</wfw:commentRss>
		</item>
		<item>
		<title>Getting Vector Graphics into Spark Skins</title>
		<link>http://www.hulstkamp.com/2009/06/20/getting-vector-graphics-into-spark-skins/433</link>
		<comments>http://www.hulstkamp.com/2009/06/20/getting-vector-graphics-into-spark-skins/433#comments</comments>
		<pubDate>Sat, 20 Jun 2009 10:42:13 +0000</pubDate>
		<dc:creator>Andy Hulstkamp</dc:creator>
		
		<category><![CDATA[FXG]]></category>

		<category><![CDATA[Flash]]></category>

		<category><![CDATA[Gumbo (Flex 4 beta)]]></category>

		<category><![CDATA[Misc]]></category>

		<category><![CDATA[embed]]></category>

		<category><![CDATA[graphics]]></category>

		<category><![CDATA[load]]></category>

		<category><![CDATA[skin]]></category>

		<category><![CDATA[vectros]]></category>

		<guid isPermaLink="false">http://www.hulstkamp.com/?p=433</guid>
		<description><![CDATA[It was funny to see how many examples of Spark Icon Buttons have shown up in the past few days. Andy mcintosh did an example here, Ben another one here, I did one myself here. While all were using a slightly different approach the motivation behind them was probably, that the Spark Button does not [...]]]></description>
			<content:encoded><![CDATA[<p>It was funny to see how many examples of Spark Icon Buttons have shown up in the past few days. Andy mcintosh did an example <a href="http://www.andymcintosh.com/?p=179">here</a>, Ben another one <a href="http://www.themorphicgroup.com/blog/2009/06/18/how-to-create-a-spark-icon-button-and-skin/">here</a>, I did one myself <a href="http://www.hulstkamp.com/2009/06/18/spark-icon-button-with-gradient-effects-and-filter-animation-colorized-by-styles-flex-4-gumbo/403">here</a>. While all were using a slightly different approach the motivation behind them was probably, that the Spark Button does not have an icon property compared to the Halo coutnerpart.</p>
<p>Out of the box there are basically three ways to get graphics into a Spark skin.<span id="more-433"></span></p>
<hr />
<h3>Use Image:</h3>
<p>Use an Image component in the skin of the button and embed the icon into a style that is used by the button (Using a property and fetching the graphic from there is another variation).</p>

<div class="wp_syntax"><div class="code"><pre class="mxml mxml" style="font-family:monospace;">.btnClass {
symbol: Embed(source='../assets/crossSymbols.swf', symbol='addCross');
}
...
<span style="color: #000000;"><span style="color: #7400FF;">&lt;mx:Image</span> id=<span style="color: #ff0000;">&quot;symbol&quot;</span>  source=<span style="color: #ff0000;">&quot;{hostComponent.getStyle('symbol')}&quot;</span> <span style="color: #7400FF;">/&gt;</span></span>
...
or
...
<span style="color: #000000;"><span style="color: #7400FF;">&lt;s:BitmapImage</span>  source=<span style="color: #ff0000;">&quot;{hostComponent.getStyle('symbol')}&quot;</span> <span style="color: #7400FF;">/&gt;</span></span></pre></div></div>

<h4>pros:</h4>
<ul>
<li>Can use bitmaps or vectors</li>
<li>When using vectors, scaling effects of the graphic works well</li>
<li>possible loading of graphics at run time</li>
<li>reusable skin for different graphics</li>
</ul>
<h4>cons:</h4>
<ul>
<li>Overhead by using Halo Component in the skin</li>
<li>No FXG defined graphics, if you want them.</li>
</ul>
<hr />
<h3>Use Spark BitmapImage</h3>
<p>Works the same way as above, but uses an BitmapImage in the skin:</p>
<h4>pros:</h4>
<ul>
<li>Can use bitmaps or vectors</li>
<li>reusable skin for different graphics</li>
</ul>
<h4>cons:</h4>
<ul>
<li>Vectors are internally drawn to a bitmap an treated accordingly</li>
<li>Scaling effects work not so well since bitmaps are used</li>
<li>No FXG defined graphics, if you want them.</li>
</ul>
<hr />
<h3>Use FXG GraphicElements</h3>
<p>The Graphics are defined by FXG Graphic Elements directly.</p>
<h4>pros:</h4>
<ul>
<li>Uses FXG (with possible bi-directional tooling support)</li>
</ul>
<h4>cons:</h4>
<ul>
<li>Skins are not reusable for different graphics, graphic is &#8216;hardcoded&#8217; into the skin</li>
</ul>
<p>Personally, I&#8217;d love to use FXG. With Flash Catalyst, the FXG-Support in Illustrator et al. and the obvious commitment of Adobe to push FXG as the XML-based graphics interchange format for the Flash Platform, I guess it will be easier and more transparent to work with FXG when it comes to vector graphics. Exporting all the stuff to swfs or swcs is ok, but i&#8217;d rather not.</p>
<p>Now, creating a spark skin for every OK-, Submit- and Cancel IconButton etc. just won&#8217;t cut it. Sure you can copy the skin over but when you have lots of transitions and stuff and your client asks for a change you gonna have to repeatedly change the skins. Not very funny.</p>
<p>All that&#8217;s needed is a way to access the Library-definitions of FXG at runtime. Up until now, I haven&#8217;t found any, except for the hack I posted <a href="http://www.hulstkamp.com/2009/05/28/creating-fxg-library-elements-at-runtime-in-flex-4-gumbo/337">here</a>.</p>
<p>After banging my head against a wall again and again, I&#8217;ve finally found <a href="http://www.hulstkamp.com/2009/06/20/advanced-fxg-spark-icon-buttons-with-one-generic-skin-in-flex4-gumbo/439">another way I can live with</a>.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.hulstkamp.com/2009/06/20/getting-vector-graphics-into-spark-skins/433/feed</wfw:commentRss>
		</item>
		<item>
		<title>Spark Icon Button with Gradient effects and Filter animation, colorized by styles. Flex 4 (Gumbo)</title>
		<link>http://www.hulstkamp.com/2009/06/18/spark-icon-button-with-gradient-effects-and-filter-animation-colorized-by-styles-flex-4-gumbo/403</link>
		<comments>http://www.hulstkamp.com/2009/06/18/spark-icon-button-with-gradient-effects-and-filter-animation-colorized-by-styles-flex-4-gumbo/403#comments</comments>
		<pubDate>Thu, 18 Jun 2009 11:59:28 +0000</pubDate>
		<dc:creator>Andy Hulstkamp</dc:creator>
		
		<category><![CDATA[Actionscript 3]]></category>

		<category><![CDATA[FXG]]></category>

		<category><![CDATA[Gumbo (Flex 4 beta)]]></category>

		<category><![CDATA[advanced selectors]]></category>

		<category><![CDATA[animate]]></category>

		<category><![CDATA[AnimateColor]]></category>

		<category><![CDATA[button]]></category>

		<category><![CDATA[css]]></category>

		<category><![CDATA[effects]]></category>

		<category><![CDATA[Gradient]]></category>

		<category><![CDATA[Icon]]></category>

		<category><![CDATA[Pseudo]]></category>

		<category><![CDATA[Selectors]]></category>

		<category><![CDATA[Spark]]></category>

		<category><![CDATA[styles]]></category>

		<category><![CDATA[Transitions]]></category>

		<guid isPermaLink="false">http://www.hulstkamp.com/?p=403</guid>
		<description><![CDATA[update: Check this example for a more advanced and generic approach
Here&#8217;s an example of a Spark Icon Button done in Flex 4. There are smooth transitions on the background gradient between the up and over states. From the over state to the down state the shadows are removed smoothly. Each button has a different base [...]]]></description>
			<content:encoded><![CDATA[<p>update: Check <a href="http://www.hulstkamp.com/2009/06/20/advanced-fxg-spark-icon-buttons-with-one-generic-skin-in-flex4-gumbo/439">this example</a> for a more advanced and generic approach</p>
<p>Here&#8217;s an example of a Spark Icon Button done in Flex 4. There are smooth transitions on the background gradient between the up and over states. From the over state to the down state the shadows are removed smoothly. Each button has a different base color.</p>
<p><a href="http://www.hulstkamp.com/byard/gumbo/iconButton/AHSimpleIconButtonTest.html"><img title="Spark Icon Buttons with transitions" src="http://www.hulstkamp.com/byard/gumbo/iconButton/iconButtons.png" alt="Spark Icon Buttons with transitions" width="345" height="124" /></a></p>
<p>Click <a title="Spark Icon Button Demo" href="http://www.hulstkamp.com/byard/gumbo/iconButton/AHSimpleIconButtonTest.html">here</a> for a demo.</p>
<p>Apart from the new skinning architecture there are a couple of <span id="more-403"></span>aspects that make defining the look and feel of Spark Components easy:</p>
<ul>
<li>Transitions and effects that look up the values in the states</li>
<li>Pseudo-Selectors for component-states, as well as id- and descendant selectors</li>
<li>Enhanced states with group states.</li>
<li>Colorization and exclusion</li>
</ul>
<p></p>
<h4>Transitions &#038; effects</h4>
<p>In this example the skin defines some transitions. There are <em>AnimateColor </em>effects that work on the gradient entries. There&#8217;s no special configuration involved, since the default-property that <em>AnimateColor </em>works on is&#8230; <em>color </em>. On the GradientEntry object there is a property for color. Flex automatically looks up the color values from the referenced states on the gradient entries.</p>
<p>In the states declarations there is an additional <em>stateGroups </em>&#8216;<em>overStates</em>&#8216; defined, that is referenced by the gradient entries.  So there&#8217;s no need to explicitly define the colors for every state.</p>

<div class="wp_syntax"><div class="code"><pre class="mxml mxml" style="font-family:monospace;"><span style="color: #000000;"><span style="color: #7400FF;">&lt;s:states</span><span style="color: #7400FF;">&gt;</span></span>
  <span style="color: #000000;"><span style="color: #7400FF;">&lt;s:State</span> name=<span style="color: #ff0000;">&quot;up&quot;</span> <span style="color: #7400FF;">/&gt;</span></span>
  <span style="color: #000000;"><span style="color: #7400FF;">&lt;s:State</span> name=<span style="color: #ff0000;">&quot;over&quot;</span> stateGroups=<span style="color: #ff0000;">&quot;overStates&quot;</span><span style="color: #7400FF;">/&gt;</span></span>
  <span style="color: #000000;"><span style="color: #7400FF;">&lt;s:State</span> name=<span style="color: #ff0000;">&quot;down&quot;</span> stateGroups=<span style="color: #ff0000;">&quot;overStates&quot;</span> <span style="color: #7400FF;">/&gt;</span></span>
  <span style="color: #000000;"><span style="color: #7400FF;">&lt;s:State</span> name=<span style="color: #ff0000;">&quot;disabled&quot;</span> <span style="color: #7400FF;">/&gt;</span></span>
<span style="color: #000000;"><span style="color: #7400FF;">&lt;/s:states</span><span style="color: #7400FF;">&gt;</span></span>
.
.
.
<span style="color: #000000;"><span style="color: #7400FF;">&lt;s:Transition</span>  fromState=<span style="color: #ff0000;">&quot;up&quot;</span> toState=<span style="color: #ff0000;">&quot;over&quot;</span> autoReverse=<span style="color: #ff0000;">&quot;true&quot;</span> <span style="color: #7400FF;">&gt;</span></span>
  <span style="color: #000000;"><span style="color: #7400FF;">&lt;s:AnimateColor</span>  targets=<span style="color: #ff0000;">&quot;{[ge1, ge2, ge3, ge4]}&quot;</span>  duration=<span style="color: #ff0000;">&quot;250&quot;</span> <span style="color: #7400FF;">/&gt;</span></span>
<span style="color: #000000;"><span style="color: #7400FF;">&lt;/s:Transition</span><span style="color: #7400FF;">&gt;</span></span>
<span style="color: #000000;"><span style="color: #7400FF;">&lt;s:Transition</span>  fromState=<span style="color: #ff0000;">&quot;over&quot;</span> toState=<span style="color: #ff0000;">&quot;up&quot;</span> autoReverse=<span style="color: #ff0000;">&quot;true&quot;</span> <span style="color: #7400FF;">&gt;</span></span>
  <span style="color: #000000;"><span style="color: #7400FF;">&lt;s:AnimateColor</span> targets=<span style="color: #ff0000;">&quot;{[ge1, ge2, ge3, ge4]}&quot;</span> duration=<span style="color: #ff0000;">&quot;750&quot;</span> <span style="color: #7400FF;">/&gt;</span></span>
<span style="color: #000000;"><span style="color: #7400FF;">&lt;/s:Transition</span><span style="color: #7400FF;">&gt;</span></span>
.
.
.
<span style="color: #000000;"><span style="color: #7400FF;">&lt;s:fill</span><span style="color: #7400FF;">&gt;</span></span>
  <span style="color: #000000;"><span style="color: #7400FF;">&lt;s:LinearGradient</span> x=<span style="color: #ff0000;">&quot;32.019&quot;</span> y=<span style="color: #ff0000;">&quot;0.5&quot;</span> scaleX=<span style="color: #ff0000;">&quot;25.5708&quot;</span> rotation=<span style="color: #ff0000;">&quot;90&quot;</span><span style="color: #7400FF;">&gt;</span></span>
	<span style="color: #000000;"><span style="color: #7400FF;">&lt;s:GradientEntry</span> id=<span style="color: #ff0000;">&quot;ge1&quot;</span> color=<span style="color: #ff0000;">&quot;#c0c0c0&quot;</span> color.overStates=<span style="color: #ff0000;">&quot;#ffffff&quot;</span> ratio=<span style="color: #ff0000;">&quot;0&quot;</span><span style="color: #7400FF;">/&gt;</span></span>
	<span style="color: #000000;"><span style="color: #7400FF;">&lt;s:GradientEntry</span> id=<span style="color: #ff0000;">&quot;ge2&quot;</span> color=<span style="color: #ff0000;">&quot;#939393&quot;</span> color.overStates=<span style="color: #ff0000;">&quot;#e3e3e3&quot;</span> ratio=<span style="color: #ff0000;">&quot;0.5&quot;</span><span style="color: #7400FF;">/&gt;</span></span>
	<span style="color: #000000;"><span style="color: #7400FF;">&lt;s:GradientEntry</span> id=<span style="color: #ff0000;">&quot;ge3&quot;</span> color=<span style="color: #ff0000;">&quot;#7e7e7e&quot;</span> color.overStates=<span style="color: #ff0000;">&quot;#cecece&quot;</span> ratio=<span style="color: #ff0000;">&quot;0.5&quot;</span><span style="color: #7400FF;">/&gt;</span></span>
	<span style="color: #000000;"><span style="color: #7400FF;">&lt;s:GradientEntry</span> id=<span style="color: #ff0000;">&quot;ge4&quot;</span> color=<span style="color: #ff0000;">&quot;#6a6a6a&quot;</span> color.overStates=<span style="color: #ff0000;">&quot;#bbbbbb&quot;</span> ratio=<span style="color: #ff0000;">&quot;1&quot;</span><span style="color: #7400FF;">/&gt;</span></span>
  <span style="color: #000000;"><span style="color: #7400FF;">&lt;/s:LinearGradient</span><span style="color: #7400FF;">&gt;</span></span>
<span style="color: #000000;"><span style="color: #7400FF;">&lt;/s:fill</span><span style="color: #7400FF;">&gt;</span></span></pre></div></div>

<p>There are also <em>Animate </em>effects that work on the <em>strength </em>of the <em>DropShadowFilters</em>. The <em>SimpleMotionPath</em> entries tell the <em>Animate </em>effect to work on the strength property. Note that there are no values defined on the effects &amp; properties of the transitions. Flex automatically looks up  the start and target values from the referenced states.</p>

<div class="wp_syntax"><div class="code"><pre class="mxml mxml" style="font-family:monospace;"><span style="color: #000000;"><span style="color: #7400FF;">&lt;s:Transition</span>  fromState=<span style="color: #ff0000;">&quot;over&quot;</span> toState=<span style="color: #ff0000;">&quot;down&quot;</span> autoReverse=<span style="color: #ff0000;">&quot;true&quot;</span> <span style="color: #7400FF;">&gt;</span></span>
   <span style="color: #000000;"><span style="color: #7400FF;">&lt;s:Animate</span> duration=<span style="color: #ff0000;">&quot;150&quot;</span> targets=<span style="color: #ff0000;">&quot;{[dsfBg, dsfSymbol]}&quot;</span> <span style="color: #7400FF;">&gt;</span></span>
	<span style="color: #000000;"><span style="color: #7400FF;">&lt;s:SimpleMotionPath</span>  property=<span style="color: #ff0000;">&quot;strength&quot;</span> <span style="color: #7400FF;">/&gt;</span></span>
  <span style="color: #000000;"><span style="color: #7400FF;">&lt;/s:Animate</span><span style="color: #7400FF;">&gt;</span></span>
<span style="color: #000000;"><span style="color: #7400FF;">&lt;/s:Transition</span><span style="color: #7400FF;">&gt;</span></span>
<span style="color: #000000;"><span style="color: #7400FF;">&lt;s:Transition</span>  fromState=<span style="color: #ff0000;">&quot;down&quot;</span> toState=<span style="color: #ff0000;">&quot;*&quot;</span> autoReverse=<span style="color: #ff0000;">&quot;true&quot;</span> <span style="color: #7400FF;">&gt;</span></span>
  <span style="color: #000000;"><span style="color: #7400FF;">&lt;s:Animate</span> duration=<span style="color: #ff0000;">&quot;150&quot;</span> targets=<span style="color: #ff0000;">&quot;{[dsfBg, dsfSymbol]}&quot;</span> <span style="color: #7400FF;">&gt;</span></span>
	<span style="color: #000000;"><span style="color: #7400FF;">&lt;s:SimpleMotionPath</span> property=<span style="color: #ff0000;">&quot;strength&quot;</span>  <span style="color: #7400FF;">/&gt;</span></span>
  <span style="color: #000000;"><span style="color: #7400FF;">&lt;/s:Animate</span><span style="color: #7400FF;">&gt;</span></span>
<span style="color: #000000;"><span style="color: #7400FF;">&lt;/s:Transition</span><span style="color: #7400FF;">&gt;</span></span>
.
.
.
<span style="color: #000000;"><span style="color: #7400FF;">&lt;s:filters</span><span style="color: #7400FF;">&gt;</span></span>
  <span style="color: #000000;"><span style="color: #7400FF;">&lt;s:DropShadowFilter</span> id=<span style="color: #ff0000;">&quot;dsfBg&quot;</span> alpha=<span style="color: #ff0000;">&quot;0.5&quot;</span> blurX=<span style="color: #ff0000;">&quot;0&quot;</span> blurY=<span style="color: #ff0000;">&quot;0&quot;</span> distance=<span style="color: #ff0000;">&quot;1&quot;</span> strength=<span style="color: #ff0000;">&quot;1&quot;</span> strength.down=<span style="color: #ff0000;">&quot;0&quot;</span>  <span style="color: #7400FF;">/&gt;</span></span>
<span style="color: #000000;"><span style="color: #7400FF;">&lt;/s:filters</span><span style="color: #7400FF;">&gt;</span></span>
.
.
.
<span style="color: #000000;"><span style="color: #7400FF;">&lt;s:filters</span><span style="color: #7400FF;">&gt;</span></span>
  <span style="color: #000000;"><span style="color: #7400FF;">&lt;s:DropShadowFilter</span> id=<span style="color: #ff0000;">&quot;dsfSymbol&quot;</span> blurX=<span style="color: #ff0000;">&quot;0&quot;</span> blurY=<span style="color: #ff0000;">&quot;0&quot;</span> distance=<span style="color: #ff0000;">&quot;1&quot;</span>  strength=<span style="color: #ff0000;">&quot;1&quot;</span> strength.down=<span style="color: #ff0000;">&quot;0&quot;</span><span style="color: #7400FF;">/&gt;</span></span>
<span style="color: #000000;"><span style="color: #7400FF;">&lt;/s:filters</span><span style="color: #7400FF;">&gt;</span></span></pre></div></div>

<p>Now, the buttons have a subtle effect when the mouse is rolled over and pressed: The gradient colors get lighter and the Shadows disappear giving the impression that the button is pressed.</p>
<p></p>
<h4>Styles. Pseudo-, Type-, Id- &#038; Class-Selectors</h4>
<p>We defined the gradients in grayscale. What when we want colored buttons? No need to change the gradients. Flex automatically colors the components based on the <em>baseColor </em>style. We can set the baseColor for each state using pseudo selectors.  Here&#8217;s an example of how to style the button that shows all of the selector types (id-, type- and class-selectors):</p>

<div class="wp_syntax"><div class="code"><pre class="css css" style="font-family:monospace;"><span style="color: #a1a100;">@namespace mx &quot;library://ns.adobe.com/flex/halo&quot;;</span>
<span style="color: #a1a100;">@namespace s &quot;library://ns.adobe.com/flex/spark&quot;;</span>
&nbsp;
<span style="color: #808080; font-style: italic;">/*   
 *	Using ID selectors with compund selectors (type and class selectors) 
 *	to define the appearance of the buttons 
 */</span>
&nbsp;
<span style="color: #808080; font-style: italic;">/* Define normal state styles on spark button type inside a desc container */</span>
<span style="color: #cc00cc;">#desc</span> s|Button <span style="color: #00AA00;">&#123;</span>
	skinClass<span style="color: #00AA00;">:</span> ClassReference<span style="color: #00AA00;">&#40;</span><span style="color: #ff0000;">'AHSimpleIconButtonSkin'</span><span style="color: #00AA00;">&#41;</span>;
	baseColor<span style="color: #00AA00;">:</span> <span style="color: #ff0000;">&quot;0x505050&quot;</span> ; <span style="color: #808080; font-style: italic;">/* Do not use black black; /*&quot;0x56d9e5&quot;;*/</span>
	<span style="color: #000000; font-weight: bold;">color</span><span style="color: #00AA00;">:</span> <span style="color: #cc00cc;">#FFFFFF</span>;
<span style="color: #00AA00;">&#125;</span>
&nbsp;
<span style="color: #808080; font-style: italic;">/* Define over states styles on spark button type inside a desc container */</span>
<span style="color: #cc00cc;">#desc</span> s|Button<span style="color: #3333ff;">:over </span><span style="color: #00AA00;">&#123;</span>
	baseColor<span style="color: #00AA00;">:</span> <span style="color: #ff0000;">&quot;0x97CD20&quot;</span>;
<span style="color: #00AA00;">&#125;</span>
&nbsp;
<span style="color: #808080; font-style: italic;">/* Define down states styles on spark button type inside a desc container */</span>
<span style="color: #cc00cc;">#desc</span> s|Button<span style="color: #3333ff;">:down </span><span style="color: #00AA00;">&#123;</span>
	baseColor<span style="color: #00AA00;">:</span> <span style="color: #ff0000;">&quot;0xa0d828&quot;</span>;
<span style="color: #00AA00;">&#125;</span>
&nbsp;
<span style="color: #808080; font-style: italic;">/* compound. override the over state of the button in element desc for class styleClass blueButton */</span>
<span style="color: #cc00cc;">#desc</span> <span style="color: #6666ff;">.blueButton</span><span style="color: #3333ff;">:over </span><span style="color: #00AA00;">&#123;</span>
	baseColor<span style="color: #00AA00;">:</span> <span style="color: #ff0000;">&quot;0x56d9e5&quot;</span>;
<span style="color: #00AA00;">&#125;</span>
&nbsp;
<span style="color: #808080; font-style: italic;">/* compound. override the down state of the button in element desc for class styleClass blueButton */</span>
<span style="color: #cc00cc;">#desc</span> <span style="color: #6666ff;">.blueButton</span><span style="color: #3333ff;">:down </span><span style="color: #00AA00;">&#123;</span>
	baseColor<span style="color: #00AA00;">:</span> <span style="color: #ff0000;">&quot;0x56d9e5&quot;</span>;
<span style="color: #00AA00;">&#125;</span>
&nbsp;
<span style="color: #808080; font-style: italic;">/* compound. override the over state of the button in element desc for class styleClass redButton */</span>
<span style="color: #cc00cc;">#desc</span> <span style="color: #6666ff;">.redButton</span><span style="color: #3333ff;">:over </span><span style="color: #00AA00;">&#123;</span>
	baseColor<span style="color: #00AA00;">:</span> <span style="color: #ff0000;">&quot;0xd52A03&quot;</span>;
<span style="color: #00AA00;">&#125;</span>
&nbsp;
<span style="color: #808080; font-style: italic;">/* compound. override the down state of the button in element desc for class styleClass redButton */</span>
<span style="color: #cc00cc;">#desc</span> <span style="color: #6666ff;">.redButton</span><span style="color: #3333ff;">:down </span><span style="color: #00AA00;">&#123;</span>
	baseColor<span style="color: #00AA00;">:</span> <span style="color: #ff0000;">&quot;0xE53A13&quot;</span>;
<span style="color: #00AA00;">&#125;</span>
.
.
.
&lt;s<span style="color: #3333ff;">:HGroup </span>id<span style="color: #00AA00;">=</span><span style="color: #ff0000;">&quot;desc&quot;</span> horizontalCenter<span style="color: #00AA00;">=</span><span style="color: #ff0000;">&quot;0&quot;</span> verticalCenter<span style="color: #00AA00;">=</span><span style="color: #ff0000;">&quot;0&quot;</span> verticalAlign<span style="color: #00AA00;">=</span><span style="color: #ff0000;">&quot;middle&quot;</span> gap<span style="color: #00AA00;">=</span><span style="color: #ff0000;">&quot;5&quot;</span><span style="color: #00AA00;">&gt;</span>
	&lt;s<span style="color: #3333ff;">:Button  </span>label<span style="color: #00AA00;">=</span><span style="color: #ff0000;">&quot;Green&quot;</span> 	useHandCursor<span style="color: #00AA00;">=</span><span style="color: #ff0000;">&quot;true&quot;</span> buttonMode<span style="color: #00AA00;">=</span><span style="color: #ff0000;">&quot;true&quot;</span> /<span style="color: #00AA00;">&gt;</span>
	&lt;s<span style="color: #3333ff;">:Button  </span>label<span style="color: #00AA00;">=</span><span style="color: #ff0000;">&quot;Blue&quot;</span> 	useHandCursor<span style="color: #00AA00;">=</span><span style="color: #ff0000;">&quot;true&quot;</span> buttonMode<span style="color: #00AA00;">=</span><span style="color: #ff0000;">&quot;true&quot;</span> styleName<span style="color: #00AA00;">=</span><span style="color: #ff0000;">&quot;blueButton&quot;</span>/<span style="color: #00AA00;">&gt;</span>
	&lt;s<span style="color: #3333ff;">:Button  </span>label<span style="color: #00AA00;">=</span><span style="color: #ff0000;">&quot;Red&quot;</span> 		useHandCursor<span style="color: #00AA00;">=</span><span style="color: #ff0000;">&quot;true&quot;</span> buttonMode<span style="color: #00AA00;">=</span><span style="color: #ff0000;">&quot;true&quot;</span> styleName<span style="color: #00AA00;">=</span><span style="color: #ff0000;">&quot;redButton&quot;</span>/<span style="color: #00AA00;">&gt;</span>
&lt;/s<span style="color: #3333ff;">:HGroup</span><span style="color: #00AA00;">&gt;</span></pre></div></div>

<p></p>
<h4>Colorization &#038; Exclusion</h4>
<p>By setting the baseColors for different states, Flex will colorize the component accordingly.  A dark grey in the up-state, a color in the over state and a lighter color in the down state.</p>
<p>The bad thing is that everything gets colorized. The good thing is that you can overwrite a function on SparkSkin to exclude elements from being colorized. We only want the background gradient to get colorized, so lets exclude the other elements from colorization:</p>

<div class="wp_syntax"><div class="code"><pre class="actionscript3 actionscript3" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">&lt;</span>fx<span style="color: #000000; font-weight: bold;">:</span>Script<span style="color: #000000; font-weight: bold;">&gt;</span>
<span style="color: #000000; font-weight: bold;">&lt;!</span><span style="color: #000000;">&#91;</span>CDATA<span style="color: #000000;">&#91;</span>         
	<span style="color: #3f5fbf;">/* Define the skin elements that should not be colorized. 
	exclude symbol and text group */</span>
	static <span style="color: #0033ff; font-weight: bold;">private</span> const exclusions<span style="color: #000000; font-weight: bold;">:</span><span style="color: #004993;">Array</span> = <span style="color: #000000;">&#91;</span><span style="color: #990000;">&quot;symbol&quot;</span>, <span style="color: #990000;">&quot;textGroup&quot;</span><span style="color: #000000;">&#93;</span>;
&nbsp;
	<span style="color: #3f5fbf;">/** 
	 * @copy spark.skins.SparkSkin#colorizeExclusions
	 */</span>		
	override <span style="color: #0033ff; font-weight: bold;">public</span> <span style="color: #339966; font-weight: bold;">function</span> <span style="color: #0033ff; font-weight: bold;">get</span> colorizeExclusions<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #000000; font-weight: bold;">:</span><span style="color: #004993;">Array</span> <span style="color: #000000;">&#123;</span><span style="color: #0033ff; font-weight: bold;">return</span> exclusions;<span style="color: #000000;">&#125;</span>
<span style="color: #000000;">&#93;</span><span style="color: #000000;">&#93;</span><span style="color: #000000; font-weight: bold;">&gt;</span>        
<span style="color: #000000; font-weight: bold;">&lt;/</span>fx<span style="color: #000000; font-weight: bold;">:</span>Script<span style="color: #000000; font-weight: bold;">&gt;</span>
.
.
.
<span style="color: #000000; font-weight: bold;">&lt;!--</span> The group <span style="color: #0033ff; font-weight: bold;">with</span> the symbol <span style="color: #0033ff; font-weight: bold;">with</span> a shadow applied to. In a group <span style="color: #0033ff; font-weight: bold;">for</span> colorization exclusion <span style="color: #000000; font-weight: bold;">--&gt;</span>
<span style="color: #000000; font-weight: bold;">&lt;</span>s<span style="color: #000000; font-weight: bold;">:</span>Group id=<span style="color: #990000;">&quot;symbol&quot;</span> verticalCenter=<span style="color: #990000;">&quot;0&quot;</span> <span style="color: #004993;">left</span>=<span style="color: #990000;">&quot;7&quot;</span> <span style="color: #004993;">top</span>=<span style="color: #990000;">&quot;9&quot;</span> <span style="color: #004993;">right</span>=<span style="color: #990000;">&quot;7&quot;</span> <span style="color: #004993;">bottom</span>=<span style="color: #990000;">&quot;7&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span>
	<span style="color: #000000; font-weight: bold;">&lt;</span>s<span style="color: #000000; font-weight: bold;">:</span>filters<span style="color: #000000; font-weight: bold;">&gt;</span>
		<span style="color: #000000; font-weight: bold;">&lt;</span>s<span style="color: #000000; font-weight: bold;">:</span><span style="color: #004993;">DropShadowFilter</span> id=<span style="color: #990000;">&quot;dsfSymbol&quot;</span> <span style="color: #004993;">blurX</span>=<span style="color: #990000;">&quot;0&quot;</span> <span style="color: #004993;">blurY</span>=<span style="color: #990000;">&quot;0&quot;</span> <span style="color: #004993;">distance</span>=<span style="color: #990000;">&quot;1&quot;</span>  <span style="color: #004993;">strength</span>=<span style="color: #990000;">&quot;1&quot;</span> <span style="color: #004993;">strength</span>.down=<span style="color: #990000;">&quot;0&quot;</span><span style="color: #000000; font-weight: bold;">/&gt;</span>
	<span style="color: #000000; font-weight: bold;">&lt;/</span>s<span style="color: #000000; font-weight: bold;">:</span>filters<span style="color: #000000; font-weight: bold;">&gt;</span>
	<span style="color: #000000; font-weight: bold;">&lt;</span>s<span style="color: #000000; font-weight: bold;">:</span>Path winding=<span style="color: #990000;">&quot;nonZero&quot;</span> <span style="color: #004993;">data</span>=<span style="color: #990000;">&quot;M12.6924 0L5.76855 6.92383 2.30762 3.46191 0 5.76855 3.46191 9.23145 5.76855 11.5391 8.07617 9.23145 15 2.30762 12.6924 0Z&quot;</span> <span style="color: #000000; font-weight: bold;">&gt;</span>
		<span style="color: #000000; font-weight: bold;">&lt;</span>s<span style="color: #000000; font-weight: bold;">:</span>fill<span style="color: #000000; font-weight: bold;">&gt;</span>
			<span style="color: #000000; font-weight: bold;">&lt;</span>s<span style="color: #000000; font-weight: bold;">:</span>SolidColor <span style="color: #004993;">color</span>=<span style="color: #990000;">&quot;#ffffff&quot;</span><span style="color: #000000; font-weight: bold;">/&gt;</span>
		<span style="color: #000000; font-weight: bold;">&lt;/</span>s<span style="color: #000000; font-weight: bold;">:</span>fill<span style="color: #000000; font-weight: bold;">&gt;</span>
	<span style="color: #000000; font-weight: bold;">&lt;/</span>s<span style="color: #000000; font-weight: bold;">:</span>Path<span style="color: #000000; font-weight: bold;">&gt;</span>
<span style="color: #000000; font-weight: bold;">&lt;/</span>s<span style="color: #000000; font-weight: bold;">:</span>Group<span style="color: #000000; font-weight: bold;">&gt;</span></pre></div></div>

<p>There is a group with an id &#8217;symbol&#8217; that is referenced in the exclusion array. Do the same for the label element.</p>
<p>Here&#8217;s a <a title="Spark Icon Button Demo" href="http://www.hulstkamp.com/byard/gumbo/iconButton/AHSimpleIconButtonTest.html">test</a> and here&#8217;s the <a href="http://www.hulstkamp.com/byard/gumbo/iconButton/srcview/index.html">source</a> (sdk 4.0.0.7282)</p>
]]></content:encoded>
			<wfw:commentRss>http://www.hulstkamp.com/2009/06/18/spark-icon-button-with-gradient-effects-and-filter-animation-colorized-by-styles-flex-4-gumbo/403/feed</wfw:commentRss>
		</item>
		<item>
		<title>Working with huge amount of data in Flex 4 (Gumbo)</title>
		<link>http://www.hulstkamp.com/2009/06/15/working-with-huge-amount-of-data-in-flex-4-gumbo/382</link>
		<comments>http://www.hulstkamp.com/2009/06/15/working-with-huge-amount-of-data-in-flex-4-gumbo/382#comments</comments>
		<pubDate>Mon, 15 Jun 2009 08:02:30 +0000</pubDate>
		<dc:creator>Andy Hulstkamp</dc:creator>
		
		<category><![CDATA[Gumbo (Flex 4 beta)]]></category>

		<category><![CDATA[Misc]]></category>

		<category><![CDATA[data]]></category>

		<category><![CDATA[DataGroup]]></category>

		<category><![CDATA[performance]]></category>

		<category><![CDATA[records]]></category>

		<category><![CDATA[Virtualization]]></category>

		<guid isPermaLink="false">http://www.hulstkamp.com/?p=382</guid>
		<description><![CDATA[When working with huge amounts of data on DataGroup, SkinnableDataContainer and all its Subclasses you will notice degradation in performance. Manipulating Data becomes slower, the UI on the Groups become less responsive, startup suffers, footprint is huge.  By default, Felx 4 creates an ItemRenderer for each data-item resulting in this overhead.
The solution is to use [...]]]></description>
			<content:encoded><![CDATA[<p>When working with huge amounts of data on DataGroup, SkinnableDataContainer and all its Subclasses you will notice degradation in performance. Manipulating Data becomes slower, the UI on the Groups become less responsive, startup suffers, footprint is huge.  By default, Felx 4 creates an ItemRenderer for each data-item resulting in this overhead.<span id="more-382"></span></p>
<p>The solution is to use virtualization on the layout of the dataGroup. By setting useVirtualLayout=true, ItemRenderers are recycled, the performance will be fine even for 100&#8242;000 and more records (depending on complexity).</p>
<p>There are a couple of things to considerate:</p>
<ul>
<li>Since ItemRenderers are recycled you must take care of updating the components in your renderer to the correct state, so that they reflect the underlying data (i.e If the data states, that a player is a midfielder and you have a checkbox for this in your renderer, then make sure to set the state of this checkbox based on the underlying data, that is passed down). Also, the data object being pushed down from the Host-Component to the ItemRenderer could be null, so we have to check for this as well, preventing NPEs.</li>
<li>Measurement will be approximate, either based on the first element, or a typical element you can reference or by setting rowHeight when using variableRowHeight=false.</li>
<li>One drawback of virtualization is that when using the itemRendererFunction property, the renderers arent recycled. The function is expected to create an Instance (wrapped in a ClassFactory) of an appropriate renderer for the data-item being passed. I haven&#8217;t looked into this, but there could be a way of creating your own ItemRenderer pool and returning an suitable renderer from that pool.</li>
<li>Checking the Profile, you&#8217;ll see that with virtualization the Renderers get reused, when virtualization is off, you&#8217;ll get as many Renderers as you have records.</li>
<li>Another disadvantage is that virtualized layouts do not respect layout element&#8217;s includeInLayout property.</li>
<li>In the Design Specification it is stated that “<em>Virtual layouts with small numbers of items whose sizes vary dramatically will respond poorly to interactive thumb scrolling. Responsiveness will improve as the variation in size decreases and/or the length of the list increases”</em>. In the test I did, I could not find any problems with poor responsiveness in scrolling, yet.</li>
</ul>
<p>My findings are, that in practice the performance is very good on huge data sets when virtualization is used.  The drawbacks can be handled or are neglectable in many situation where thousands of rows must be used.</p>
<p>Here&#8217;s a <a href="http://www.hulstkamp.com/byard/gumbo/DataListTest/DataGroupTest.html">simple test</a> to check out virtualization and measurement when using increasing amounts of data.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.hulstkamp.com/2009/06/15/working-with-huge-amount-of-data-in-flex-4-gumbo/382/feed</wfw:commentRss>
		</item>
		<item>
		<title>Random notes on DataGroup and Spark Containers in Flex 4 (Gumbo)</title>
		<link>http://www.hulstkamp.com/2009/06/14/random-notes-on-datagroup-in-flex-4-gumbo/371</link>
		<comments>http://www.hulstkamp.com/2009/06/14/random-notes-on-datagroup-in-flex-4-gumbo/371#comments</comments>
		<pubDate>Sun, 14 Jun 2009 17:17:59 +0000</pubDate>
		<dc:creator>Andy Hulstkamp</dc:creator>
		
		<category><![CDATA[Gumbo (Flex 4 beta)]]></category>

		<category><![CDATA[Misc]]></category>

		<category><![CDATA[DataGroup]]></category>

		<category><![CDATA[ItemRenderer]]></category>

		<category><![CDATA[Lyout]]></category>

		<category><![CDATA[SKinnableDataContainer]]></category>

		<category><![CDATA[Spark containers]]></category>

		<category><![CDATA[Virtualization]]></category>

		<guid isPermaLink="false">http://www.hulstkamp.com/?p=371</guid>
		<description><![CDATA[Here are some notes I took while investigating and reading about Spark Containers.
VerticalLayout.variableRowHeight and HorizontalLayout.variableColumnWidth properties are set to true by default. This might affect performance in a bad way, since Flex has to determine the size of each child. Setting theses properties to false in conjunction with rowHeight / columnWidth or a typical element [...]]]></description>
			<content:encoded><![CDATA[<p>Here are some notes I took while investigating and reading about Spark Containers.<span id="more-371"></span></p>
<p><samp>VerticalLayout.variableRowHeight</samp> and <samp>HorizontalLayout</samp><samp>.</samp><samp>variableColumnWidth</samp> properties are set to true by default. This might affect performance in a bad way, since Flex has to determine the size of each child. Setting theses properties to false in conjunction with <samp>rowHeight</samp> / <samp>columnWidth</samp> or a typical element or the dimension of the first element can affect performance in a positive way.</p>
<hr />Setting the <samp>typicalLayoutElement</samp> can affect performance in a positive way, since the dimension of this Element is used for all children, so measuring each child is not necessary.</p>
<hr /><samp>SkinnableContainer</samp> and <samp>SkinnableDataContainer</samp> can be used when skinning of a group is desired. The required skin-part is <samp>contentGroup</samp>.</p>
<hr />Out of the box, Flex 4 comes with two ItemRenderers:</p>
<p><samp> DefaultItemRenderer</samp> that converts its data item to a single String for display in a Spark <samp>SimpleText</samp>control and the <samp>DefaultComplexItemRenderer</samp> that displays a component in a Group container. Each component is wrapped in its own Group container.</p>
<hr />To create a custom ItemRenderer extend from</p>
<p><samp>spark.components.supportClasses.</samp><samp>ItemRenderer</samp></p>
<hr />Passing data to an ItemRenderer goes via properties of the ItemRenderer:</p>
<ul>
<li><samp>labelText</samp> String 	representation of the data-item.</li>
<li><samp>data</samp> The 	original data</li>
<li><samp>owner</samp> The 	Host-Component of the ItemRenderer. Can be used to fetch data.</li>
</ul>
<p>A host-component that implements the IItemRendererOwner interface has methods where data is pushed down to the ItemRenderer</p>
<ul>
<li><samp>itemToLabel</samp><samp>()</samp> converts 	the data item to a String representation.</li>
<li><samp>updateRenderer</samp><samp>()</samp></li>
</ul>
<p>One can overwrite these methods to manipulate data and the representation of the data.</p>
<hr />To 	determine which ItemRenderer to use either set it on the 	itemRenderer property of the DataGroup or set the 	<samp>itemRendererFunction</samp> property to a function that returns an instance 	of a <samp>ClassFactory</samp> with the desired custom ItemRenderer.</p>
<hr />A DataGroup visualizes a collection of data-items via ItemRenderers. 	Therefore, to add or remove children in a DataGroup manipulate the 	data using methods like <samp>addItem</samp>() 	and <samp><samp>removeItemAt()</samp> on the dataProvider.</samp></p>
<hr />Virtualization 	can be used to improve performance when working with huge amounts of 	records.<samp> UseVirtualLayout</samp> set to true to enable virtualization.</p>
<hr />When Virtualization is enabled, Flex will recycle ItemRenderes resulting in less overhead. Be sure to reset your ItemRenderes (explicitly setting the state of the components based on the passed data) and checking for null of the data property so that you don&#8217;t get an NPE at run time.</p>
<hr />A typical item can be set on the DataGroup, so that Flex uses this to determine the size  of the childs, resulting in better performance.</p>
<hr />Virtualization cannot be used when using the ItemRendererFunction. Well, the function can be set, but no virtualization will be used.</p>
<p><strong>Update</strong>: To be more precise (thanks to Steven Shongrunden@Adobe)</p>
<p><em>virtualization will be used even when an item renderer function is defined, but in that case item renderer recycling will not happen. Instead renderers will be created and destroyed roughly as they come in and out of view. (Compare this to the non-virtual case where every renderer is instantiated at startup). ItemRenderer recycling can be more performant than creation and destruction (depending on the renderers) so if you want to get the best performance it’s typically better to define an itemRenderer rather than an itemRendererFunction</em></p>
<hr />The Viewport on a spark container is set by its <samp>width</samp> and <samp>heigt</samp> properties. <samp>verticalScrollPosition</samp> and <samp>horizontalScrollPosition</samp> specify the origin of the viewport relative to the containers content. <samp>clipAndEnableScrolling </samp>is used for clipping and scrolling. For scrolling the container can be surrounded by a scroller component (or you could use a slider and set the <samp>verticalScrollPosition</samp> and <samp>horizontalScrollPosition</samp>at runtime).</p>
]]></content:encoded>
			<wfw:commentRss>http://www.hulstkamp.com/2009/06/14/random-notes-on-datagroup-in-flex-4-gumbo/371/feed</wfw:commentRss>
		</item>
		<item>
		<title>Custom Spark CheckBox Component in Flex 4 (Gumbo)</title>
		<link>http://www.hulstkamp.com/2009/06/13/custom-spark-checkbox-component-in-flex-4-gumbo/361</link>
		<comments>http://www.hulstkamp.com/2009/06/13/custom-spark-checkbox-component-in-flex-4-gumbo/361#comments</comments>
		<pubDate>Sat, 13 Jun 2009 19:35:05 +0000</pubDate>
		<dc:creator>Andy Hulstkamp</dc:creator>
		
		<category><![CDATA[Actionscript 3]]></category>

		<category><![CDATA[Astro (Flash 10 beta)]]></category>

		<category><![CDATA[FXG]]></category>

		<category><![CDATA[Gumbo (Flex 4 beta)]]></category>

		<category><![CDATA[CheckBox]]></category>

		<category><![CDATA[custom component]]></category>

		<category><![CDATA[effects]]></category>

		<category><![CDATA[graphic]]></category>

		<category><![CDATA[skinning]]></category>

		<category><![CDATA[Spark]]></category>

		<category><![CDATA[states]]></category>

		<category><![CDATA[styles]]></category>

		<category><![CDATA[Transitions]]></category>

		<guid isPermaLink="false">http://www.hulstkamp.com/?p=361</guid>
		<description><![CDATA[Here&#8217;s an example of how to enhance the default Spark CheckBox. This example uses a mark for the unchecked states and one for the checked states. Some simple transitions are used to make things a little bit nicer.

The skin uses two additional properties (symbolColorChecked,  symbolColorUnchecked) for the color of the marks:

   s&#124;CheckBox &#123;
 [...]]]></description>
			<content:encoded><![CDATA[<p>Here&#8217;s an example of how to enhance the default Spark CheckBox. This example uses a mark for the unchecked states and one for the checked states. Some simple transitions are used to make things a little bit nicer.</p>
<p><a href="http://www.hulstkamp.com/byard/gumbo/AHCheckBox/AHCheckboxTest.html"><img src="http://www.hulstkamp.com/byard/gumbo/AHCheckBox/CustomCheckBox.png" alt="Custom CheckBox Preview" /></a></p>
<p>The skin uses two additional properties (symbolColorChecked,  symbolColorUnchecked) for the <span id="more-361"></span>color of the marks:</p>

<div class="wp_syntax"><div class="code"><pre class="css css" style="font-family:monospace;">   s|CheckBox <span style="color: #00AA00;">&#123;</span>
       skinClass<span style="color: #00AA00;">:</span> ClassReference<span style="color: #00AA00;">&#40;</span><span style="color: #ff0000;">&quot;AHCheckboxSkin&quot;</span><span style="color: #00AA00;">&#41;</span>;
       symbolColorChecked<span style="color: #00AA00;">:</span> <span style="color: #ff0000;">&quot;0x70d000&quot;</span>;
       symbolColorUnchecked<span style="color: #00AA00;">:</span> <span style="color: #ff0000;">&quot;0xe83800&quot;</span>;
       fontSize<span style="color: #00AA00;">:</span> <span style="color: #ff0000;">&quot;11&quot;</span>;
       <span style="color: #000000; font-weight: bold;">color</span><span style="color: #00AA00;">:</span> <span style="color: #ff0000;">&quot;0x606060&quot;</span>;
<span style="color: #00AA00;">&#125;</span></pre></div></div>

<p>The skin goes like this:</p>

<div class="wp_syntax"><div class="code"><pre class="mxml mxml" style="font-family:monospace;">.
.
.
&nbsp;
	<span style="color: #000000;"><span style="color: #7400FF;">&lt;fx:Script</span><span style="color: #7400FF;">&gt;</span></span>
	<span style="color: #000000;">&lt;!<span style="color: #66cc66;">&#91;</span>CDATA<span style="color: #66cc66;">&#91;</span></span>
<span style="color: #000000;">		import mx.utils.ColorUtil;</span>
<span style="color: #000000;">		import mx.events.FlexEvent;</span>
&nbsp;
<span style="color: #000000;">		<span style="color: #66cc66;">&#91;</span>Bindable<span style="color: #66cc66;">&#93;</span>	</span>
<span style="color: #000000;">		private var highlightColor:uint; </span>
&nbsp;
<span style="color: #000000;">		protected function sparkskin1_creationCompleteHandler<span style="color: #66cc66;">&#40;</span>event:FlexEvent<span style="color: #66cc66;">&#41;</span>:void</span>
<span style="color: #000000;">		<span style="color: #66cc66;">&#123;</span></span>
<span style="color: #000000;">			hostComponent.buttonMode = true;</span>
<span style="color: #000000;">			hostComponent.useHandCursor = true;</span>
<span style="color: #000000;">			var col:uint = uint <span style="color: #66cc66;">&#40;</span>hostComponent.getStyle<span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">'color'</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span>;</span>
<span style="color: #000000;">			highlightColor = ColorUtil.adjustBrightness<span style="color: #66cc66;">&#40;</span>col, <span style="color: #cc66cc;">80</span><span style="color: #66cc66;">&#41;</span>;</span>
<span style="color: #000000;">		<span style="color: #66cc66;">&#125;</span></span>
<span style="color: #000000;">	<span style="color: #66cc66;">&#93;</span><span style="color: #66cc66;">&#93;</span><span style="color: #7400FF;">&gt;</span></span>
	<span style="color: #000000;"><span style="color: #7400FF;">&lt;/fx:Script</span><span style="color: #7400FF;">&gt;</span></span>
&nbsp;
&nbsp;
	<span style="color: #000000;"><span style="color: #7400FF;">&lt;fx:Declarations</span><span style="color: #7400FF;">&gt;</span></span>
		<span style="color: #000000;"><span style="color: #7400FF;">&lt;s:Linear</span> id=<span style="color: #ff0000;">&quot;easer&quot;</span> easeInFraction=<span style="color: #ff0000;">&quot;0&quot;</span>  easeOutFraction=<span style="color: #ff0000;">&quot;1&quot;</span> <span style="color: #7400FF;">/&gt;</span></span>
	<span style="color: #000000;"><span style="color: #7400FF;">&lt;/fx:Declarations</span><span style="color: #7400FF;">&gt;</span></span>
&nbsp;
	<span style="color: #000000;"><span style="color: #7400FF;">&lt;s:states</span><span style="color: #7400FF;">&gt;</span></span>
		<span style="color: #000000;"><span style="color: #7400FF;">&lt;s:State</span> name=<span style="color: #ff0000;">&quot;up&quot;</span>  stateGroups=<span style="color: #ff0000;">&quot;unchecked&quot;</span> <span style="color: #7400FF;">/&gt;</span></span>
		<span style="color: #000000;"><span style="color: #7400FF;">&lt;s:State</span> name=<span style="color: #ff0000;">&quot;over&quot;</span> stateGroups=<span style="color: #ff0000;">&quot;overStates, unchecked&quot;</span> <span style="color: #7400FF;">/&gt;</span></span>
		<span style="color: #000000;"><span style="color: #7400FF;">&lt;s:State</span> name=<span style="color: #ff0000;">&quot;down&quot;</span> stateGroups=<span style="color: #ff0000;">&quot;downStates, unchecked&quot;</span> <span style="color: #7400FF;">/&gt;</span></span>
		<span style="color: #000000;"><span style="color: #7400FF;">&lt;s:State</span> name=<span style="color: #ff0000;">&quot;disabled&quot;</span> stateGroups=<span style="color: #ff0000;">&quot;disabledStates, unchecked&quot;</span> <span style="color: #7400FF;">/&gt;</span></span>
		<span style="color: #000000;"><span style="color: #7400FF;">&lt;s:State</span> name=<span style="color: #ff0000;">&quot;upAndSelected&quot;</span> stateGroups=<span style="color: #ff0000;">&quot;selectedStates, checked&quot;</span> <span style="color: #7400FF;">/&gt;</span></span>
		<span style="color: #000000;"><span style="color: #7400FF;">&lt;s:State</span> name=<span style="color: #ff0000;">&quot;overAndSelected&quot;</span> stateGroups=<span style="color: #ff0000;">&quot;overStates, selectedStates, checked&quot;</span> <span style="color: #7400FF;">/&gt;</span></span>
		<span style="color: #000000;"><span style="color: #7400FF;">&lt;s:State</span> name=<span style="color: #ff0000;">&quot;downAndSelected&quot;</span> stateGroups=<span style="color: #ff0000;">&quot;downStates, selectedStates, checked&quot;</span> <span style="color: #7400FF;">/&gt;</span></span>
		<span style="color: #000000;"><span style="color: #7400FF;">&lt;s:State</span> name=<span style="color: #ff0000;">&quot;disabledAndSelected&quot;</span> stateGroups=<span style="color: #ff0000;">&quot;disabledStates, selectedStates, checked&quot;</span> <span style="color: #7400FF;">/&gt;</span></span>
	<span style="color: #000000;"><span style="color: #7400FF;">&lt;/s:states</span><span style="color: #7400FF;">&gt;</span></span>
&nbsp;
	<span style="color: #000000;"><span style="color: #808080; font-style: italic;">&lt;!-- Transitions for the mark --&gt;</span></span>
	<span style="color: #000000;"><span style="color: #7400FF;">&lt;s:transitions</span><span style="color: #7400FF;">&gt;</span></span>
		<span style="color: #000000;"><span style="color: #7400FF;">&lt;s:Transition</span>  fromState=<span style="color: #ff0000;">&quot;over&quot;</span> toState=<span style="color: #ff0000;">&quot;overAndSelected&quot;</span> <span style="color: #7400FF;">&gt;</span></span>
			<span style="color: #000000;"><span style="color: #7400FF;">&lt;s:Parallel</span> target=<span style="color: #ff0000;">&quot;{checkedMark}&quot;</span> <span style="color: #7400FF;">&gt;</span></span>
				<span style="color: #000000;"><span style="color: #7400FF;">&lt;s:Scale</span> duration=<span style="color: #ff0000;">&quot;250&quot;</span>  easer=<span style="color: #ff0000;">&quot;{easer}&quot;</span> <span style="color: #7400FF;">/&gt;</span></span>
			<span style="color: #000000;"><span style="color: #7400FF;">&lt;/s:Parallel</span><span style="color: #7400FF;">&gt;</span></span>
		<span style="color: #000000;"><span style="color: #7400FF;">&lt;/s:Transition</span><span style="color: #7400FF;">&gt;</span></span>
		<span style="color: #000000;"><span style="color: #7400FF;">&lt;s:Transition</span> fromState=<span style="color: #ff0000;">&quot;overAndSelected&quot;</span> toState=<span style="color: #ff0000;">&quot;over&quot;</span> <span style="color: #7400FF;">&gt;</span></span>
			<span style="color: #000000;"><span style="color: #7400FF;">&lt;s:Parallel</span> target=<span style="color: #ff0000;">&quot;{uncheckedMark}&quot;</span><span style="color: #7400FF;">&gt;</span></span>
				<span style="color: #000000;"><span style="color: #7400FF;">&lt;s:Scale</span> duration=<span style="color: #ff0000;">&quot;250&quot;</span> easer=<span style="color: #ff0000;">&quot;{easer}&quot;</span> <span style="color: #7400FF;">/&gt;</span></span>
			<span style="color: #000000;"><span style="color: #7400FF;">&lt;/s:Parallel</span><span style="color: #7400FF;">&gt;</span></span>
		<span style="color: #000000;"><span style="color: #7400FF;">&lt;/s:Transition</span><span style="color: #7400FF;">&gt;</span></span>
	<span style="color: #000000;"><span style="color: #7400FF;">&lt;/s:transitions</span><span style="color: #7400FF;">&gt;</span></span>
&nbsp;
	<span style="color: #000000;"><span style="color: #808080; font-style: italic;">&lt;!-- Label --&gt;</span></span>
	<span style="color: #000000;"><span style="color: #7400FF;">&lt;s:SimpleText</span> id=<span style="color: #ff0000;">&quot;labelElement&quot;</span></span>
<span style="color: #000000;">				  textAlign=<span style="color: #ff0000;">&quot;start&quot;</span></span>
<span style="color: #000000;">				  color.over=<span style="color: #ff0000;">&quot;{highlightColor}&quot;</span></span>
<span style="color: #000000;">				  color.down=<span style="color: #ff0000;">&quot;{highlightColor}&quot;</span></span>
<span style="color: #000000;">				  color.overAndSelected=<span style="color: #ff0000;">&quot;{highlightColor}&quot;</span></span>
<span style="color: #000000;">				  color.downAndSelected=<span style="color: #ff0000;">&quot;{highlightColor}&quot;</span></span>
<span style="color: #000000;">				  verticalAlign=<span style="color: #ff0000;">&quot;middle&quot;</span></span>
<span style="color: #000000;">				  lineBreak=<span style="color: #ff0000;">&quot;explicit&quot;</span></span>
<span style="color: #000000;">				  left=<span style="color: #ff0000;">&quot;16&quot;</span> right=<span style="color: #ff0000;">&quot;0&quot;</span> top=<span style="color: #ff0000;">&quot;3&quot;</span> bottom=<span style="color: #ff0000;">&quot;3&quot;</span> verticalCenter=<span style="color: #ff0000;">&quot;2&quot;</span> <span style="color: #7400FF;">/&gt;</span></span>
	<span style="color: #000000;"><span style="color: #808080; font-style: italic;">&lt;!-- Group with the marks --&gt;</span></span> 
	<span style="color: #000000;"><span style="color: #7400FF;">&lt;s:Group</span> id=<span style="color: #ff0000;">&quot;marks&quot;</span> verticalCenter=<span style="color: #ff0000;">&quot;0&quot;</span> width=<span style="color: #ff0000;">&quot;11&quot;</span> height=<span style="color: #ff0000;">&quot;11&quot;</span> left=<span style="color: #ff0000;">&quot;0&quot;</span> <span style="color: #7400FF;">&gt;</span></span>
&nbsp;
		<span style="color: #000000;"><span style="color: #808080; font-style: italic;">&lt;!-- GraphicElement for the checked-mark --&gt;</span></span>
		<span style="color: #000000;"><span style="color: #7400FF;">&lt;s:Path</span> horizontalCenter=<span style="color: #ff0000;">&quot;0&quot;</span> verticalCenter=<span style="color: #ff0000;">&quot;0&quot;</span> width=<span style="color: #ff0000;">&quot;11&quot;</span> height=<span style="color: #ff0000;">&quot;11&quot;</span> winding=<span style="color: #ff0000;">&quot;nonZero&quot;</span> data=<span style="color: #ff0000;">&quot;M 100 0 C 75.148 24.853 46.191 87.574 46.191 87.574 C 46.191 87.574 14.204 40.716 0 40.716 L 25.11 41.012 L 43.787 62.213 L 79.29 0 L 100 0 Z&quot;</span> </span>
<span style="color: #000000;">				id=<span style="color: #ff0000;">&quot;checkedMark&quot;</span> scaleX.unchecked=<span style="color: #ff0000;">&quot;0&quot;</span> scaleX=<span style="color: #ff0000;">&quot;1&quot;</span> scaleY.unchecked=<span style="color: #ff0000;">&quot;0&quot;</span> scaleY=<span style="color: #ff0000;">&quot;1&quot;</span><span style="color: #7400FF;">&gt;</span></span>
			<span style="color: #000000;"><span style="color: #7400FF;">&lt;s:fill</span><span style="color: #7400FF;">&gt;</span></span>
				<span style="color: #000000;"><span style="color: #7400FF;">&lt;s:SolidColor</span> color=<span style="color: #ff0000;">&quot;{hostComponent.getStyle('symbolColorChecked')}&quot;</span><span style="color: #7400FF;">/&gt;</span></span>
			<span style="color: #000000;"><span style="color: #7400FF;">&lt;/s:fill</span><span style="color: #7400FF;">&gt;</span></span>
		<span style="color: #000000;"><span style="color: #7400FF;">&lt;/s:Path</span><span style="color: #7400FF;">&gt;</span></span>
&nbsp;
		<span style="color: #000000;"><span style="color: #808080; font-style: italic;">&lt;!-- GraphicElement for the unchecked-mark --&gt;</span></span>
		<span style="color: #000000;"><span style="color: #7400FF;">&lt;s:Path</span> horizontalCenter=<span style="color: #ff0000;">&quot;0&quot;</span> verticalCenter=<span style="color: #ff0000;">&quot;0&quot;</span> width=<span style="color: #ff0000;">&quot;9&quot;</span> height=<span style="color: #ff0000;">&quot;9&quot;</span> winding=<span style="color: #ff0000;">&quot;nonZero&quot;</span> data=<span style="color: #ff0000;">&quot;M 100 90.29 L 60.694 42.28 C 72.2 26.205 84.896 9.838 95.214 0 L 74.28 0.1 L 51.336 30.851 L 26.922 1.031 L 0 1.031 C 13.126 7.917 29.115 24.561 43.297 41.625 L 7.425 89.702 L 28.995 89.617 C 28.995 89.617 39.309 73.04 52.832 53.468 C 68.081 72.987 79.403 90.131 79.403 90.131 L 100 90.29 Z&quot;</span> </span>
<span style="color: #000000;">				id=<span style="color: #ff0000;">&quot;uncheckedMark&quot;</span> scaleX.checked=<span style="color: #ff0000;">&quot;0&quot;</span> scaleX=<span style="color: #ff0000;">&quot;1&quot;</span> scaleY.checked=<span style="color: #ff0000;">&quot;0&quot;</span> scaleY=<span style="color: #ff0000;">&quot;1&quot;</span><span style="color: #7400FF;">&gt;</span></span>
			<span style="color: #000000;"><span style="color: #7400FF;">&lt;s:fill</span><span style="color: #7400FF;">&gt;</span></span>
				<span style="color: #000000;"><span style="color: #7400FF;">&lt;s:SolidColor</span> id=<span style="color: #ff0000;">&quot;checkMarkFill&quot;</span> color=<span style="color: #ff0000;">&quot;{hostComponent.getStyle('symbolColorUnchecked')}&quot;</span><span style="color: #7400FF;">/&gt;</span></span>
			<span style="color: #000000;"><span style="color: #7400FF;">&lt;/s:fill</span><span style="color: #7400FF;">&gt;</span></span>
		<span style="color: #000000;"><span style="color: #7400FF;">&lt;/s:Path</span><span style="color: #7400FF;">&gt;</span></span>
&nbsp;
		<span style="color: #000000;"><span style="color: #808080; font-style: italic;">&lt;!-- Fake HitArea. TODO: Sort out how to use hitArea property, which does not seem to work correctly yet, but haven't investigated --&gt;</span></span>
		<span style="color: #000000;"><span style="color: #7400FF;">&lt;s:Group</span> width=<span style="color: #ff0000;">&quot;100%&quot;</span> height=<span style="color: #ff0000;">&quot;100%&quot;</span> alpha=<span style="color: #ff0000;">&quot;0&quot;</span> <span style="color: #7400FF;">&gt;</span></span>
			<span style="color: #000000;"><span style="color: #7400FF;">&lt;s:Rect</span> width=<span style="color: #ff0000;">&quot;100%&quot;</span> height=<span style="color: #ff0000;">&quot;100%&quot;</span>  <span style="color: #7400FF;">&gt;</span></span>
				<span style="color: #000000;"><span style="color: #7400FF;">&lt;s:fill</span><span style="color: #7400FF;">&gt;</span></span>
					<span style="color: #000000;"><span style="color: #7400FF;">&lt;s:SolidColor</span> color=<span style="color: #ff0000;">&quot;0xff0000&quot;</span> <span style="color: #7400FF;">/&gt;</span></span>
				<span style="color: #000000;"><span style="color: #7400FF;">&lt;/s:fill</span><span style="color: #7400FF;">&gt;</span></span>
			<span style="color: #000000;"><span style="color: #7400FF;">&lt;/s:Rect</span><span style="color: #7400FF;">&gt;</span></span>
		<span style="color: #000000;"><span style="color: #7400FF;">&lt;/s:Group</span><span style="color: #7400FF;">&gt;</span></span>
&nbsp;
		<span style="color: #000000;"><span style="color: #7400FF;">&lt;s:filters</span><span style="color: #7400FF;">&gt;</span></span>
			<span style="color: #000000;"><span style="color: #7400FF;">&lt;s:DropShadowFilter</span> distance=<span style="color: #ff0000;">&quot;1&quot;</span> strength=<span style="color: #ff0000;">&quot;0.75&quot;</span> blurX=<span style="color: #ff0000;">&quot;1&quot;</span> blurY=<span style="color: #ff0000;">&quot;1&quot;</span> <span style="color: #7400FF;">/&gt;</span></span>
		<span style="color: #000000;"><span style="color: #7400FF;">&lt;/s:filters</span><span style="color: #7400FF;">&gt;</span></span>
	<span style="color: #000000;"><span style="color: #7400FF;">&lt;/s:Group</span><span style="color: #7400FF;">&gt;</span></span>
.
.
.</pre></div></div>

<p>FXG GraphicElements are used to draw the marks. The color of the marks are fetched from the hostComponents styles. The customs styles are set in the style definition of the CheckBox. When creation is complete some flags are set, so that the hand-cursor is shown when rolling over the label-field. An highlight-color for the label is calculated from the color-style-property and used in the over- and down-states. Transitions are use to have a scale-effect when the CheckBox is un(selected).</p>
<p><a href="http://www.hulstkamp.com/byard/gumbo/AHCheckBox/AHCheckboxTest.html">Test</a> &#038; <a href="http://www.hulstkamp.com/byard/gumbo/AHCheckBox/srcview/index.html">source (sdk 4.0.0.7282) </a>.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.hulstkamp.com/2009/06/13/custom-spark-checkbox-component-in-flex-4-gumbo/361/feed</wfw:commentRss>
		</item>
		<item>
		<title>Customize the Spark TextInput Component in Flex 4 (Gumbo). Adding focus and Transitions.</title>
		<link>http://www.hulstkamp.com/2009/06/01/customize-the-spark-textinput-component-in-flex-4-gumbo-adding-focus-and-transitions/344</link>
		<comments>http://www.hulstkamp.com/2009/06/01/customize-the-spark-textinput-component-in-flex-4-gumbo-adding-focus-and-transitions/344#comments</comments>
		<pubDate>Mon, 01 Jun 2009 15:45:43 +0000</pubDate>
		<dc:creator>Andy Hulstkamp</dc:creator>
		
		<category><![CDATA[Actionscript 3]]></category>

		<category><![CDATA[FXG]]></category>

		<category><![CDATA[Flash]]></category>

		<category><![CDATA[Gumbo (Flex 4 beta)]]></category>

		<category><![CDATA[Misc]]></category>

		<category><![CDATA[Sound]]></category>

		<category><![CDATA[component]]></category>

		<category><![CDATA[customizing]]></category>

		<category><![CDATA[effects]]></category>

		<category><![CDATA[skinning]]></category>

		<category><![CDATA[SkinState]]></category>

		<category><![CDATA[Spark]]></category>

		<category><![CDATA[Transition]]></category>

		<guid isPermaLink="false">http://www.hulstkamp.com/?p=344</guid>
		<description><![CDATA[Changing the look of a spark component mainly comes down to customizing the skin-class, but there are situations where this might not be enough.
In a project I&#8217;m working on, we wanted to have a smooth transition when a text-input gets or loses focus. The default Spark TextInput and the associated skin-class do not have a [...]]]></description>
			<content:encoded><![CDATA[<p>Changing the look of a spark component mainly comes down to customizing the skin-class, but there are situations where this might not be enough.</p>
<p>In a project I&#8217;m working on, we wanted to have a smooth transition when a text-input gets or loses focus. The default Spark TextInput and the associated skin-class do not have a focused state. (In Flex the FocusManager manages the focus by drawing a border around a component, but we wanted the focus on the skin itself and a transition)</p>
<p><a href="http://www.hulstkamp.com/byard/gumbo/TextInputFocus/AHTextFieldTest.html"><img src="http://www.hulstkamp.com/byard/gumbo/TextInputFocus/customTextinput.png" alt="custom TextInput" /></a></p>
<p>One way to achieve this is to enhance the TextInput Component:<span id="more-344"></span></p>
<p>1.) Extend spark.components.TextInput<br />
2.) Declare the additional SkinStates</p>

<div class="wp_syntax"><div class="code"><pre class="actionscript3 actionscript3" style="font-family:monospace;"><span style="color: #0033ff; font-weight: bold;">public</span> <span style="color: #9900cc; font-weight: bold;">class</span> AHTextInput extends TextInput <span style="color: #000000;">&#123;</span>
&nbsp;
	<span style="color: #009900;">//Declare the additional SkinStates</span>
	<span style="color: #000000;">&#91;</span>SkinState<span style="color: #000000;">&#40;</span><span style="color: #990000;">&quot;focused&quot;</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">&#93;</span>;
&nbsp;
	<span style="color: #0033ff; font-weight: bold;">private</span> <span style="color: #6699cc; font-weight: bold;">var</span> bfocused<span style="color: #000000; font-weight: bold;">:</span><span style="color: #004993;">Boolean</span>;
&nbsp;
	<span style="color: #0033ff; font-weight: bold;">public</span> <span style="color: #339966; font-weight: bold;">function</span> AHTextInput<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>
	<span style="color: #000000;">&#123;</span>
		<span style="color: #0033ff; font-weight: bold;">super</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>;
	<span style="color: #000000;">&#125;</span>
...</pre></div></div>

<p>3.) Add Event-Listeners for the Focus-Event</p>

<div class="wp_syntax"><div class="code"><pre class="actionscript3 actionscript3" style="font-family:monospace;"><span style="color: #009900;">//Add Event-Listeners to the textview for FocusEvent</span>
override <span style="color: #0033ff; font-weight: bold;">protected</span> <span style="color: #339966; font-weight: bold;">function</span> partAdded<span style="color: #000000;">&#40;</span>partName<span style="color: #000000; font-weight: bold;">:</span><span style="color: #004993;">String</span>, instance<span style="color: #000000; font-weight: bold;">:</span><span style="color: #004993;">Object</span><span style="color: #000000;">&#41;</span><span style="color: #000000; font-weight: bold;">:</span><span style="color: #0033ff; font-weight: bold;">void</span> <span style="color: #000000;">&#123;</span>
	<span style="color: #0033ff; font-weight: bold;">super</span>.partAdded<span style="color: #000000;">&#40;</span>partName, instance<span style="color: #000000;">&#41;</span>;
	<span style="color: #0033ff; font-weight: bold;">if</span> <span style="color: #000000;">&#40;</span>instance == <span style="color: #0033ff; font-weight: bold;">this</span>.textView<span style="color: #000000;">&#41;</span> <span style="color: #000000;">&#123;</span>
		<span style="color: #004993;">trace</span> <span style="color: #000000;">&#40;</span><span style="color: #990000;">&quot;Adding TextView&quot;</span><span style="color: #000000;">&#41;</span>;
		<span style="color: #0033ff; font-weight: bold;">this</span>.textView.<span style="color: #004993;">addEventListener</span><span style="color: #000000;">&#40;</span><span style="color: #004993;">FocusEvent</span>.<span style="color: #004993;">FOCUS_IN</span>, onFocusInHandler<span style="color: #000000;">&#41;</span>;
		<span style="color: #0033ff; font-weight: bold;">this</span>.textView.<span style="color: #004993;">addEventListener</span><span style="color: #000000;">&#40;</span><span style="color: #004993;">FocusEvent</span>.<span style="color: #004993;">FOCUS_OUT</span>, onFocusOutHandler<span style="color: #000000;">&#41;</span>;
	<span style="color: #000000;">&#125;</span>
<span style="color: #000000;">&#125;</span>
&nbsp;
<span style="color: #009900;">//Clean up Event-Listeners and stuff...</span>
override <span style="color: #0033ff; font-weight: bold;">protected</span> <span style="color: #339966; font-weight: bold;">function</span> partRemoved<span style="color: #000000;">&#40;</span>partName<span style="color: #000000; font-weight: bold;">:</span><span style="color: #004993;">String</span>, instance<span style="color: #000000; font-weight: bold;">:</span><span style="color: #004993;">Object</span><span style="color: #000000;">&#41;</span><span style="color: #000000; font-weight: bold;">:</span><span style="color: #0033ff; font-weight: bold;">void</span> <span style="color: #000000;">&#123;</span>
	<span style="color: #0033ff; font-weight: bold;">super</span>.partRemoved<span style="color: #000000;">&#40;</span>partName, instance<span style="color: #000000;">&#41;</span>;
	<span style="color: #0033ff; font-weight: bold;">if</span> <span style="color: #000000;">&#40;</span>instance == <span style="color: #0033ff; font-weight: bold;">this</span>.textView<span style="color: #000000;">&#41;</span> <span style="color: #000000;">&#123;</span>
		<span style="color: #0033ff; font-weight: bold;">this</span>.textView.<span style="color: #004993;">removeEventListener</span><span style="color: #000000;">&#40;</span><span style="color: #004993;">FocusEvent</span>.<span style="color: #004993;">FOCUS_IN</span>, onFocusInHandler<span style="color: #000000;">&#41;</span>;
		<span style="color: #0033ff; font-weight: bold;">this</span>.textView.<span style="color: #004993;">removeEventListener</span><span style="color: #000000;">&#40;</span><span style="color: #004993;">FocusEvent</span>.<span style="color: #004993;">FOCUS_OUT</span>, onFocusOutHandler<span style="color: #000000;">&#41;</span>;
	<span style="color: #000000;">&#125;</span>
<span style="color: #000000;">&#125;</span>
...</pre></div></div>

<p>4.) Keep track of the state and leverage focused=false|true</p>

<div class="wp_syntax"><div class="code"><pre class="actionscript3 actionscript3" style="font-family:monospace;"><span style="color: #009900;">//Handler for FocusIn Event</span>
<span style="color: #0033ff; font-weight: bold;">private</span> <span style="color: #339966; font-weight: bold;">function</span> onFocusInHandler<span style="color: #000000;">&#40;</span>event<span style="color: #000000; font-weight: bold;">:</span><span style="color: #004993;">FocusEvent</span><span style="color: #000000;">&#41;</span><span style="color: #000000; font-weight: bold;">:</span><span style="color: #0033ff; font-weight: bold;">void</span> <span style="color: #000000;">&#123;</span>
	bfocused = <span style="color: #0033ff; font-weight: bold;">true</span>;
	invalidateSkinState<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>;
	<span style="color: #004993;">trace</span><span style="color: #000000;">&#40;</span><span style="color: #990000;">&quot;Getting focus&quot;</span><span style="color: #000000;">&#41;</span>;
<span style="color: #000000;">&#125;</span>
&nbsp;
<span style="color: #009900;">//Handler for FocusOut</span>
<span style="color: #0033ff; font-weight: bold;">private</span> <span style="color: #339966; font-weight: bold;">function</span> onFocusOutHandler<span style="color: #000000;">&#40;</span>event<span style="color: #000000; font-weight: bold;">:</span><span style="color: #004993;">FocusEvent</span><span style="color: #000000;">&#41;</span><span style="color: #000000; font-weight: bold;">:</span><span style="color: #0033ff; font-weight: bold;">void</span> <span style="color: #000000;">&#123;</span>
	bfocused = <span style="color: #0033ff; font-weight: bold;">false</span>;
	invalidateSkinState<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>;
	<span style="color: #004993;">trace</span><span style="color: #000000;">&#40;</span><span style="color: #990000;">&quot;Loosing focus&quot;</span><span style="color: #000000;">&#41;</span>;
<span style="color: #000000;">&#125;</span>
<span style="color: #009900;">//Gets called after invalidateSkinState() by Flex</span>
override <span style="color: #0033ff; font-weight: bold;">protected</span> <span style="color: #339966; font-weight: bold;">function</span> getCurrentSkinState<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #000000; font-weight: bold;">:</span><span style="color: #004993;">String</span> <span style="color: #000000;">&#123;</span>
	<span style="color: #0033ff; font-weight: bold;">if</span> <span style="color: #000000;">&#40;</span>bfocused<span style="color: #000000;">&#41;</span> <span style="color: #000000;">&#123;</span>
		<span style="color: #0033ff; font-weight: bold;">return</span> <span style="color: #990000;">&quot;focused&quot;</span>;
	<span style="color: #000000;">&#125;</span> <span style="color: #0033ff; font-weight: bold;">else</span> <span style="color: #000000;">&#123;</span>
		<span style="color: #0033ff; font-weight: bold;">return</span> <span style="color: #0033ff; font-weight: bold;">super</span>.getCurrentSkinState<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>;
	<span style="color: #000000;">&#125;</span>
<span style="color: #000000;">&#125;</span>
...</pre></div></div>

<p>5.) Create a new Skin-Class which uses the additional states</p>

<div class="wp_syntax"><div class="code"><pre class="mxml mxml" style="font-family:monospace;"><span style="color: #000000;"><span style="color: #7400FF;">&lt;s:states</span><span style="color: #7400FF;">&gt;</span></span>
    <span style="color: #000000;"><span style="color: #7400FF;">&lt;s:State</span> name=<span style="color: #ff0000;">&quot;normal&quot;</span><span style="color: #7400FF;">/&gt;</span></span>
    <span style="color: #000000;"><span style="color: #7400FF;">&lt;s:State</span> name=<span style="color: #ff0000;">&quot;disabled&quot;</span><span style="color: #7400FF;">/&gt;</span></span>
    <span style="color: #000000;"><span style="color: #7400FF;">&lt;s:State</span> name=<span style="color: #ff0000;">&quot;focused&quot;</span><span style="color: #7400FF;">/&gt;</span></span>
 <span style="color: #000000;"><span style="color: #7400FF;">&lt;/s:states</span><span style="color: #7400FF;">&gt;</span></span>
&nbsp;
<span style="color: #000000;"><span style="color: #808080; font-style: italic;">&lt;!-- background --&gt;</span></span> 
<span style="color: #000000;"><span style="color: #7400FF;">&lt;s:Rect</span> blendMode=<span style="color: #ff0000;">&quot;normal&quot;</span> left=<span style="color: #ff0000;">&quot;1&quot;</span> right=<span style="color: #ff0000;">&quot;1&quot;</span> top=<span style="color: #ff0000;">&quot;1&quot;</span> bottom=<span style="color: #ff0000;">&quot;1&quot;</span> radiusX=<span style="color: #ff0000;">&quot;3&quot;</span> radiusY=<span style="color: #ff0000;">&quot;3&quot;</span> alpha=<span style="color: #ff0000;">&quot;1&quot;</span><span style="color: #7400FF;">&gt;</span></span>
	<span style="color: #000000;"><span style="color: #7400FF;">&lt;s:fill</span><span style="color: #7400FF;">&gt;</span></span>
        <span style="color: #000000;"><span style="color: #7400FF;">&lt;s:SolidColor</span> id=<span style="color: #ff0000;">&quot;bgFill&quot;</span> color=<span style="color: #ff0000;">&quot;0xa2d2ff&quot;</span> color.focused=<span style="color: #ff0000;">&quot;0xe8f8ff&quot;</span>  <span style="color: #7400FF;">/&gt;</span></span>
	<span style="color: #000000;"><span style="color: #7400FF;">&lt;/s:fill</span><span style="color: #7400FF;">&gt;</span></span>
      <span style="color: #000000;"><span style="color: #7400FF;">&lt;s:stroke</span><span style="color: #7400FF;">&gt;</span></span>            
        <span style="color: #000000;"><span style="color: #7400FF;">&lt;s:SolidColorStroke</span> id=<span style="color: #ff0000;">&quot;stroke&quot;</span> color=<span style="color: #ff0000;">&quot;0x92c2ef&quot;</span> color.focused=<span style="color: #ff0000;">&quot;0xffffff&quot;</span>  weight=<span style="color: #ff0000;">&quot;1&quot;</span> <span style="color: #7400FF;">/&gt;</span></span>
      <span style="color: #000000;"><span style="color: #7400FF;">&lt;/s:stroke</span><span style="color: #7400FF;">&gt;</span></span>
<span style="color: #000000;"><span style="color: #7400FF;">&lt;/s:Rect</span><span style="color: #7400FF;">&gt;</span></span>
...</pre></div></div>

<p>6.) Declare the transition inside the Skin-Class on the Elements you want</p>

<div class="wp_syntax"><div class="code"><pre class="mxml mxml" style="font-family:monospace;"><span style="color: #000000;"><span style="color: #808080; font-style: italic;">&lt;!-- Transition from normal state to focused state and back --&gt;</span></span>
<span style="color: #000000;"><span style="color: #7400FF;">&lt;s:transitions</span><span style="color: #7400FF;">&gt;</span></span>
  <span style="color: #000000;"><span style="color: #7400FF;">&lt;s:Transition</span> fromState=<span style="color: #ff0000;">&quot;normal&quot;</span> toState=<span style="color: #ff0000;">&quot;focused&quot;</span> <span style="color: #7400FF;">&gt;</span></span>
    <span style="color: #000000;"><span style="color: #7400FF;">&lt;s:AnimateColor</span> duration=<span style="color: #ff0000;">&quot;350&quot;</span> targets=<span style="color: #ff0000;">&quot;{[bgFill,  stroke]}&quot;</span> <span style="color: #7400FF;">/&gt;</span></span>
  <span style="color: #000000;"><span style="color: #7400FF;">&lt;/s:Transition</span><span style="color: #7400FF;">&gt;</span></span> 
  <span style="color: #000000;"><span style="color: #7400FF;">&lt;s:Transition</span> fromState=<span style="color: #ff0000;">&quot;focused&quot;</span> toState=<span style="color: #ff0000;">&quot;normal&quot;</span> <span style="color: #7400FF;">&gt;</span></span>
    <span style="color: #000000;"><span style="color: #7400FF;">&lt;s:AnimateColor</span> duration=<span style="color: #ff0000;">&quot;350&quot;</span> targets=<span style="color: #ff0000;">&quot;{[bgFill,  stroke]}&quot;</span> <span style="color: #7400FF;">/&gt;</span></span>
  <span style="color: #000000;"><span style="color: #7400FF;">&lt;/s:Transition</span><span style="color: #7400FF;">&gt;</span></span> 
<span style="color: #000000;"><span style="color: #7400FF;">&lt;/s:transitions</span><span style="color: #7400FF;">&gt;</span></span>
...</pre></div></div>

<p><a href="http://www.hulstkamp.com/byard/gumbo/TextInputFocus/AHTextFieldTest.html">Test</a> and <a href="http://www.hulstkamp.com/byard/gumbo/TextInputFocus/srcview/index.html">source</a>  (sdk 4.0.0.7282). Note: textView has been renamed to textDisplay in the SkinnableTextBase.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.hulstkamp.com/2009/06/01/customize-the-spark-textinput-component-in-flex-4-gumbo-adding-focus-and-transitions/344/feed</wfw:commentRss>
		</item>
		<item>
		<title>Creating FXG-Library Elements at runtime in Flex 4 (Gumbo)</title>
		<link>http://www.hulstkamp.com/2009/05/28/creating-fxg-library-elements-at-runtime-in-flex-4-gumbo/337</link>
		<comments>http://www.hulstkamp.com/2009/05/28/creating-fxg-library-elements-at-runtime-in-flex-4-gumbo/337#comments</comments>
		<pubDate>Thu, 28 May 2009 21:07:49 +0000</pubDate>
		<dc:creator>Andy Hulstkamp</dc:creator>
		
		<category><![CDATA[Actionscript 3]]></category>

		<category><![CDATA[FXG]]></category>

		<category><![CDATA[Gumbo (Flex 4 beta)]]></category>

		<category><![CDATA[Definition]]></category>

		<category><![CDATA[element]]></category>

		<category><![CDATA[graphic]]></category>

		<category><![CDATA[instance]]></category>

		<category><![CDATA[Library]]></category>

		<category><![CDATA[runtime]]></category>

		<category><![CDATA[symbol]]></category>

		<guid isPermaLink="false">http://www.hulstkamp.com/?p=337</guid>
		<description><![CDATA[Part of the FXG 1.0 specification in Flex 4 makes it possible to define elements inside a library. The elements can then be re-used in a FXG document:

&#60;!--Library with the definitions --&#62;
&#60;Library&#62;
   &#60;Definition name=&#34;circle&#34;&#62;
	&#60;s:Ellipse x=&#34;0&#34; y=&#34;0&#34; width=&#34;100&#34; height=&#34;100&#34; &#62;
	   &#60;s:fill&#62;
		&#60;s:SolidColor color=&#34;0x000000&#34; /&#62;
	   &#60;/s:fill&#62;
	&#60;/s:Ellipse&#62;
   &#60;/Definition&#62;
&#60;/Library&#62;
&#160;
&#60;!-- use some instances [...]]]></description>
			<content:encoded><![CDATA[<p>Part of the FXG 1.0 specification in Flex 4 makes it possible to define elements inside a library. The elements can then be re-used in a FXG document:</p>

<div class="wp_syntax"><div class="code"><pre class="mxml mxml" style="font-family:monospace;"><span style="color: #000000;"><span style="color: #808080; font-style: italic;">&lt;!--Library with the definitions --&gt;</span></span>
<span style="color: #000000;">&lt;Library<span style="color: #7400FF;">&gt;</span></span>
   <span style="color: #000000;">&lt;Definition name=<span style="color: #ff0000;">&quot;circle&quot;</span><span style="color: #7400FF;">&gt;</span></span>
	<span style="color: #000000;"><span style="color: #7400FF;">&lt;s:Ellipse</span> x=<span style="color: #ff0000;">&quot;0&quot;</span> y=<span style="color: #ff0000;">&quot;0&quot;</span> width=<span style="color: #ff0000;">&quot;100&quot;</span> height=<span style="color: #ff0000;">&quot;100&quot;</span> <span style="color: #7400FF;">&gt;</span></span>
	   <span style="color: #000000;"><span style="color: #7400FF;">&lt;s:fill</span><span style="color: #7400FF;">&gt;</span></span>
		<span style="color: #000000;"><span style="color: #7400FF;">&lt;s:SolidColor</span> color=<span style="color: #ff0000;">&quot;0x000000&quot;</span> <span style="color: #7400FF;">/&gt;</span></span>
	   <span style="color: #000000;"><span style="color: #7400FF;">&lt;/s:fill</span><span style="color: #7400FF;">&gt;</span></span>
	<span style="color: #000000;"><span style="color: #7400FF;">&lt;/s:Ellipse</span><span style="color: #7400FF;">&gt;</span></span>
   <span style="color: #000000;">&lt;/Definition<span style="color: #7400FF;">&gt;</span></span>
<span style="color: #000000;">&lt;/Library<span style="color: #7400FF;">&gt;</span></span>
&nbsp;
<span style="color: #000000;"><span style="color: #808080; font-style: italic;">&lt;!-- use some instances of the definition  --&gt;</span></span>
<span style="color: #000000;">&lt;circle<span style="color: #7400FF;">/&gt;</span></span>
<span style="color: #000000;">&lt;circle x=<span style="color: #ff0000;">&quot;200&quot;</span> y=<span style="color: #ff0000;">&quot;100&quot;</span><span style="color: #7400FF;">/&gt;</span></span>
<span style="color: #000000;">&lt;circle x=<span style="color: #ff0000;">&quot;300&quot;</span> y=<span style="color: #ff0000;">&quot;100&quot;</span> height=<span style="color: #ff0000;">&quot;75&quot;</span> width=<span style="color: #ff0000;">&quot;75&quot;</span> <span style="color: #7400FF;">/&gt;</span></span></pre></div></div>

<p>As of now there is no way to create these symols at runtime. For example, if you&#8217;d like to create a starfield, you would need <span id="more-337"></span>to place all the objects inside the document - not exactly elegant.</p>
<p>Fortunately there&#8217;s a hack that works. The Flex compiler creates classes of the Library-Definitions in the background, which opens a path to create instances at runtime.</p>
<p>The Flex-Compiler creates classes with the name [DocumentName]_definition[1..n] from the definitions in the library. Using actionscript we can the do something like this:</p>

<div class="wp_syntax"><div class="code"><pre class="actionscript3 actionscript3" style="font-family:monospace;"><span style="color: #009900;">//create an instance of the graphic element. </span>
<span style="color: #009900;">//The definition is declared in a document with the name 'MyLibrary'</span>
<span style="color: #6699cc; font-weight: bold;">var</span> obj<span style="color: #000000; font-weight: bold;">:</span>GraphicElement = <span style="color: #0033ff; font-weight: bold;">new</span> MyLibrary_definition1<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>;
&nbsp;
<span style="color: #009900;">//set some properties of the graphic element</span>
<span style="color: #6699cc; font-weight: bold;">var</span> wh<span style="color: #000000; font-weight: bold;">:</span><span style="color: #004993;">Number</span> = <span style="color: #004993;">Math</span>.<span style="color: #004993;">random</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span> <span style="color: #000000; font-weight: bold;">*</span> <span style="color: #000000; font-weight:bold;">25</span> <span style="color: #000000; font-weight: bold;">+</span> <span style="color: #000000; font-weight:bold;">25</span>;
obj.<span style="color: #004993;">width</span> = obj.<span style="color: #004993;">height</span> = wh;
obj.<span style="color: #004993;">x</span> = <span style="color: #004993;">Math</span>.<span style="color: #004993;">random</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span> <span style="color: #000000; font-weight: bold;">*</span> container.<span style="color: #004993;">width</span>;
obj.<span style="color: #004993;">y</span> = <span style="color: #004993;">Math</span>.<span style="color: #004993;">random</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span> <span style="color: #000000; font-weight: bold;">*</span> container.<span style="color: #004993;">height</span>;
obj.<span style="color: #004993;">blendMode</span> = <span style="color: #990000;">&quot;screen&quot;</span>;
&nbsp;
<span style="color: #009900;">//the definition is a FilledElement. Change fill to blue</span>
<span style="color: #6699cc; font-weight: bold;">var</span> scf<span style="color: #000000; font-weight: bold;">:</span>SolidColor = SolidColor<span style="color: #000000;">&#40;</span>FilledElement<span style="color: #000000;">&#40;</span>obj<span style="color: #000000;">&#41;</span>.fill<span style="color: #000000;">&#41;</span>;
scf.<span style="color: #004993;">color</span> = 0x0000ff;
&nbsp;
<span style="color: #009900;">//container is just a group that holds the created elements</span>
container.addElement<span style="color: #000000;">&#40;</span>obj<span style="color: #000000;">&#41;</span>;</pre></div></div>

<p>Relying on the fact that the Flex-Compiler creates classes for the definitions in the background might not be the best way, but it works. Let&#8217;s hope we&#8217;ll get something like FXGLibrary.createElement(libraryName:String, defintionName:String) in the future&#8230;</p>
<p><a href="http://www.hulstkamp.com/byard/gumbo/fxgcreate/FXGLibraryTest.html">test</a> &#038; <a href="http://www.hulstkamp.com/byard/gumbo/fxgcreate/srcview/index.html">source</a> (sdk 4.0.0.7282)</p>
]]></content:encoded>
			<wfw:commentRss>http://www.hulstkamp.com/2009/05/28/creating-fxg-library-elements-at-runtime-in-flex-4-gumbo/337/feed</wfw:commentRss>
		</item>
		<item>
		<title>Skinning and creating custom rating component in flex 4 (Gumbo)</title>
		<link>http://www.hulstkamp.com/2009/03/12/skinning-and-creating-custom-rating-component-in-flex-4-gumbo/329</link>
		<comments>http://www.hulstkamp.com/2009/03/12/skinning-and-creating-custom-rating-component-in-flex-4-gumbo/329#comments</comments>
		<pubDate>Thu, 12 Mar 2009 17:27:03 +0000</pubDate>
		<dc:creator>Andy Hulstkamp</dc:creator>
		
		<category><![CDATA[Actionscript 3]]></category>

		<category><![CDATA[FXG]]></category>

		<category><![CDATA[Gumbo (Flex 4 beta)]]></category>

		<category><![CDATA[component]]></category>

		<category><![CDATA[customizing]]></category>

		<category><![CDATA[flex 4]]></category>

		<category><![CDATA[gumbo]]></category>

		<category><![CDATA[mask]]></category>

		<category><![CDATA[masking]]></category>

		<category><![CDATA[skin parts]]></category>

		<category><![CDATA[skin states]]></category>

		<category><![CDATA[skinning]]></category>

		<guid isPermaLink="false">http://www.hulstkamp.com/?p=329</guid>
		<description><![CDATA[Here&#8217;s a simple rating component done in Flex 4 (Gumbo).
The skin uses two library definitions. One symbol for the active and one for the passive rating. The symbols are then placed in a passive and an active Group. A mask is used to show/hide the active group based on the rating. ActiveGroup/passiveGroup and mask are [...]]]></description>
			<content:encoded><![CDATA[<p>Here&#8217;s a simple rating component done in Flex 4 (Gumbo).</p>
<p>The skin uses two library definitions. One symbol for the active and one for the passive rating. The symbols are then placed in a passive and an active Group. A mask is used to show/hide the active group based on the rating. ActiveGroup/passiveGroup and mask are the required Skin-Parts.</p>
<p>The Component itself manages the rating and pushes this down to the mask by setting its width. The rating is exposed as a bindable property.</p>
<p>The following example usees the component with two different skins.</p>
<p><a href="http://www.hulstkamp.com/byard/gumbo/ratingComponent/AhRatingComponentTest.html"><img src="http://www.hulstkamp.com/byard/gumbo/ratingComponent/customRatingComponent.png" alt="" /></a></p>
<p>source is <a href="http://www.hulstkamp.com/byard/gumbo/ratingComponent/srcview/index.html">here</a> (SDK 4.0.0.4932)</p>
]]></content:encoded>
			<wfw:commentRss>http://www.hulstkamp.com/2009/03/12/skinning-and-creating-custom-rating-component-in-flex-4-gumbo/329/feed</wfw:commentRss>
		</item>
	</channel>
</rss>
