<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Saturnboy &#187; flexlib</title>
	<atom:link href="http://saturnboy.com/tag/flexlib/feed/" rel="self" type="application/rss+xml" />
	<link>http://saturnboy.com</link>
	<description>Code, Work, and Life</description>
	<lastBuildDate>Thu, 01 Mar 2012 22:35:28 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.2.1</generator>
		<item>
		<title>Drawer Component in Flex 4</title>
		<link>http://saturnboy.com/2010/06/drawer-component-flex-4/</link>
		<comments>http://saturnboy.com/2010/06/drawer-component-flex-4/#comments</comments>
		<pubDate>Wed, 02 Jun 2010 04:31:09 +0000</pubDate>
		<dc:creator>justin</dc:creator>
				<category><![CDATA[Code]]></category>
		<category><![CDATA[custom component]]></category>
		<category><![CDATA[flex4]]></category>
		<category><![CDATA[flexlib]]></category>
		<category><![CDATA[skinning]]></category>

		<guid isPermaLink="false">http://saturnboy.com/?p=1418</guid>
		<description><![CDATA[I needed a good way to have a large settings panel with a minimal visual impact. The obvious answer is to hide or minimize or collapse the settings panel when not in use. I thought about using Flexlib&#8216;s WindowShade component (which I&#8217;ve dicussed in detail in Styling Flexlib&#8217;s WindowShade), but why reuse something when you [...]]]></description>
			<content:encoded><![CDATA[<p>I needed a good way to have a large settings panel with a minimal visual impact.  The obvious answer is to hide or minimize or collapse the settings panel when not in use.  I thought about using <a href="http://code.google.com/p/flexlib/">Flexlib</a>&#8216;s WindowShade component (which I&#8217;ve dicussed in detail in <a href="http://saturnboy.com/2009/03/styling-flexlib-windowshade/">Styling Flexlib&#8217;s WindowShade</a>), but why reuse something when you can reinvent the wheel?  Plus, it always helps to hone my Flex 4 custom component kung-fu.  So, I chose to implement a simple sliding drawer component from scratch as a Flex 4 component.</p>
<p class="bottom">The Drawer component is a vanilla container (it actually extends <code>SkinnableContainer</code>), so it will happily take any spark component for its children.  Before I dive into my implementation, let&#8217;s check out the finished drawer component in action (view source enabled):</p>
<div id="flashcontent-drawer" style="background-color:#eee">
Flash is required.  <a href="http://www.adobe.com/go/getflashplayer">Get it here!</a>
</div>
<p> Just click on the handle to open and close the drawer.</p>
<h3>Extending <code>SkinnableContainer</code></h3>
<p>The Drawer component itself, is just pure AS3, but the demo above uses a few MXML skins to achieve the desired look-and-feel.  This is a pretty standard pattern that I see during Flex 4 development, so expect it when you write your own custom components.</p>
<p class="bottom">We&#8217;ll review the component implementation in two steps.  First, we focus on the skin state management aspect of the drawer.  Here&#8217;s the relevant code (taken from <code>Drawer.as</code>):</p>

<div class="wp_syntax"><div class="code"><pre class="actionscript" style="font-family:monospace;"><span style="color: #66cc66;">&#91;</span>SkinState<span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">&quot;opened&quot;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#93;</span>
<span style="color: #0066CC;">public</span> <span style="color: #000000; font-weight: bold;">class</span> Drawer <span style="color: #0066CC;">extends</span> SkinnableContainer <span style="color: #66cc66;">&#123;</span>
    <span style="color: #0066CC;">private</span> <span style="color: #000000; font-weight: bold;">var</span> _opened:<span style="color: #0066CC;">Boolean</span> = <span style="color: #000000; font-weight: bold;">false</span>;
&nbsp;
    <span style="color: #0066CC;">public</span> <span style="color: #000000; font-weight: bold;">function</span> <span style="color: #0066CC;">get</span> opened<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>:<span style="color: #0066CC;">Boolean</span> <span style="color: #66cc66;">&#123;</span>
        <span style="color: #b1b100;">return</span> _opened;
    <span style="color: #66cc66;">&#125;</span>
&nbsp;
    <span style="color: #0066CC;">public</span> <span style="color: #000000; font-weight: bold;">function</span> <span style="color: #0066CC;">set</span> opened<span style="color: #66cc66;">&#40;</span>value:<span style="color: #0066CC;">Boolean</span><span style="color: #66cc66;">&#41;</span>:<span style="color: #0066CC;">void</span> <span style="color: #66cc66;">&#123;</span>
        <span style="color: #b1b100;">if</span> <span style="color: #66cc66;">&#40;</span>_opened <span style="color: #66cc66;">!</span>= value<span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#123;</span>
            _opened = value;
            invalidateSkinState<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;
        <span style="color: #66cc66;">&#125;</span>
    <span style="color: #66cc66;">&#125;</span>
&nbsp;
    override protected <span style="color: #000000; font-weight: bold;">function</span> getCurrentSkinState<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>:<span style="color: #0066CC;">String</span> <span style="color: #66cc66;">&#123;</span>
        <span style="color: #b1b100;">return</span> <span style="color: #66cc66;">&#40;</span>opened ? <span style="color: #ff0000;">'opened'</span> : <span style="color: #0066CC;">super</span>.<span style="color: #006600;">getCurrentSkinState</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span>;
    <span style="color: #66cc66;">&#125;</span>
    ...
<span style="color: #66cc66;">&#125;</span></pre></div></div>

<p>The <code>Drawer</code> component can either be closed (the default) or opened.  To model theses states, we use the <code>normal</code> state from the superclass to represent the closed drawer, and add a new <code>opened</code> <code>SkinState</code> to represent the opened drawer.  We just expose a simple <code>opened</code> boolean property with a custom getter and setter, and then override the <code>getCurrentSkinState()</code> method.  It&#8217;s important to remember the states we are talking about are skin states, and not <i>component</i> states (see <a href="http://saturnboy.com/2009/09/flex4-component-states-skin-states/">Flex 4 Component States vs. Skin States</a> for the difference).</p>
<p class="bottom">Second, we focus on the action of opening and closing the drawer.  Here&#8217;s the relevant code (taken from <code>Drawer.as</code>):</p>

<div class="wp_syntax"><div class="code"><pre class="actionscript" style="font-family:monospace;"><span style="color: #0066CC;">public</span> <span style="color: #000000; font-weight: bold;">class</span> Drawer <span style="color: #0066CC;">extends</span> SkinnableContainer <span style="color: #66cc66;">&#123;</span>
    ...
    <span style="color: #66cc66;">&#91;</span>SkinPart<span style="color: #66cc66;">&#40;</span>required=<span style="color: #ff0000;">&quot;false&quot;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#93;</span>
    <span style="color: #0066CC;">public</span> <span style="color: #000000; font-weight: bold;">var</span> openButton:<span style="color: #0066CC;">Button</span>;
&nbsp;
    <span style="color: #0066CC;">private</span> <span style="color: #000000; font-weight: bold;">function</span> clickHandler<span style="color: #66cc66;">&#40;</span>event:MouseEvent<span style="color: #66cc66;">&#41;</span>:<span style="color: #0066CC;">void</span> <span style="color: #66cc66;">&#123;</span>
        opened = <span style="color: #66cc66;">!</span>opened;
    <span style="color: #66cc66;">&#125;</span>
&nbsp;
    override protected <span style="color: #000000; font-weight: bold;">function</span> partAdded<span style="color: #66cc66;">&#40;</span>partName:<span style="color: #0066CC;">String</span>, instance:<span style="color: #0066CC;">Object</span><span style="color: #66cc66;">&#41;</span>:<span style="color: #0066CC;">void</span> <span style="color: #66cc66;">&#123;</span>
        <span style="color: #0066CC;">super</span>.<span style="color: #006600;">partAdded</span><span style="color: #66cc66;">&#40;</span>partName, instance<span style="color: #66cc66;">&#41;</span>;
        <span style="color: #b1b100;">if</span> <span style="color: #66cc66;">&#40;</span>instance == openButton<span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#123;</span>
            openButton.<span style="color: #006600;">addEventListener</span><span style="color: #66cc66;">&#40;</span>MouseEvent.<span style="color: #006600;">CLICK</span>, clickHandler<span style="color: #66cc66;">&#41;</span>;
        <span style="color: #66cc66;">&#125;</span>
    <span style="color: #66cc66;">&#125;</span>
&nbsp;
    override protected <span style="color: #000000; font-weight: bold;">function</span> partRemoved<span style="color: #66cc66;">&#40;</span>partName:<span style="color: #0066CC;">String</span>, instance:<span style="color: #0066CC;">Object</span><span style="color: #66cc66;">&#41;</span>:<span style="color: #0066CC;">void</span> <span style="color: #66cc66;">&#123;</span>
        <span style="color: #0066CC;">super</span>.<span style="color: #006600;">partRemoved</span><span style="color: #66cc66;">&#40;</span>partName, instance<span style="color: #66cc66;">&#41;</span>;
        <span style="color: #b1b100;">if</span> <span style="color: #66cc66;">&#40;</span>instance == openButton<span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#123;</span>
            openButton.<span style="color: #006600;">removeEventListener</span><span style="color: #66cc66;">&#40;</span>MouseEvent.<span style="color: #006600;">CLICK</span>, clickHandler<span style="color: #66cc66;">&#41;</span>;
        <span style="color: #66cc66;">&#125;</span>
    <span style="color: #66cc66;">&#125;</span>
<span style="color: #66cc66;">&#125;</span></pre></div></div>

<p>The <code>Drawer</code> component includes a simple spark button, as an optional <code>SkinPart</code>, that is used to initiate the state change.  The <code>partAdded()</code> and <code>partRemoved()</code> methods are overridden to manage and adding and removing of the button&#8217;s click event handler.  And lastly, the <code>clickHandler()</code> method flips between skin states by toggling the <code>opened</code> boolean property.</p>
<h3>Usage</h3>
<p class="bottom">Using the <code>Drawer</code> is the same as any container.  In MXML, just put any child components you want between the container&#8217;s open and close tags:</p>

<div class="wp_syntax"><div class="code"><pre class="mxml" style="font-family:monospace;"><span style="color: #000000;"><span style="color: #7400FF;">&lt;containers:Drawer</span> ... skinClass=<span style="color: #ff0000;">&quot;skins.DrawerSkin&quot;</span><span style="color: #7400FF;">&gt;</span></span>
    <span style="color: #000000;"><span style="color: #808080; font-style: italic;">&lt;!-- components go here --&gt;</span></span>
<span style="color: #000000;"><span style="color: #7400FF;">&lt;/containers:Drawer</span><span style="color: #7400FF;">&gt;</span></span></pre></div></div>

<p>Here we also apply the <code>DrawerSkin</code> to our container.</p>
<h3>Skins</h3>
<p class="bottom">The <code>DrawerSkin</code> is responsible for creating the desired look-and-feel and generally making the <code>Drawer</code> component look cool.  Here are the interesting parts of the skin:</p>

<div class="wp_syntax"><div class="code"><pre class="mxml" style="font-family:monospace;"><span style="color: #000000;"><span style="color: #7400FF;">&lt;s:Skin</span> ...<span style="color: #7400FF;">&gt;</span></span>
&nbsp;
    <span style="color: #000000;"><span style="color: #7400FF;">&lt;fx:Metadata</span><span style="color: #7400FF;">&gt;</span></span>
        [HostComponent(&quot;containers.Drawer&quot;)]
    <span style="color: #000000;"><span style="color: #7400FF;">&lt;/fx:Metadata</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;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;opened&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>
&nbsp;
   ...
&nbsp;
    <span style="color: #000000;"><span style="color: #7400FF;">&lt;s:Button</span> id=<span style="color: #ff0000;">&quot;openButton&quot;</span> ...</span>
<span style="color: #000000;">            skinClass=<span style="color: #ff0000;">&quot;skins.DrawerOpenButtonSkin&quot;</span></span>
<span style="color: #000000;">            skinClass.opened=<span style="color: #ff0000;">&quot;skins.DrawerCloseButtonSkin&quot;</span> <span style="color: #7400FF;">/&gt;</span></span>
&nbsp;
    <span style="color: #000000;"><span style="color: #7400FF;">&lt;s:Group</span> id=<span style="color: #ff0000;">&quot;contentGroup&quot;</span> ... includeIn=<span style="color: #ff0000;">&quot;opened&quot;</span> <span style="color: #7400FF;">/&gt;</span></span>
<span style="color: #000000;"><span style="color: #7400FF;">&lt;/s:Skin</span><span style="color: #7400FF;">&gt;</span></span></pre></div></div>

<p>The <code>DrawerSkin</code> has three skin states, <code>normal</code> and <code>disabled</code> are inherited from <code>SkinnableContainer</code>, but <code>opened</code> is our custom skin state.  The skin also includes the optional <code>openButton</code> <code>SkinPart</code>, which itself uses two custom buttons skins, one for the open drawer and one for the closed drawer.  Lastly, note that the container&#8217;s content is only displayed when the skin is in the <code>opened</code> state via the newfangled inline state syntax: <code>includeIn=&quot;opened&quot;</code>.</p>
<h5>Files</h5>
<ul>
<li><a href="http://saturnboy.com/proj/flex4/drawer/Drawer.html">Drawer</a> (<a href="http://saturnboy.com/proj/flex4/drawer/srcview/Drawer.zip">download</a>)</li>
</ul>
<div>
<script type="text/javascript">
swfobject.embedSWF('http://saturnboy.com/proj/flex4/drawer/Drawer.swf', 'flashcontent-drawer', '520', '340', '10.0.0', 'playerProductInstall.swf', false, { bgColor:'#eeeeee', base:'.' });
</script>
</div>
]]></content:encoded>
			<wfw:commentRss>http://saturnboy.com/2010/06/drawer-component-flex-4/feed/</wfw:commentRss>
		<slash:comments>17</slash:comments>
		</item>
		<item>
		<title>Styling Flexlib&#8217;s WindowShade</title>
		<link>http://saturnboy.com/2009/03/styling-flexlib-windowshade/</link>
		<comments>http://saturnboy.com/2009/03/styling-flexlib-windowshade/#comments</comments>
		<pubDate>Thu, 05 Mar 2009 05:45:03 +0000</pubDate>
		<dc:creator>justin</dc:creator>
				<category><![CDATA[Code]]></category>
		<category><![CDATA[Work]]></category>
		<category><![CDATA[design]]></category>
		<category><![CDATA[flex]]></category>
		<category><![CDATA[flexlib]]></category>
		<category><![CDATA[skinning]]></category>

		<guid isPermaLink="false">http://saturnboy.com/?p=246</guid>
		<description><![CDATA[A while back I started digging into the WindowShade component in Flexlib. I really needed a set of cool collapsable buckets for a project at work, and WindowShade was perfect for the task. Alas, I couldn&#8217;t find too much info on styling a WindowShade other than Doug McCune&#8217;s awesome example of WindowShade and Degrafa. So, [...]]]></description>
			<content:encoded><![CDATA[<p>A while back I started digging into the <a href="http://flexlib.googlecode.com/svn/trunk/docs/flexlib/containers/WindowShade.html">WindowShade</a> component in <a href="http://code.google.com/p/flexlib/">Flexlib</a>. I really needed a set of cool collapsable buckets for a project at <a href="http://www.gorillalogic.com/">work</a>, and WindowShade was perfect for the task.  Alas, I couldn&#8217;t find too much info on styling a WindowShade other than Doug McCune&#8217;s <a href="http://dougmccune.com/blog/2008/02/26/examples-from-my-360flex-session-using-open-source-community-projects/">awesome example of WindowShade and Degrafa</a>.  So, here is how I went about achieving the look and feel I needed with WindowShade.</p>
<h5>Plain Vanilla</h5>
<p>I started with an unstyled, super vanilla WindowShade wrapping a List.  And of course, I get this super-vanilla output:</p>
<p><a href="http://saturnboy.com/proj/shade/shade1/shade1.html">shade 1</a> (view source enabled)</p>
<p>The only styling magic was to add <code>padding="0"</code> to the WindowShade to get the child List component to suck up to the bottom of the WindowShade button.</p>
<h5>My First Attempt</h5>
<p class="bottom">In the next pass, I ditched the lame WindowShade button, and went with Flexlib&#8217;s <a href="http://flexlib.googlecode.com/svn/trunk/docs/flexlib/controls/CanvasButton.html">CanvasButton</a>, which contains a simple Label plus a CheckBox skinned with a plus or minus graphic. The code:</p>

<div class="wp_syntax"><div class="code"><pre class="mxml" style="font-family:monospace;"><span style="color: #000000;">&lt;?xml version=<span style="color: #ff0000;">&quot;1.0&quot;</span> encoding=<span style="color: #ff0000;">&quot;utf-8&quot;</span>?<span style="color: #7400FF;">&gt;</span></span>
<span style="color: #000000;"><span style="color: #7400FF;">&lt;mx:Application</span></span>
<span style="color: #000000;">        xmlns:mx=<span style="color: #ff0000;">&quot;http://www.adobe.com/2006/mxml&quot;</span></span>
<span style="color: #000000;">        xmlns:flexlibContainer=<span style="color: #ff0000;">&quot;flexlib.containers.*&quot;</span></span>
<span style="color: #000000;">        xmlns:flexlibControl=<span style="color: #ff0000;">&quot;flexlib.controls.*&quot;</span></span>
<span style="color: #000000;">        viewSourceURL=<span style="color: #ff0000;">&quot;srcview/index.html&quot;</span><span style="color: #7400FF;">&gt;</span></span>
&nbsp;
    <span style="color: #339933;">&lt;mx:Script&gt;</span>
<span style="color: #339933;">    &lt;![CDATA[</span>
<span style="color: #339933;">        [Bindable]</span>
<span style="color: #339933;">        private var goodies:Array = [</span>
<span style="color: #339933;">            { header:'Ice Cream', items:['Vanilla', 'Chocolate', 'Strawberry', 'Cookies &amp; Cream'] },</span>
<span style="color: #339933;">            { header:'Candy', items:['Twix', 'Snickers', 'Fire Balls', 'Hot Tamales', 'Mike &amp; Ikes', 'Pez'] },</span>
<span style="color: #339933;">            { header:'Cookies', items:['Chewy Chips Ahoy', 'Mint Milano', 'Oreo', 'Nutter Butter', 'Fig Newtons'] }];</span>
<span style="color: #339933;">    ]]&gt;</span>
<span style="color: #339933;">    &lt;/mx:Script&gt;</span>
&nbsp;
    <span style="color: #000000;"><span style="color: #7400FF;">&lt;mx:Style</span> source=<span style="color: #ff0000;">&quot;style.css&quot;</span> <span style="color: #7400FF;">/&gt;</span></span>
&nbsp;
    <span style="color: #000000;"><span style="color: #7400FF;">&lt;mx:VBox</span> width=<span style="color: #ff0000;">&quot;140&quot;</span> styleName=<span style="color: #ff0000;">&quot;container&quot;</span><span style="color: #7400FF;">&gt;</span></span>
        <span style="color: #000000;"><span style="color: #7400FF;">&lt;mx:Repeater</span> id=<span style="color: #ff0000;">&quot;r&quot;</span> dataProvider=<span style="color: #ff0000;">&quot;{goodies}&quot;</span><span style="color: #7400FF;">&gt;</span></span>
            <span style="color: #000000;"><span style="color: #7400FF;">&lt;flexlibContainer:WindowShade</span> width=<span style="color: #ff0000;">&quot;100%&quot;</span> styleName=<span style="color: #ff0000;">&quot;shade&quot;</span></span>
<span style="color: #000000;">                    data=<span style="color: #ff0000;">&quot;{r.currentItem.header}&quot;</span></span>
<span style="color: #000000;">                    opened=<span style="color: #ff0000;">&quot;{r.currentIndex == 0}&quot;</span><span style="color: #7400FF;">&gt;</span></span>
                <span style="color: #000000;"><span style="color: #7400FF;">&lt;flexlibContainer:headerRenderer</span><span style="color: #7400FF;">&gt;</span></span>
                    <span style="color: #000000;"><span style="color: #7400FF;">&lt;mx:Component</span><span style="color: #7400FF;">&gt;</span></span>
                        <span style="color: #000000;"><span style="color: #7400FF;">&lt;flexlibControl:CanvasButton</span> width=<span style="color: #ff0000;">&quot;100%&quot;</span> height=<span style="color: #ff0000;">&quot;30&quot;</span> styleName=<span style="color: #ff0000;">&quot;shadeBtn&quot;</span><span style="color: #7400FF;">&gt;</span></span>
                            <span style="color: #339933;">&lt;mx:Script&gt;</span>
<span style="color: #339933;">                            &lt;![CDATA[</span>
<span style="color: #339933;">                                import flexlib.containers.WindowShade;</span>
<span style="color: #339933;">                            ]]&gt;</span>
<span style="color: #339933;">                            &lt;/mx:Script&gt;</span>
&nbsp;
                            <span style="color: #000000;"><span style="color: #7400FF;">&lt;mx:Label</span> id=<span style="color: #ff0000;">&quot;header&quot;</span> top=<span style="color: #ff0000;">&quot;3&quot;</span> left=<span style="color: #ff0000;">&quot;4&quot;</span> text=<span style="color: #ff0000;">&quot;{WindowShade(parent).data}&quot;</span> styleName=<span style="color: #ff0000;">&quot;shadeHead&quot;</span><span style="color: #7400FF;">/&gt;</span></span>
                            <span style="color: #000000;"><span style="color: #7400FF;">&lt;mx:CheckBox</span> id=<span style="color: #ff0000;">&quot;chk&quot;</span> top=<span style="color: #ff0000;">&quot;9&quot;</span> right=<span style="color: #ff0000;">&quot;6&quot;</span> selected=<span style="color: #ff0000;">&quot;{WindowShade(parent).opened}&quot;</span> styleName=<span style="color: #ff0000;">&quot;shadeChk&quot;</span><span style="color: #7400FF;">/&gt;</span></span>
                        <span style="color: #000000;"><span style="color: #7400FF;">&lt;/flexlibControl:CanvasButton</span><span style="color: #7400FF;">&gt;</span></span>
                    <span style="color: #000000;"><span style="color: #7400FF;">&lt;/mx:Component</span><span style="color: #7400FF;">&gt;</span></span>
                <span style="color: #000000;"><span style="color: #7400FF;">&lt;/flexlibContainer:headerRenderer</span><span style="color: #7400FF;">&gt;</span></span>
&nbsp;
                <span style="color: #000000;"><span style="color: #7400FF;">&lt;mx:List</span> width=<span style="color: #ff0000;">&quot;100%&quot;</span> dataProvider=<span style="color: #ff0000;">&quot;{r.currentItem.items}&quot;</span> rowCount=<span style="color: #ff0000;">&quot;{r.currentItem.items.length}&quot;</span> styleName=<span style="color: #ff0000;">&quot;shadeList&quot;</span><span style="color: #7400FF;">/&gt;</span></span>
            <span style="color: #000000;"><span style="color: #7400FF;">&lt;/flexlibContainer:WindowShade</span><span style="color: #7400FF;">&gt;</span></span>
        <span style="color: #000000;"><span style="color: #7400FF;">&lt;/mx:Repeater</span><span style="color: #7400FF;">&gt;</span></span>
    <span style="color: #000000;"><span style="color: #7400FF;">&lt;/mx:VBox</span><span style="color: #7400FF;">&gt;</span></span>
<span style="color: #000000;"><span style="color: #7400FF;">&lt;/mx:Application</span><span style="color: #7400FF;">&gt;</span></span></pre></div></div>

<p>After throwing in some colors from a sweet <a href="http://kuler.adobe.com/#themeID/356863">Kuler theme</a> and embedding Helvetica, we get this:</p>
<p><a href="http://saturnboy.com/proj/shade/shade2/shade2.html">shade 2</a> (view source enabled)</p>
<p>At this point, I was really happy with look and feel, but there we still a few minor issues with the CanvasButton header that needed to be fixed before declaring victory.</p>
<h5>Fixups</h5>
<p>First, I needed the rollover event to flow down to the checkbox, so it would correctly show the overSkin on mouse over.  Second, I wanted a color change on the Label on rollover to provide better visual feedback to the user.  And lastly, I wanted the entire CanvasButton header to be clickable, not just the label text or the checkbox graphic.</p>
<p class="bottom">Focusing just on the modified CanvasButton code, used in the <code>headerRendered</code>:</p>

<div class="wp_syntax"><div class="code"><pre class="mxml" style="font-family:monospace;"><span style="color: #000000;"><span style="color: #7400FF;">&lt;flexlibControl:CanvasButton</span> width=<span style="color: #ff0000;">&quot;100%&quot;</span> height=<span style="color: #ff0000;">&quot;30&quot;</span> styleName=<span style="color: #ff0000;">&quot;shadeBtn&quot;</span></span>
<span style="color: #000000;">        rollOver=<span style="color: #ff0000;">&quot;header.setStyle('color', 0xffffff); chk.dispatchEvent(event);&quot;</span></span>
<span style="color: #000000;">        rollOut=<span style="color: #ff0000;">&quot;header.setStyle('color', 0xcccccc); chk.dispatchEvent(event);&quot;</span><span style="color: #7400FF;">&gt;</span></span>
    <span style="color: #339933;">&lt;mx:Script&gt;</span>
<span style="color: #339933;">    &lt;![CDATA[</span>
<span style="color: #339933;">        import flexlib.containers.WindowShade;</span>
<span style="color: #339933;">    ]]&gt;</span>
<span style="color: #339933;">    &lt;/mx:Script&gt;</span>
&nbsp;
    <span style="color: #000000;"><span style="color: #7400FF;">&lt;mx:Label</span> id=<span style="color: #ff0000;">&quot;header&quot;</span> top=<span style="color: #ff0000;">&quot;3&quot;</span> left=<span style="color: #ff0000;">&quot;4&quot;</span> text=<span style="color: #ff0000;">&quot;{WindowShade(parent).data}&quot;</span> styleName=<span style="color: #ff0000;">&quot;shadeHead&quot;</span><span style="color: #7400FF;">/&gt;</span></span>
    <span style="color: #000000;"><span style="color: #7400FF;">&lt;mx:CheckBox</span> id=<span style="color: #ff0000;">&quot;chk&quot;</span> top=<span style="color: #ff0000;">&quot;9&quot;</span> right=<span style="color: #ff0000;">&quot;6&quot;</span> selected=<span style="color: #ff0000;">&quot;{WindowShade(parent).opened}&quot;</span> styleName=<span style="color: #ff0000;">&quot;shadeChk&quot;</span><span style="color: #7400FF;">/&gt;</span></span>
    <span style="color: #000000;"><span style="color: #7400FF;">&lt;mx:Canvas</span> width=<span style="color: #ff0000;">&quot;100%&quot;</span> height=<span style="color: #ff0000;">&quot;100%&quot;</span> backgroundColor=<span style="color: #ff0000;">&quot;#000000&quot;</span> backgroundAlpha=<span style="color: #ff0000;">&quot;0&quot;</span> <span style="color: #7400FF;">/&gt;</span></span>
<span style="color: #000000;"><span style="color: #7400FF;">&lt;/flexlibControl:CanvasButton</span><span style="color: #7400FF;">&gt;</span></span></pre></div></div>

<p>The final result, a nice styled WindowShade:</p>
<p><a href="http://saturnboy.com/proj/shade/shade3/shade3.html">shade 3</a> (view source enabled)</p>
<p>I used the parent CanvasButton&#8217;s rollover event to set the child Label color and forward the event to the child CheckBox.  To make the entire button clickable, I used one of my favorite Flex UI hacks: I added a space-filling transparent Canvas.</p>
<h5>Comparison Shopping</h5>
<p class="bottom">And finally, a side-by-side comparison of all three WindowShade skins:</p>
<div id="flashcontent-windowshade">
Flash is required.  <a href="http://www.adobe.com/go/getflashplayer">Get it here!</a>
</div>
<p><b>Update:</b> See my <a href="http://saturnboy.com/2010/06/drawer-component-flex-4/">Drawer Component in Flex 4</a> post for a custom collapsible drawer component written from scratch in Flex 4.</p>
<div>
<script type="text/javascript">
swfobject.embedSWF('http://saturnboy.com/proj/shade/shade/shade.swf', 'flashcontent-windowshade', '530', '400', '9.0.28', 'expressInstall.swf', false, { bgColor:'#ffffff', base:'.' });
</script>
</div>
]]></content:encoded>
			<wfw:commentRss>http://saturnboy.com/2009/03/styling-flexlib-windowshade/feed/</wfw:commentRss>
		<slash:comments>16</slash:comments>
		</item>
	</channel>
</rss>

