<?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</title>
	<atom:link href="http://webroo.org/feed/" rel="self" type="application/rss+xml" />
	<link>http://webroo.org</link>
	<description>Matt Sweetman :: Flex &#38; Actionscript Development</description>
	<pubDate>Sun, 17 Jan 2010 18:24:02 +0000</pubDate>
	<generator>http://wordpress.org/?v=2.6.3</generator>
	<language>en</language>
			<item>
		<title>HTML 5 Canvas vs Flash</title>
		<link>http://webroo.org/2010/01/17/html-5-canvas-vs-flash/</link>
		<comments>http://webroo.org/2010/01/17/html-5-canvas-vs-flash/#comments</comments>
		<pubDate>Sun, 17 Jan 2010 16:11:26 +0000</pubDate>
		<dc:creator>Matt Sweetman</dc:creator>
		
		<category><![CDATA[Actionscript]]></category>

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

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

		<guid isPermaLink="false">http://webroo.org/?p=136</guid>
		<description><![CDATA[Over the holidays I gave myself a break from Actionscript and took a look at the HTML 5 Canvas object. It&#8217;s been a while since I programmed any javascript, and AJAX technologies seem to be the popular choice for web apps these days (goodbye Flex!). I decided to port over an old Actionscript 1 experiment [...]]]></description>
			<content:encoded><![CDATA[<p>Over the holidays I gave myself a break from Actionscript and took a look at the HTML 5 Canvas object. It&#8217;s been a while since I programmed any javascript, and AJAX technologies seem to be the popular choice for web apps these days (goodbye Flex!). I decided to port over an old Actionscript 1 experiment to see how the two technologies performed alongside each other, the results can be seen below.</p>
<p><img src="http://webroo.org/images/snow1.jpg" width="130" height="130" alt="Snowfall image" /><a href="http://webroo.org/media/snowfall/canvassnowfall.html">Canvas Snowfall</a></p>
<p><a href="http://webroo.org/media/snowfall/flashsnowfall.html">Flash Snowfall</a></p>
<p>You&#8217;ll need a modern browser to view the canvas version (eg: Firefox/Chrome/Opera/etc). View the source of the Canvas version for the javascript.</p>
<p>As you can see they look pretty much identical, the differences primarily lie in performance. The Flash version can handle more than twice the number of snowflakes before the frame rate drops. This may be down to the a fundamental difference between Canvas and Flash: Canvas is a rasterised bitmap object, whereas Flash is a vector animation tool. When you draw shapes in Canvas you&#8217;re drawing directly onto a bitmap, the shape can no longer be moved or scaled and is &#8216;baked&#8217; into the image. In some ways it&#8217;s similar to the BitmapData object in Flash. Because of this animation is far easier to accomplish in Flash and I had to adapt parts of the original code to work with the Canvas concept.</p>
<p><span id="more-136"></span>Javascript and AS1 share a lot in similarity as programming languages so porting the code was relatively easy. The Canvas object also has a similar API to the Graphics object in Flash. I&#8217;ll admit Javascript is not my favourite language, by a long shot, the lack of strict typing is difficult to return to after years of AS3, and in more complex scripts nested closures can get messy. It is however fast to program, which can come in very handy when prototyping and experimenting with ideas.</p>
<p>It may be worth investigating <a href="http://processingjs.org/">Processing</a>, a framework for the Canvas object written by John Resig, the guy behind JQuery.</p>
]]></content:encoded>
			<wfw:commentRss>http://webroo.org/2010/01/17/html-5-canvas-vs-flash/feed/</wfw:commentRss>
		</item>
		<item>
		<title>Overlapping hit areas for sibling sprites</title>
		<link>http://webroo.org/2009/12/01/overlapping-hit-areas-for-sibling-sprites/</link>
		<comments>http://webroo.org/2009/12/01/overlapping-hit-areas-for-sibling-sprites/#comments</comments>
		<pubDate>Tue, 01 Dec 2009 14:50:27 +0000</pubDate>
		<dc:creator>Matt Sweetman</dc:creator>
		
		<category><![CDATA[Actionscript]]></category>

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

		<guid isPermaLink="false">http://webroo.org/?p=124</guid>
		<description><![CDATA[I have a recurring problem with buttons. And when I mean buttons I mean anything that has a mouse handler and inherits from InteractiveObject, which includes Sprite and SimpleButton. The problem is when two or more of these objects are siblings (i.e. in the same container, not nested) and they overlap, then they block each [...]]]></description>
			<content:encoded><![CDATA[<p>I have a recurring problem with buttons. And when I mean buttons I mean anything that has a mouse handler and inherits from <span style="font-family: courier new">InteractiveObject</span>, which includes <span style="font-family: courier new">Sprite</span> and <span style="font-family: courier new">SimpleButton</span>. The problem is when two or more of these objects are siblings (i.e. in the same container, not nested) and they overlap, then they block each other. The top-most one will always receive mouse interaction and anything beneath is blocked.</p>
<p><img src="http://webroo.org/images/layers.jpg" alt="Blocked hit area diagram" /></p>
<p>What I would like is both Sprites to dispatch mouse events when the user interacts. Sometimes you can get round it by nesting buttons and using ROLL_OVER and MOUSE_OVER events, but this isn&#8217;t always practical, especially if there are a lot of overlapping buttons. So I&#8217;ve come up with another solution.</p>
<p>The idea is to create a &#8216;fake&#8217; hit area using the Rectangle object. Rectangle has a method called <span style="font-family: courier new">containsPoint</span>, which you pass a <span style="font-family: courier new">Point</span> object and it returns true or false depending on whether the coordinates fall inside the specified dimensions. So if you pass the mouse coordinates you can determine whether the mouse is inside the &#8216;fake&#8217; hit area. Also, because Rectangle isn&#8217;t a display object it can&#8217;t block mouse interaction, and so you can have multiple overlapping hit areas that all trigger when clicked.</p>
<p><span id="more-124"></span>The <span style="font-family: courier new">containsPoint</span> method has to be continually polled, so it needs to be called everytime the mouse moves. I&#8217;ve written some code that wraps this functionality up for ease of use. Take a look at the class below to see how the insides work.</p>
<p>Download: <a href="http://webroo.org/media/source/HitArea.as">HitArea.as</a></p>
<p>In the example below I&#8217;ve set up two hit areas and overlap them by 100px. The hit areas are invisible, so they won&#8217;t show up on the stage, but when you click on the overlapping section the CLICK event will fire twice, once for each hit area. There are also <span style="font-family: courier new">HitArea.ROLL_OVER</span> and <span style="font-family: courier new">HitArea.ROLL_OUT</span> events, which can be useful.</p>
<div class="codesnip-container" >
<div class="codesnip">hitArea1 = <span class="kw3">new</span> <span class="kw3">HitArea</span><span class="br0">&#40;</span><span class="nu0">200</span>, <span class="nu0">200</span><span class="br0">&#41;</span>; <span class="co1">// Dimensions are passed in the constructor</span><br />
addChild<span class="br0">&#40;</span>hitArea1<span class="br0">&#41;</span>;<br />
hitArea1.<span class="me1">addEventListener</span><span class="br0">&#40;</span><span class="kw3">HitArea</span>.<span class="me1">CLICK</span>, hitAreaClick<span class="br0">&#41;</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; <br />
hitArea2 = <span class="kw3">new</span> <span class="kw3">HitArea</span><span class="br0">&#40;</span><span class="nu0">200</span>, <span class="nu0">200</span><span class="br0">&#41;</span>;<br />
addChild<span class="br0">&#40;</span>hitArea2<span class="br0">&#41;</span>;<br />
hitArea2.<span class="me1">x</span> = <span class="nu0">100</span>; <span class="co1">// overlap the first hit area by 100 px</span><br />
hitArea2.<span class="me1">addEventListener</span><span class="br0">&#40;</span><span class="kw3">HitArea</span>.<span class="me1">CLICK</span>, hitAreaClick<span class="br0">&#41;</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; <br />
<span class="kw3">private</span> <span class="kw1">function</span> hitAreaClick<span class="br0">&#40;</span>event:Event<span class="br0">&#41;</span>:<span class="kw3">void</span><br />
<span class="br0">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span class="co1">// will fire twice, even on overlapping area</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span class="kw3">trace</span><span class="br0">&#40;</span><span class="st0">&#8220;click: &#8220;</span> + event.<span class="me1">target</span>.<span class="kw3">name</span><span class="br0">&#41;</span>;<br />
<span class="br0">&#125;</span></div>
</div>
<p>Unfortunately there are two downsides to this method: firstly it&#8217;s slightly more CPU intensive (it needs to constantly run code whenever the mouse moves). Secondly you can&#8217;t use the hand cursor with the hit area. This is the most problematic from a user-experience point of view. Unfortunately to get a hand cursor you need to set <span style="font-family: courier new">buttonMode=true</span> on the Sprite, and the moment you do that it turns it into a real button and we come back to the original problem.</p>
]]></content:encoded>
			<wfw:commentRss>http://webroo.org/2009/12/01/overlapping-hit-areas-for-sibling-sprites/feed/</wfw:commentRss>
		</item>
		<item>
		<title>Modulo and the negative divisor</title>
		<link>http://webroo.org/2009/10/24/modulo-and-the-negative-divisor/</link>
		<comments>http://webroo.org/2009/10/24/modulo-and-the-negative-divisor/#comments</comments>
		<pubDate>Sat, 24 Oct 2009 12:41:03 +0000</pubDate>
		<dc:creator>Matt Sweetman</dc:creator>
		
		<category><![CDATA[Actionscript]]></category>

		<guid isPermaLink="false">http://webroo.org/?p=111</guid>
		<description><![CDATA[I never had reason to doubt the modulo operator, but it turns out it&#8217;s been hiding a little secret from me all these years: it works differently in other programming langauges. I discovered this while converting a Python program to Flash. In Python the result of the modulo operation has the same sign as the [...]]]></description>
			<content:encoded><![CDATA[<p>I never had reason to doubt the modulo operator, but it turns out it&#8217;s been hiding a little secret from me all these years: it works differently in other programming langauges. I discovered this while converting a Python program to Flash. In Python the result of the modulo operation has the same sign as the right-hand number (divisor), but in Actionscript it has the same sign as the left-hand number (dividend). There&#8217;s a wikipedia article on the <a href="http://en.wikipedia.org/wiki/Modulo_operation">modulo operation</a> that explains it in more detail, and has a list of languages and their relevant implementation.</p>
<p>If you need to retain the sign of the divisor in your result (i.e. python-style) here&#8217;s a quick Actionscript method to achieve it:</p>
<div class="codesnip-container" >
<div class="codesnip"><span class="kw3">public</span> <span class="kw1">function</span> mod<span class="br0">&#40;</span>a:Number, b:Number<span class="br0">&#41;</span>:Number<br />
<span class="br0">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span class="kw3">return</span> a - <span class="br0">&#40;</span>b * <span class="kw3">Math</span>.<span class="kw3">floor</span><span class="br0">&#40;</span>a/b<span class="br0">&#41;</span><span class="br0">&#41;</span>;<br />
<span class="br0">&#125;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <br />
<span class="kw3">trace</span><span class="br0">&#40;</span><span class="nu0">100</span> % -<span class="nu0">30</span><span class="br0">&#41;</span>; <span class="co1">// output: 10</span><br />
<span class="kw3">trace</span><span class="br0">&#40;</span>mod<span class="br0">&#40;</span><span class="nu0">100</span>, -<span class="nu0">30</span><span class="br0">&#41;</span><span class="br0">&#41;</span>; <span class="co1">// output: -20 </span><br />
&nbsp;</div>
</div>
<p>Admittedly this is the first time in 10 years of actionscript programming that it&#8217;s caused me a problem, so take from that what you will.</p>
]]></content:encoded>
			<wfw:commentRss>http://webroo.org/2009/10/24/modulo-and-the-negative-divisor/feed/</wfw:commentRss>
		</item>
		<item>
		<title>Time sync for remote server</title>
		<link>http://webroo.org/2009/08/11/time-sync-for-remote-server/</link>
		<comments>http://webroo.org/2009/08/11/time-sync-for-remote-server/#comments</comments>
		<pubDate>Tue, 11 Aug 2009 13:09:42 +0000</pubDate>
		<dc:creator>Matt Sweetman</dc:creator>
		
		<category><![CDATA[Actionscript]]></category>

		<guid isPermaLink="false">http://webroo.org/?p=74</guid>
		<description><![CDATA[Here&#8217;s a quick little utility I used in my last project: a simple class that syncs with a time source. It can be used to ensure your application runs on server time rather than the user&#8217;s system clock. You sync once with the remote server at the start, and then Flash runs an internal timer [...]]]></description>
			<content:encoded><![CDATA[<p>Here&#8217;s a quick little utility I used in my last project: a simple class that syncs with a time source. It can be used to ensure your application runs on server time rather than the user&#8217;s system clock. You sync once with the remote server at the start, and then Flash runs an internal timer to calculate the time elapsed since you last synced. This can prevent multiple server calls everytime you need a time value.</p>

<object	type="application/x-shockwave-flash"
			data="/media/swf/timesyncexample.swf"
			width="300"
			height="25">
	<param name="movie" value="/media/swf/timesyncexample.swf" />
</object>
<p>Inside it uses the getTimer() function, which is good at keeping sync and is unaffected by system clock changes, even mid-application. It&#8217;s not a particularly difficult piece of code. I made the class a singleton, but you could use it differently if you wanted.</p>
<p><span id="more-74"></span></p>
<div class="codesnip-container" >
<div class="codesnip"><span class="kw2">package</span><br />
<span class="br0">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span class="kw3">import</span> flash.<span class="me1">utils</span>.<span class="kw3">getTimer</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; <br />
&nbsp; &nbsp; &nbsp; &nbsp; <span class="coMULTI">/**<br />
&nbsp; &nbsp; &nbsp; &nbsp;&nbsp; * TimeSync maintains a seperate time value from the system clock.<br />
&nbsp; &nbsp; &nbsp; &nbsp;&nbsp; */</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span class="kw3">public</span> <span class="kw2">class</span> TimeSync<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span class="br0">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="kw3">private</span> <span class="kw3">static</span> <span class="kw1">var</span> _instance:TimeSync;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="kw3">public</span> <span class="kw3">static</span> <span class="kw1">function</span> getInstance<span class="br0">&#40;</span><span class="br0">&#41;</span>:TimeSync<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="br0">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="kw3">if</span> <span class="br0">&#40;</span>_instance == <span class="kw3">null</span><span class="br0">&#41;</span> _instance = <span class="kw3">new</span> TimeSync<span class="br0">&#40;</span><span class="br0">&#41;</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="kw3">return</span> _instance; <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="br0">&#125;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="coMULTI">/**<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;&nbsp; * Internal time-stamp value to sync to.<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;&nbsp; * Must be set using sync().<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;&nbsp; */</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="kw3">protected</span> <span class="kw1">var</span> _syncStamp:Number;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="coMULTI">/**<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;&nbsp; * Time-stamp for the internal flash getTimer().<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;&nbsp; */</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="kw3">protected</span> <span class="kw1">var</span> _timerStamp:Number;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="kw3">public</span> <span class="kw1">function</span> TimeSync<span class="br0">&#40;</span><span class="br0">&#41;</span> <span class="br0">&#123;</span><span class="br0">&#125;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="coMULTI">/**<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;&nbsp; * The time elapsed since the last sync, in millseconds.<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;&nbsp; */</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="kw3">public</span> <span class="kw1">function</span> <span class="kw3">get</span> delta<span class="br0">&#40;</span><span class="br0">&#41;</span>:Number<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="br0">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="kw3">return</span> <span class="br0">&#40;</span><span class="kw3">getTimer</span><span class="br0">&#40;</span><span class="br0">&#41;</span> - _timerStamp<span class="br0">&#41;</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="br0">&#125;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="coMULTI">/**<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;&nbsp; * The synchronized time value, in milliseconds. Pass this into<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;&nbsp; * a new Date object to get formatted time: new Date(time);<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;&nbsp; */</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="kw3">public</span> <span class="kw1">function</span> <span class="kw3">get</span> <span class="kw3">time</span><span class="br0">&#40;</span><span class="br0">&#41;</span>:Number<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="br0">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="kw3">return</span> <span class="br0">&#40;</span>_syncStamp + delta<span class="br0">&#41;</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="br0">&#125;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="coMULTI">/**<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;&nbsp; * Sync the timer to a new time value.<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;&nbsp; * @param time Unix time value in milliseconds<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;&nbsp; */</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="kw3">public</span> <span class="kw1">function</span> sync<span class="br0">&#40;</span><span class="kw3">time</span>:Number<span class="br0">&#41;</span>:<span class="kw3">void</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="br0">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; _syncStamp = <span class="kw3">time</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; _timerStamp = <span class="kw3">getTimer</span><span class="br0">&#40;</span><span class="br0">&#41;</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="br0">&#125;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span class="br0">&#125;</span><br />
<span class="br0">&#125;</span></div>
</div>
<p>Download: <a href="http://webroo.org/media/source/TimeSync.as">TimeSync.as</a></p>
<p>To use it just call the sync() method and set the time value you want to sync to. Then everytime you need the synced time value use the .time property to retrieve it. You can also pass the time value into a new Date object to format it.</p>
<div class="codesnip-container" >
<div class="codesnip"><span class="co1">// Example</span><br />
<span class="kw1">var</span> timeSync:TimeSync = TimeSync.<span class="me1">getInstance</span><span class="br0">&#40;</span><span class="br0">&#41;</span>;<br />
timeSync.<span class="me1">sync</span><span class="br0">&#40;</span><span class="nu0">987654321098</span><span class="br0">&#41;</span>; <span class="co1">// set unix time value, in milliseconds</span><br />
<span class="kw3">trace</span><span class="br0">&#40;</span>timeSync.<span class="kw3">time</span><span class="br0">&#41;</span>; <span class="co1">// 987654321098</span><br />
<span class="kw3">trace</span><span class="br0">&#40;</span><span class="kw3">new</span> <span class="kw3">Date</span><span class="br0">&#40;</span>timeSync.<span class="kw3">time</span><span class="br0">&#41;</span><span class="br0">&#41;</span>; <span class="co1">// Thu Apr 19 05:25:21 GMT+0100 2001 </span><br />
&nbsp;</div>
</div>
<p><strong>Remote sync example</strong></p>
<p>To get it syncing remotely you just need to retrieve a unix time-stamp from a server. A simple bit of php code can do this:</p>
<div class="codesnip-container" >
<div class="codesnip"><span class="kw2">&lt;?php</span> <a href="http://www.php.net/echo"><span class="kw3">echo</span></a> <span class="st0">&#8220;time=&#8221;</span>.<a href="http://www.php.net/time"><span class="kw3">time</span></a><span class="br0">&#40;</span><span class="br0">&#41;</span>; <span class="kw2">?&gt;</span></div>
</div>
<p>Then use URLLoader in Flash to retrieve the value. Remember to multiply the value to milliseconds! Unix time is usually returned in seconds but Flash works in milliseconds.</p>
<div class="codesnip-container" >
<div class="codesnip"><span class="kw3">public</span> <span class="kw1">function</span> syncServerTime<span class="br0">&#40;</span><span class="br0">&#41;</span>:<span class="kw3">void</span><br />
<span class="br0">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span class="kw1">var</span> request:URLRequest = <span class="kw3">new</span> URLRequest<span class="br0">&#40;</span><span class="st0">&#8220;http://webroo.org/time.php&#8221;</span><span class="br0">&#41;</span>; <br />
&nbsp; &nbsp; &nbsp; &nbsp; <span class="kw1">var</span> loader:URLLoader = <span class="kw3">new</span> URLLoader<span class="br0">&#40;</span><span class="br0">&#41;</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; loader.<span class="me1">dataFormat</span> = URLLoaderDataFormat.<span class="me1">VARIABLES</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; loader.<span class="me1">addEventListener</span><span class="br0">&#40;</span>Event.<span class="me1">COMPLETE</span>, loaderCompleteHandler<span class="br0">&#41;</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; loader.<span class="me1">load</span><span class="br0">&#40;</span>request<span class="br0">&#41;</span>;<br />
<span class="br0">&#125;</span></p>
<p><span class="kw3">public</span> <span class="kw1">function</span> loaderCompleteHandler<span class="br0">&#40;</span>event:Event<span class="br0">&#41;</span>:<span class="kw3">void</span><br />
<span class="br0">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span class="kw1">var</span> <span class="kw3">time</span>:Number = <span class="br0">&#40;</span>event.<span class="me1">target</span> as URLLoader<span class="br0">&#41;</span>.<span class="me1">data</span>.<span class="kw3">time</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; TimeSync.<span class="me1">getInstance</span><span class="br0">&#40;</span><span class="br0">&#41;</span>.<span class="me1">sync</span><span class="br0">&#40;</span><span class="kw3">time</span> * <span class="nu0">1000</span><span class="br0">&#41;</span>; <span class="co1">// Multiply unix time to ms</span><br />
<span class="br0">&#125;</span></div>
</div>
<p>Download: <a href="http://webroo.org/media/source/TimeSyncExample.as">TimeSyncExample.as</a></p>
]]></content:encoded>
			<wfw:commentRss>http://webroo.org/2009/08/11/time-sync-for-remote-server/feed/</wfw:commentRss>
		</item>
		<item>
		<title>Auto size button for Flash components</title>
		<link>http://webroo.org/2009/04/19/auto-size-button-for-flash-components/</link>
		<comments>http://webroo.org/2009/04/19/auto-size-button-for-flash-components/#comments</comments>
		<pubDate>Sun, 19 Apr 2009 10:50:37 +0000</pubDate>
		<dc:creator>Matt Sweetman</dc:creator>
		
		<category><![CDATA[Flash]]></category>

		<guid isPermaLink="false">http://webroo.org/?p=56</guid>
		<description><![CDATA[I&#8217;ve recently been working outside of Flex in standard Flash &#038; Actionscript, so I thought I&#8217;d take the opportunity to try the CS3/4 components. They&#8217;re much leaner than their bigger brother&#8217;s, and as a consequence don&#8217;t offer anywhere near the functionality, but their simplicity means they&#8217;re fast and easy to work with.
One of the tweaks [...]]]></description>
			<content:encoded><![CDATA[<p>I&#8217;ve recently been working outside of Flex in standard Flash &#038; Actionscript, so I thought I&#8217;d take the opportunity to try the CS3/4 components. They&#8217;re much leaner than their bigger brother&#8217;s, and as a consequence don&#8217;t offer anywhere near the functionality, but their simplicity means they&#8217;re fast and easy to work with.</p>
<p>One of the tweaks I had to make was creating an auto-sizing Button:</p>

<object	type="application/x-shockwave-flash"
			data="/media/swf/autosizebutton.swf"
			width="380"
			height="95">
	<param name="movie" value="/media/swf/autosizebutton.swf" />
</object>
<p>If you type some text into the box you can see the difference. The standard Button doesn&#8217;t change it&#8217;s width based on the label length, which is crucial to any web project if it&#8217;s multi-lingual. So here&#8217;s my solution, with both an example and the code.</p>
<p><span id="more-56"></span><br />
<strong>Code</strong></p>
<p>In order to add the auto-sizing functionality I needed to subclass Button and override the layout routine. I also added a property that allows you to turn the auto-sizing on of off, the default is on.</p>
<div class="codesnip-container" >
<div class="codesnip"><span class="kw2">package</span><br />
<span class="br0">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span class="kw3">import</span> fl.<span class="me1">controls</span>.<span class="me1">Button</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span class="kw3">import</span> fl.<span class="me1">core</span>.<span class="me1">InvalidationType</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; <br />
&nbsp; &nbsp; &nbsp; &nbsp; <span class="kw3">import</span> flash.<span class="me1">text</span>.<span class="me1">TextFieldAutoSize</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; <br />
&nbsp; &nbsp; &nbsp; &nbsp; <span class="kw3">public</span> <span class="kw2">class</span> AutoSizeButton <span class="kw3">extends</span> Button<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span class="br0">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="kw3">public</span> <span class="kw1">function</span> AutoSizeButton<span class="br0">&#40;</span><span class="br0">&#41;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="br0">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="kw3">super</span><span class="br0">&#40;</span><span class="br0">&#41;</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="br0">&#125;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="kw3">protected</span> <span class="kw1">var</span> _autoSize:<span class="kw3">Boolean</span> = <span class="kw3">true</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="coMULTI">/**<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;&nbsp; * Whether auto sizing is turned on. Default is true.<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;&nbsp; */</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="kw3">public</span> <span class="kw1">function</span> <span class="kw3">get</span> <span class="kw3">autoSize</span><span class="br0">&#40;</span><span class="br0">&#41;</span>:<span class="kw3">Boolean</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="br0">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="kw3">return</span> _autoSize;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="br0">&#125;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="kw3">public</span> <span class="kw1">function</span> <span class="kw3">set</span> <span class="kw3">autoSize</span><span class="br0">&#40;</span>value:<span class="kw3">Boolean</span><span class="br0">&#41;</span>:<span class="kw3">void</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="br0">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; _autoSize = value;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="kw3">textField</span>.<span class="kw3">autoSize</span> = _autoSize ? TextFieldAutoSize.<span class="kw3">LEFT</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; : TextFieldAutoSize.<span class="me1">NONE</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; invalidate<span class="br0">&#40;</span>InvalidationType.<span class="kw3">SIZE</span><span class="br0">&#41;</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="br0">&#125;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="kw3">override</span> <span class="kw3">protected</span> <span class="kw1">function</span> drawLayout<span class="br0">&#40;</span><span class="br0">&#41;</span>:<span class="kw3">void</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="br0">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="kw3">if</span> <span class="br0">&#40;</span><span class="kw3">autoSize</span><span class="br0">&#41;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="br0">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="co1">// Set the component width by</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="co1">// calculating text &amp; padding widths</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="kw1">var</span> txtPad:Number =<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Number<span class="br0">&#40;</span>getStyleValue<span class="br0">&#40;</span><span class="st0">&#8220;textPadding&#8221;</span><span class="br0">&#41;</span><span class="br0">&#41;</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="kw3">_width</span> = <span class="br0">&#40;</span><span class="kw3">textField</span>.<span class="kw3">textWidth</span> + <span class="nu0">4</span><span class="br0">&#41;</span> + <span class="br0">&#40;</span><span class="nu0">2</span> * txtPad<span class="br0">&#41;</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="br0">&#125;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="kw3">super</span>.<span class="me1">drawLayout</span><span class="br0">&#40;</span><span class="br0">&#41;</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="br0">&#125;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <br />
&nbsp; &nbsp; &nbsp; &nbsp; <span class="br0">&#125;</span><br />
<span class="br0">&#125;</span></div>
</div>
<p>Basically all this class is doing is intercepting the layout drawing routine and pre-calculating the entire component width. Then it calls super.drawLayout() which ensures the text field sizes to the width. The calculation is taken directly from LabelButton, a super class of Button.</p>
<p><strong>Issues</strong></p>
<p>There are a few issues: Firstly it won&#8217;t work with an icon in the button, and secondly it doesn&#8217;t auto-size the height. Also you will need to instantiate it through Actionscript, like so:</p>
<div class="codesnip-container" >
<div class="codesnip"><span class="kw1">var</span> myButton:AutoSizeButton = <span class="kw3">new</span> AutoSizeButton<span class="br0">&#40;</span><span class="br0">&#41;</span>;<br />
myButton.<span class="me1">label</span> = <span class="st0">&#8220;My first button&#8221;</span>;<br />
addChild<span class="br0">&#40;</span>myButton<span class="br0">&#41;</span>;</div>
</div>
<p>Download source code here: <a href="http://webroo.org/media/source/AutoSizeButton.as">AutoSizeButton.as</a></p>
]]></content:encoded>
			<wfw:commentRss>http://webroo.org/2009/04/19/auto-size-button-for-flash-components/feed/</wfw:commentRss>
		</item>
		<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>
		<item>
		<title>New blog</title>
		<link>http://webroo.org/2008/02/15/new-blog/</link>
		<comments>http://webroo.org/2008/02/15/new-blog/#comments</comments>
		<pubDate>Fri, 15 Feb 2008 11:01:34 +0000</pubDate>
		<dc:creator>Matt Sweetman</dc:creator>
		
		<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://webroo.org/2008/02/15/new-blog-for-2008/</guid>
		<description><![CDATA[I&#8217;ve decided that what I should really do is start a new blog. I&#8217;ve been using other people&#8217;s blogs as a source of information and trouble-shooting for many years, and I think it&#8217;s finally time to give back some of the good karma. I&#8217;m going to share some of my Actionscript and Flex knowledge with [...]]]></description>
			<content:encoded><![CDATA[<p>I&#8217;ve decided that what I should really do is start a new blog. I&#8217;ve been using other people&#8217;s blogs as a source of information and trouble-shooting for many years, and I think it&#8217;s finally time to give back some of the good karma. I&#8217;m going to share some of my Actionscript and Flex knowledge with the rest of the world.</p>
<p>Of course writing about something that hasn&#8217;t already been documented in obsessive detail by a fellow nerd is always hard, especially with the deluge of blogs out there. But just <em>maybe</em> I can document a problem nobody&#8217;s encountered before, and someone, somewhere will benefit from what I type. And if it all goes wrong then I&#8217;ll just write about things I like.</p>
]]></content:encoded>
			<wfw:commentRss>http://webroo.org/2008/02/15/new-blog/feed/</wfw:commentRss>
		</item>
	</channel>
</rss>
