<?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>webroo.org &#187; Flex</title>
	<atom:link href="http://webroo.org/category/flex/feed/" rel="self" type="application/rss+xml" />
	<link>http://webroo.org</link>
	<description>Matt Sweetman :: Flex &#38; Actionscript Development</description>
	<pubDate>Tue, 08 Jun 2010 10:15:26 +0000</pubDate>
	<generator>http://wordpress.org/?v=2.6.3</generator>
	<language>en</language>
			<item>
		<title>Bindable interfaces with custom events</title>
		<link>http://webroo.org/2008/12/06/bindable-interfaces-with-custom-events/</link>
		<comments>http://webroo.org/2008/12/06/bindable-interfaces-with-custom-events/#comments</comments>
		<pubDate>Sat, 06 Dec 2008 18:12:51 +0000</pubDate>
		<dc:creator>Matt Sweetman</dc:creator>
		
		<category><![CDATA[Flex]]></category>

		<guid isPermaLink="false">http://webroo.org/?p=26</guid>
		<description><![CDATA[I&#8217;m surprised I haven&#8217;t stumbled across this before, but it caused a little head-scratching in a recent project. The problem involves having a class with a mixture of binding tags (i.e. with and without custom events), but assumes you are programming to the interface the class implements. In this case making it bindable proves a [...]]]></description>
			<content:encoded><![CDATA[<p>I&#8217;m surprised I haven&#8217;t stumbled across this before, but it caused a little head-scratching in a recent project. The problem involves having a class with a mixture of binding tags (i.e. with and without custom events), but assumes you are programming to the <em>interface</em> the class implements. In this case making it bindable proves a little unintuitive.</p>
<p>Imagine you have an class called <em>Artist</em> with two getter/setter properties: <em>name</em> and <em>age</em>. One of them uses a standard binding tag: [Bindable], the other uses a bindable tag with a custom event: [Bindable(event="artistAgeUpdate")]. Now you may be inclined to copy the tags into your interface and paste them above the getter/setter pair, like so:</p>
<p><span id="more-26"></span></p>
<div class="codesnip-container" >
<div class="codesnip"><span class="kw2">package</span> bindingTest<br />
<span class="br0">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span class="kw3">public</span> <span class="kw2">interface</span> IArtist<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span class="br0">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="br0">&#91;</span>Bindable<span class="br0">&#93;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="kw1">function</span> <span class="kw3">get</span> <span class="kw3">name</span><span class="br0">&#40;</span><span class="br0">&#41;</span>:String;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="kw1">function</span> <span class="kw3">set</span> <span class="kw3">name</span><span class="br0">&#40;</span>value:String<span class="br0">&#41;</span>:<span class="kw3">void</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="br0">&#91;</span>Bindable<span class="br0">&#40;</span>event=<span class="st0">&#8220;artistAgeUpdate&#8221;</span><span class="br0">&#41;</span><span class="br0">&#93;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="kw1">function</span> <span class="kw3">get</span> age<span class="br0">&#40;</span><span class="br0">&#41;</span>:int;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="kw1">function</span> <span class="kw3">set</span> age<span class="br0">&#40;</span>value:int<span class="br0">&#41;</span>:<span class="kw3">void</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span class="br0">&#125;</span><br />
<span class="br0">&#125;</span></div>
</div>
<p>But this will give you the following compiler error:</p>
<blockquote><p><em><strong><font color='#CC0000'>Error: [Bindable] not allowed on global or package-level functions</font></strong></em></p></blockquote>
<p>Also, putting a [Bindable] tag above the interface definition doesn&#8217;t work either, which is different to how classes work. The compiler won&#8217;t actually throw an error in this case, but the binding won&#8217;t work.</p>
<p><strong>The propertyChange event</strong></p>
<p>The solution is to specify an event for <em>every</em> bindable tag. This means you must use &#8220;propertyChange&#8221; for any normal [Bindable] tag used in your class. This is the event type the standard binding system dispatches. Take a look at PropertyChangeEvent in the Flex docs for more info.</p>
<div class="codesnip-container" >
<div class="codesnip"><span class="kw2">package</span> bindingTest<br />
<span class="br0">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span class="kw3">public</span> <span class="kw2">interface</span> IArtist<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span class="br0">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="br0">&#91;</span>Bindable<span class="br0">&#40;</span>event=<span class="st0">&#8220;propertyChange&#8221;</span><span class="br0">&#41;</span><span class="br0">&#93;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="kw1">function</span> <span class="kw3">get</span> <span class="kw3">name</span><span class="br0">&#40;</span><span class="br0">&#41;</span>:String;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="kw1">function</span> <span class="kw3">set</span> <span class="kw3">name</span><span class="br0">&#40;</span>value:String<span class="br0">&#41;</span>:<span class="kw3">void</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="br0">&#91;</span>Bindable<span class="br0">&#40;</span>event=<span class="st0">&#8220;artistAgeUpdate&#8221;</span><span class="br0">&#41;</span><span class="br0">&#93;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="kw1">function</span> <span class="kw3">get</span> age<span class="br0">&#40;</span><span class="br0">&#41;</span>:int;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="kw1">function</span> <span class="kw3">set</span> age<span class="br0">&#40;</span>value:int<span class="br0">&#41;</span>:<span class="kw3">void</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span class="br0">&#125;</span><br />
<span class="br0">&#125;</span></div>
</div>
<p>It seems classes and interfaces treat binding tags in slightly different ways. I guess the moral of the story is you should specify custom events for <em>every</em> bindable property. But that&#8217;s a lot of work. On the other hand it makes debugging those binding call-stacks a little easier as you can quickly identify the event type.</p>
]]></content:encoded>
			<wfw:commentRss>http://webroo.org/2008/12/06/bindable-interfaces-with-custom-events/feed/</wfw:commentRss>
		</item>
		<item>
		<title>Quality Glow and Blur Flex effects</title>
		<link>http://webroo.org/2008/11/04/quality-glow-and-blur-flex-effects/</link>
		<comments>http://webroo.org/2008/11/04/quality-glow-and-blur-flex-effects/#comments</comments>
		<pubDate>Tue, 04 Nov 2008 15:03:46 +0000</pubDate>
		<dc:creator>Matt Sweetman</dc:creator>
		
		<category><![CDATA[Flex]]></category>

		<guid isPermaLink="false">http://webroo.org/2008/11/04/quality-glow-and-blur-flex-effects/</guid>
		<description><![CDATA[The Glow and Blur effects are useful tweens that can be used to animate flash filters in Flex, the only problem is they don&#8217;t implement the quality property. It&#8217;s hard coded at a value of 1. In most cases this isn&#8217;t an issue, and where performance is concerned it&#8217;s best left unchanged. But having the [...]]]></description>
			<content:encoded><![CDATA[<p>The Glow and Blur effects are useful tweens that can be used to animate flash filters in Flex, the only problem is they don&#8217;t implement the <em>quality</em> property. It&#8217;s hard coded at a value of 1. In most cases this isn&#8217;t an issue, and where performance is concerned it&#8217;s best left unchanged. But having the extra control doesn&#8217;t hurt, especially considering a quality of even 2 or 4 can dramatically increase the smoothness a filter.</p>

<object	type="application/x-shockwave-flash"
			data="/media/swf/qualityglow.swf"
			width="370"
			height="60">
	<param name="movie" value="/media/swf/qualityglow.swf" />
</object>
<p>This shows the difference between a Glow effect with a quality of 4 and 1. As you can see the quality glow is far smoother. Adding the quality property onto Flex effects is quite simple, although it does require overriding two of the effect classes and duplicating a small amount of code.</p>
<p><span id="more-9"></span><br />
<strong>Effect and EffectInstance</strong></p>
<p>All Flex effects consist of subclasses of Effect and an EffectInstance. In the case of glow this is Glow and GlowInstance. Glow contains the properties and targets of the effect, and GlowInstance applies the actual filter. You need to subclass these and add the quality property to both:</p>
<div class="codesnip-container" >
<div class="codesnip"><span class="kw2">package</span> glowtest<br />
<span class="br0">&#123;</span><br />
&nbsp; &nbsp;<span class="kw3">import</span> mx.<span class="me1">effects</span>.<span class="me1">Glow</span>;<br />
&nbsp; &nbsp;<span class="kw3">import</span> mx.<span class="me1">effects</span>.<span class="me1">IEffectInstance</span>;</p>
<p>&nbsp; &nbsp;<span class="kw3">public</span> <span class="kw2">class</span> QualityGlow <span class="kw3">extends</span> Glow<br />
&nbsp; &nbsp;<span class="br0">&#123;</span><br />
&nbsp; &nbsp; &nbsp; <span class="co1">// Add the quality property</span><br />
&nbsp; &nbsp; &nbsp; <span class="br0">&#91;</span>Inspectable<span class="br0">&#40;</span>category=<span class="st0">&#8220;General&#8221;</span>, defaultValue=<span class="st0">&#8220;1&#8243;</span><span class="br0">&#41;</span><span class="br0">&#93;</span><br />
&nbsp; &nbsp; &nbsp; <span class="kw3">public</span> <span class="kw1">var</span> quality:Number;<br />
&nbsp; &nbsp; &nbsp; <br />
&nbsp; &nbsp; &nbsp; <span class="kw3">public</span> <span class="kw1">function</span> QualityGlow<span class="br0">&#40;</span>target:Object=<span class="kw3">null</span><span class="br0">&#41;</span><br />
&nbsp; &nbsp; &nbsp; <span class="br0">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span class="kw3">super</span><span class="br0">&#40;</span>target<span class="br0">&#41;</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span class="co1">// Our new class that applies the filter</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;instanceClass = QualityGlowInstance;<br />
&nbsp; &nbsp; &nbsp; <span class="br0">&#125;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <br />
&nbsp; &nbsp; &nbsp; <span class="kw3">override</span> <span class="kw3">protected</span> <span class="kw1">function</span> initInstance<span class="br0">&#40;</span>instance:IEffectInstance<span class="br0">&#41;</span>:<span class="kw3">void</span><br />
&nbsp; &nbsp; &nbsp; <span class="br0">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span class="kw3">super</span>.<span class="me1">initInstance</span><span class="br0">&#40;</span>instance<span class="br0">&#41;</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;QualityGlowInstance<span class="br0">&#40;</span>instance<span class="br0">&#41;</span>.<span class="me1">quality</span> = quality;<br />
&nbsp; &nbsp; &nbsp; <span class="br0">&#125;</span><br />
&nbsp; &nbsp;<span class="br0">&#125;</span><br />
<span class="br0">&#125;</span></div>
</div>
<p>Here I&#8217;ve added the &#8216;quality&#8217; property and tagged it with Inspectable metadata, which ensures it&#8217;s available in MXML. Also, instanceClass is set to our new version of QualityGlowInstance, a new class which makes sure the underlying GlowFilter uses the property &#8216;quality&#8217; in it&#8217;s constructor. </p>
<div class="codesnip-container" >
<div class="codesnip"><span class="kw2">package</span> glowtest<br />
<span class="br0">&#123;</span><br />
&nbsp; &nbsp;<span class="kw3">import</span> flash.<span class="me1">filters</span>.<span class="me1">GlowFilter</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; <br />
&nbsp; &nbsp;<span class="kw3">import</span> mx.<span class="me1">effects</span>.<span class="me1">effectClasses</span>.<span class="me1">GlowInstance</span>;</p>
<p>&nbsp; &nbsp;<span class="kw3">public</span> <span class="kw2">class</span> QualityGlowInstance <span class="kw3">extends</span> GlowInstance<br />
&nbsp; &nbsp;<span class="br0">&#123;</span><br />
&nbsp; &nbsp; &nbsp; <span class="kw3">public</span> <span class="kw1">var</span> quality:Number;</p>
<p>&nbsp; &nbsp; &nbsp; <span class="kw3">public</span> <span class="kw1">function</span> QualityGlowInstance<span class="br0">&#40;</span>target:Object<span class="br0">&#41;</span><br />
&nbsp; &nbsp; &nbsp; <span class="br0">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span class="kw3">super</span><span class="br0">&#40;</span>target<span class="br0">&#41;</span>;<br />
&nbsp; &nbsp; &nbsp; <span class="br0">&#125;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <br />
&nbsp; &nbsp; &nbsp; <span class="kw3">override</span> <span class="kw3">public</span> <span class="kw1">function</span> onTweenUpdate<span class="br0">&#40;</span>value:Object<span class="br0">&#41;</span>:<span class="kw3">void</span><br />
&nbsp; &nbsp; &nbsp; <span class="br0">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;setQualityGlowFilter<span class="br0">&#40;</span>value<span class="br0">&#91;</span><span class="nu0">0</span><span class="br0">&#93;</span>, value<span class="br0">&#91;</span><span class="nu0">1</span><span class="br0">&#93;</span>, value<span class="br0">&#91;</span><span class="nu0">2</span><span class="br0">&#93;</span>, value<span class="br0">&#91;</span><span class="nu0">3</span><span class="br0">&#93;</span><span class="br0">&#41;</span>;<br />
&nbsp; &nbsp; &nbsp; <span class="br0">&#125;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <br />
&nbsp; &nbsp; &nbsp; <span class="kw3">override</span> <span class="kw3">public</span> <span class="kw1">function</span> onTweenEnd<span class="br0">&#40;</span>value:Object<span class="br0">&#41;</span>:<span class="kw3">void</span><br />
&nbsp; &nbsp; &nbsp; <span class="br0">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;setQualityGlowFilter<span class="br0">&#40;</span>value<span class="br0">&#91;</span><span class="nu0">0</span><span class="br0">&#93;</span>, value<span class="br0">&#91;</span><span class="nu0">1</span><span class="br0">&#93;</span>, value<span class="br0">&#91;</span><span class="nu0">2</span><span class="br0">&#93;</span>, value<span class="br0">&#91;</span><span class="nu0">3</span><span class="br0">&#93;</span><span class="br0">&#41;</span>;&nbsp; &nbsp; <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span class="kw3">super</span>.<span class="me1">onTweenEnd</span><span class="br0">&#40;</span>value<span class="br0">&#41;</span>;&nbsp; &nbsp; &nbsp; &nbsp;<br />
&nbsp; &nbsp; &nbsp; <span class="br0">&#125;</span></p>
<p>&nbsp; &nbsp; &nbsp; <span class="co1">// setGlowFilter() is private in the superclass</span><br />
&nbsp; &nbsp; &nbsp; <span class="co1">// so we duplicate it&#8217;s functionality here:</span><br />
&nbsp; &nbsp; &nbsp; <span class="kw3">protected</span> <span class="kw1">function</span> setQualityGlowFilter<span class="br0">&#40;</span>color:uint, alpha:Number, blurX:Number, blurY:Number<span class="br0">&#41;</span>:<span class="kw3">void</span><br />
&nbsp; &nbsp; &nbsp; <span class="br0">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span class="kw1">var</span> filters:Array = target.<span class="me1">filters</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span class="co1">// Remove any existing Glow filters</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span class="kw1">var</span> n:int = filters.<span class="me1">length</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span class="kw3">for</span> <span class="br0">&#40;</span><span class="kw1">var</span> i:int = <span class="nu0">0</span>; i &lt; n; i++<span class="br0">&#41;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span class="br0">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="kw3">if</span> <span class="br0">&#40;</span>filters<span class="br0">&#91;</span>i<span class="br0">&#93;</span> is GlowFilter<span class="br0">&#41;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;filters.<span class="me1">splice</span><span class="br0">&#40;</span>i, <span class="nu0">1</span><span class="br0">&#41;</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span class="br0">&#125;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span class="co1">// Add quality property to GlowFilter:</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span class="kw3">if</span> <span class="br0">&#40;</span>blurX || blurY || alpha<span class="br0">&#41;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; filters.<span class="me1">push</span><span class="br0">&#40;</span><span class="kw3">new</span> GlowFilter<span class="br0">&#40;</span>color, alpha, blurX, blurY, strength, quality, inner, knockout<span class="br0">&#41;</span><span class="br0">&#41;</span>;</p>
<p>&nbsp; &nbsp; &nbsp; &nbsp; target.<span class="me1">filters</span> = filters;<br />
&nbsp; &nbsp; &nbsp; <span class="br0">&#125;</span><br />
&nbsp; &nbsp;<span class="br0">&#125;</span><br />
<span class="br0">&#125;</span></div>
</div>
<p>Apologies for the length of this class, but some code needed to be duplicated from the superclass. A common problem with the Flex framework is private methods, which means you cannot override them in a subclass. In this case setGlowFilter was the culprit, and in order change it&#8217;s functionality I had to duplicate the contents and change any references made elsewhere. This explains why the two onTween* methods are overridden.</p>
<p>Identical changes can be made to the Blur effect to get the quality property working, or simply download all the classes below.</p>
<p>Download source code here: <a href="http://webroo.org/media/source/qualityflexeffects.zip">qualityflexeffects.zip</a></p>
]]></content:encoded>
			<wfw:commentRss>http://webroo.org/2008/11/04/quality-glow-and-blur-flex-effects/feed/</wfw:commentRss>
		</item>
		<item>
		<title>Overlapping TabBar in Flex</title>
		<link>http://webroo.org/2008/02/27/overlapping-tabbar-in-flex/</link>
		<comments>http://webroo.org/2008/02/27/overlapping-tabbar-in-flex/#comments</comments>
		<pubDate>Wed, 27 Feb 2008 13:07:50 +0000</pubDate>
		<dc:creator>Matt Sweetman</dc:creator>
		
		<category><![CDATA[Flex]]></category>

		<guid isPermaLink="false">http://webroo.org/2008/02/27/overlapping-tabbar-in-flex/</guid>
		<description><![CDATA[On a recent project I needed an overlapping tab bar, something that the default Flex TabBar doesn&#8217;t implement. While you can can easily change the spacing between tabs using a negative horizontalGap, you cannot retain a top-of-the-pile-like status for the selected tab. They are permanently stacked left-to-right on top of each other.
There&#8217;s a solution out [...]]]></description>
			<content:encoded><![CDATA[<p>On a recent project I needed an overlapping tab bar, something that the default Flex TabBar doesn&#8217;t implement. While you can can easily change the spacing between tabs using a negative horizontalGap, you cannot retain a top-of-the-pile-like status for the selected tab. They are permanently stacked left-to-right on top of each other.</p>
<p>There&#8217;s a solution out there that relies on <a href="http://scalenine.com/blog/2007/04/19/creating-overlapping-tabs-in-flex-graphically/">clever skinning techniques</a>, but it&#8217;s a little time-consuming and inflexible. So after some poking around inside the Flex framework I discovered the underlying problem and came up with this solution:</p>

<object	type="application/x-shockwave-flash"
			data="/media/swf/overlappingtabbar.swf"
			width="370"
			height="41">
	<param name="movie" value="/media/swf/overlappingtabbar.swf" />
</object>
<p>Before I explain how I achieved this let&#8217;s take a look at the problem with the default TabBar:</p>
<p><span id="more-8"></span><strong>The Problem</strong></p>

<object	type="application/x-shockwave-flash"
			data="/media/swf/defaulttabbar.swf"
			width="370"
			height="41">
	<param name="movie" value="/media/swf/defaulttabbar.swf" />
</object>
<p>The example above shows the default TabBar functionality. Notice the right-hand side each tab is obscured by the next tab along, no matter which tab you select. The problem lies in the way TabBar arranges it&#8217;s children buttons. TabBar ultimately derives from Box, which uses the BoxLayout class to order sprites left-to-right based on their index in the display list. This means if you change the depth of a sprite in a Box it&#8217;s corresponding horizontal position will also change. So in our situation, changing the selected tab&#8217;s depth to the top causes the tab-sprite to be moved to the far-right of the box.</p>
<p><strong>The Solution</strong></p>
<p>Based on what&#8217;s overridable in TabBar the best solution is to manage the position of the tabs in the display list ourselves. To do this we need to subclass TabBar and store a fixed reference of the tabs in an array and dictionary. We then return these positions when the layout class arranges everything, which satisfies the layout routine&#8217;s desire to order everything left-to-right on depth. This then leaves us to manage the real sprite depths ourselves. Hopefully this code will explain it better:</p>
<div class="codesnip-container" >
<div class="codesnip"><span class="kw3">public</span> <span class="kw2">class</span> OverlappingTabBar <span class="kw3">extends</span> TabBar<br />
<span class="br0">&#123;</span><br />
&nbsp; &nbsp;<span class="co1">// Used to store local reference to tabs</span><br />
&nbsp; &nbsp;<span class="kw3">private</span> <span class="kw1">var</span> _tabs:Array;<br />
&nbsp; &nbsp;<span class="kw3">private</span> <span class="kw1">var</span> _tabsDict:Dictionary;<br />
&nbsp; &nbsp;<br />
&nbsp; &nbsp;<span class="kw3">public</span> <span class="kw1">function</span> OverlappingTabBar<span class="br0">&#40;</span><span class="br0">&#41;</span><br />
&nbsp; &nbsp;<span class="br0">&#123;</span><br />
&nbsp; &nbsp; &nbsp; <span class="kw3">super</span><span class="br0">&#40;</span><span class="br0">&#41;</span>;<br />
&nbsp; &nbsp; &nbsp; _tabs = <span class="kw3">new</span> Array<span class="br0">&#40;</span><span class="br0">&#41;</span>;<br />
&nbsp; &nbsp; &nbsp; _tabsDict = <span class="kw3">new</span> Dictionary<span class="br0">&#40;</span><span class="kw3">true</span><span class="br0">&#41;</span>;<br />
&nbsp; &nbsp;<span class="br0">&#125;</span><br />
&nbsp; &nbsp;<br />
&nbsp; &nbsp;<span class="kw3">override</span> <span class="kw3">protected</span> <span class="kw1">function</span> createNavItem<span class="br0">&#40;</span>label:String, icon:<span class="kw2">Class</span> = <span class="kw3">null</span><span class="br0">&#41;</span>:IFlexDisplayObject<br />
&nbsp; &nbsp;<span class="br0">&#123;</span><br />
&nbsp; &nbsp; &nbsp; <span class="kw1">var</span> <span class="kw3">tabIndex</span>:int = numChildren;<br />
&nbsp; &nbsp; &nbsp; <span class="kw1">var</span> navItem:IFlexDisplayObject = <span class="kw3">super</span>.<span class="me1">createNavItem</span><span class="br0">&#40;</span>label, icon<span class="br0">&#41;</span>;<br />
&nbsp; &nbsp; &nbsp; <span class="co1">// Store tab refs in our array and dictionary</span><br />
&nbsp; &nbsp; &nbsp; _tabs.<span class="me1">push</span><span class="br0">&#40;</span>navItem<span class="br0">&#41;</span>;<br />
&nbsp; &nbsp; &nbsp; _tabsDict<span class="br0">&#91;</span>navItem<span class="br0">&#93;</span> = <span class="kw3">tabIndex</span>;<br />
&nbsp; &nbsp; &nbsp; <span class="kw3">return</span> navItem;<br />
&nbsp; &nbsp;<span class="br0">&#125;</span><br />
&nbsp; &nbsp;<br />
&nbsp; &nbsp;<span class="kw3">override</span> <span class="kw3">public</span> <span class="kw1">function</span> getChildAt<span class="br0">&#40;</span><span class="kw3">index</span>:int<span class="br0">&#41;</span>:DisplayObject<br />
&nbsp; &nbsp;<span class="br0">&#123;</span><br />
&nbsp; &nbsp; &nbsp; <span class="kw3">return</span> _tabs<span class="br0">&#91;</span><span class="kw3">index</span><span class="br0">&#93;</span>;<br />
&nbsp; &nbsp;<span class="br0">&#125;</span><br />
&nbsp; &nbsp;<br />
&nbsp; &nbsp;<span class="kw3">override</span> <span class="kw3">public</span> <span class="kw1">function</span> getChildIndex<span class="br0">&#40;</span>child:DisplayObject<span class="br0">&#41;</span>:int<br />
&nbsp; &nbsp;<span class="br0">&#123;</span><br />
&nbsp; &nbsp; &nbsp; <span class="kw3">return</span> _tabsDict<span class="br0">&#91;</span>child<span class="br0">&#93;</span>;<br />
&nbsp; &nbsp;<span class="br0">&#125;</span><br />
&nbsp; &nbsp;<br />
&nbsp; &nbsp;<span class="kw3">override</span> <span class="kw3">public</span> <span class="kw1">function</span> removeChildAt<span class="br0">&#40;</span><span class="kw3">index</span>:int<span class="br0">&#41;</span>:DisplayObject<br />
&nbsp; &nbsp;<span class="br0">&#123;</span><br />
&nbsp; &nbsp; &nbsp; <span class="co1">// ensures tabs are cleaned up from our</span><br />
&nbsp; &nbsp; &nbsp; <span class="co1">// array and dictionary when removed</span><br />
&nbsp; &nbsp; &nbsp; <span class="kw1">var</span> c:DisplayObject = <span class="kw3">super</span>.<span class="me1">removeChild</span><span class="br0">&#40;</span>getChildAt<span class="br0">&#40;</span><span class="kw3">index</span><span class="br0">&#41;</span><span class="br0">&#41;</span>;<br />
&nbsp; &nbsp; &nbsp; _tabsDict<span class="br0">&#91;</span>getChildAt<span class="br0">&#40;</span><span class="kw3">index</span><span class="br0">&#41;</span><span class="br0">&#93;</span> = <span class="kw3">null</span>;<br />
&nbsp; &nbsp; &nbsp; _tabs.<span class="me1">splice</span><span class="br0">&#40;</span><span class="kw3">index</span>, <span class="nu0">1</span><span class="br0">&#41;</span>;<br />
&nbsp; &nbsp; &nbsp; <span class="kw3">return</span> c;<br />
&nbsp; &nbsp;<span class="br0">&#125;</span><br />
<span class="br0">&#125;</span></div>
</div>
<p>We&#8217;re simply storing the original position for each tab when it&#8217;s created in createNavItem(), then we return the stored position everytime getChildAt() and getChildIndex() is called (as it will be by the layout class). The overridden removeChildAt() ensures that our array and dictionary is kept up to date if tabs are removed from the bar, which occurs whenever the TabBar.dataProvider is changed.</p>
<p>Finally we need organise the tabs in the display list ourselves. The best location I found to do this was in hiliteSelectedNavItem(), as the method is passed the index of the selected tab.</p>
<div class="codesnip-container" >
<div class="codesnip"><span class="kw3">override</span> <span class="kw3">protected</span> <span class="kw1">function</span> hiliteSelectedNavItem<span class="br0">&#40;</span><span class="kw3">index</span>:int<span class="br0">&#41;</span>:<span class="kw3">void</span><br />
<span class="br0">&#123;</span><br />
&nbsp; &nbsp;<span class="kw3">super</span>.<span class="me1">hiliteSelectedNavItem</span><span class="br0">&#40;</span><span class="kw3">index</span><span class="br0">&#41;</span>;<br />
&nbsp; &nbsp;<span class="kw3">if</span> <span class="br0">&#40;</span><span class="kw3">index</span> != -<span class="nu0">1</span><span class="br0">&#41;</span><br />
&nbsp; &nbsp;<span class="br0">&#123;</span><br />
&nbsp; &nbsp; &nbsp; <span class="co1">// z-order tabs</span><br />
&nbsp; &nbsp; &nbsp; <span class="kw1">var</span> l:int = _tabs.<span class="me1">length</span> - <span class="nu0">1</span>;<br />
&nbsp; &nbsp; &nbsp; <span class="kw3">for</span> <span class="br0">&#40;</span><span class="kw1">var</span> i:int = <span class="nu0">0</span>; i &lt;= l; i++<span class="br0">&#41;</span> <span class="br0">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;setChildIndex<span class="br0">&#40;</span>_tabs<span class="br0">&#91;</span>i<span class="br0">&#93;</span>, <span class="br0">&#40;</span>l-i<span class="br0">&#41;</span><span class="br0">&#41;</span>;<br />
&nbsp; &nbsp; &nbsp; <span class="br0">&#125;</span><br />
&nbsp; &nbsp; &nbsp; <span class="co1">// put our selected tab at the top</span><br />
&nbsp; &nbsp; &nbsp; setChildIndex<span class="br0">&#40;</span>_tabs<span class="br0">&#91;</span><span class="kw3">index</span><span class="br0">&#93;</span>, l<span class="br0">&#41;</span>;<br />
&nbsp; &nbsp;<span class="br0">&#125;</span><br />
<span class="br0">&#125;</span></div>
</div>
<p>Of course it would look nicer with some decoratively sloped tab edges, but hopefully you get the idea. I admit that the code is a bit of a hack on top of the original component, and I can&#8217;t guarantee it won&#8217;t cause problems somewhere down the line, but iso far it&#8217;s proved robust. You should be able to swap out your original TabBar instances with OverlappingTabBar by simply renaming the MXML tag.</p>
<p>Download the source code here: <a href="/media/source/OverlappingTabBar.as">OverlappingTabBar.as</a></p>
]]></content:encoded>
			<wfw:commentRss>http://webroo.org/2008/02/27/overlapping-tabbar-in-flex/feed/</wfw:commentRss>
		</item>
	</channel>
</rss>
