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

<channel>
	<title>firstrow RIA</title>
	<atom:link href="http://flash.firstrowria.com/feed/" rel="self" type="application/rss+xml" />
	<link>http://flash.firstrowria.com</link>
	<description>Enterprise RIA consulting, training and software development</description>
	<lastBuildDate>Wed, 30 Nov 2011 14:24:55 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.8.4</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>[AS3] Application wide event broadcasting</title>
		<link>http://flash.firstrowria.com/2010/05/as3-application-wide-event-broadcasting/</link>
		<comments>http://flash.firstrowria.com/2010/05/as3-application-wide-event-broadcasting/#comments</comments>
		<pubDate>Tue, 04 May 2010 21:46:09 +0000</pubDate>
		<dc:creator>Bernd</dc:creator>
				<category><![CDATA[AS3]]></category>
		<category><![CDATA[application]]></category>
		<category><![CDATA[application wide]]></category>
		<category><![CDATA[broadcast]]></category>
		<category><![CDATA[channel]]></category>
		<category><![CDATA[event]]></category>
		<category><![CDATA[event listener]]></category>
		<category><![CDATA[eventdispatcher]]></category>
		<category><![CDATA[listeners]]></category>
		<category><![CDATA[private static]]></category>
		<category><![CDATA[wide]]></category>

		<guid isPermaLink="false">http://www.firstrowria.com/?p=544</guid>
		<description><![CDATA[Sometimes you need the ability to send events &#8220;through&#8221; the entire application. This can be useful, especially when you have a module-based architecture. 
Imagine following situation: Multiple modules, one of them is periodically checking some server state. If this module detects an important change, maybe the user has logged out on the server side, or [...]]]></description>
			<content:encoded><![CDATA[<p>Sometimes you need the ability to send events &#8220;through&#8221; the entire application. This can be useful, especially when you have a module-based architecture. </p>
<p><u>Imagine following situation:</u> Multiple modules, one of them is periodically checking some server state. If this module detects an important change, maybe the user has logged out on the server side, or whatever, the other modules need to know about that change. So we need a component that broadcasts this change and anybody who is interested in that change listens for it. The change is broadcasted via <a href="http://livedocs.adobe.com/flash/9.0_de/ActionScriptLangRefV3/flash/events/Event.html">Flash-Events</a> and for the broadcasting itself, there is already the <a href="http://livedocs.adobe.com/flash/9.0_de/ActionScriptLangRefV3/flash/events/EventDispatcher.html">EventDispatcher</a>. So the idea is to build a class that is simply holding a private static instance of an EventDispatcher and provides a dispatchEvent and addEventListener function, just like the EventDispatcher itself does.<br/></p>
<div class="code-box">
package com.firstrowria<br />
{<br />
&nbsp;&nbsp;&nbsp;&nbsp;import flash.events.Event;<br />
&nbsp;&nbsp;&nbsp;&nbsp;import flash.events.EventDispatcher;</p>
<p>&nbsp;&nbsp;&nbsp;&nbsp;public class GlobalEventBroadcaster<br />
&nbsp;&nbsp;&nbsp;&nbsp;{</p>
<p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;private static var dispatcher:EventDispatcher = new EventDispatcher();</p>
<p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;public static function addEventListener(type:String, listener:Function, useCapture:Boolean = false, priority:int = 0, useWeakReference:Boolean = false):void<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;{<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;dispatcher.addEventListener(type, listener, useCapture, priority, useWeakReference);<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}</p>
<p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;public static function removeEventListener(type:String, listener:Function, useCapture:Boolean = false):void<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;{<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;if (dispatcher)<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;dispatcher.removeEventListener(type, listener, useCapture);<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}</p>
<p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;public static function dispatchEvent(event:Event):void<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;{<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;if (dispatcher)<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;dispatcher.dispatchEvent(event);<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}</p>
<p>&nbsp;&nbsp;&nbsp;&nbsp;}<br />
}
</p></div>
<p>That&#8217;s it, dispatch and listen to your own Events as you need it. Since this is a very simple approach there is a lot of space for improvements. <u>Just a few ideas:</u></p>
<ul>
<li>Channel support. Could be a huge improvement when you have a lot of listeners already</li>
<li>Store the current listeners in an array so the removement of all listeners at once for a specific event is possible</li>
<li>Check if there are listeners for a specific event, if not, do not dispatch the Event since this is <a href="http://www.gskinner.com/blog/archives/2008/12/making_dispatch.html">ridiculous slow</a> and totally useless</li>
<li>Remove the possibility for weak references in the addEventListener function. More info on this topic? <a href="http://joeberkovitz.com/blog/2007/06/20/moment-of-weakness-weak-event-listeners-can-be-dangerous/">See Joe Berkovitz&#8217;s blog entry why weak references can be dangerous</a></li>
</ul>
]]></content:encoded>
			<wfw:commentRss>http://flash.firstrowria.com/2010/05/as3-application-wide-event-broadcasting/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>[AS3] Introducing the OddFormatter class</title>
		<link>http://flash.firstrowria.com/2010/01/as3-introducing-the-oddformatter-class/</link>
		<comments>http://flash.firstrowria.com/2010/01/as3-introducing-the-oddformatter-class/#comments</comments>
		<pubDate>Thu, 28 Jan 2010 19:27:19 +0000</pubDate>
		<dc:creator>Bernd</dc:creator>
				<category><![CDATA[AS3]]></category>
		<category><![CDATA[american]]></category>
		<category><![CDATA[bet]]></category>
		<category><![CDATA[betting]]></category>
		<category><![CDATA[bookmaker]]></category>
		<category><![CDATA[british]]></category>
		<category><![CDATA[decimal]]></category>
		<category><![CDATA[european]]></category>
		<category><![CDATA[format]]></category>
		<category><![CDATA[formatter]]></category>
		<category><![CDATA[fraction]]></category>
		<category><![CDATA[odd]]></category>
		<category><![CDATA[odds]]></category>
		<category><![CDATA[term]]></category>

		<guid isPermaLink="false">http://www.firstrowria.com/?p=515</guid>
		<description><![CDATA[If you need a formatter that supports the European, British and even American odd format, have a look at the following piece of code. If you have no idea about the different formats you might check the Odd Article on Wikipedia first.
Please note that for the UK format, the odd is always converted to the [...]]]></description>
			<content:encoded><![CDATA[<p>If you need a formatter that supports the European, British and even American odd format, have a look at the following piece of code. If you have no idea about the different formats you might check the <a href="http://en.wikipedia.org/wiki/Odds#Decimal_presentation">Odd Article on Wikipedia</a> first.</p>
<p>Please note that for the UK format, the odd is always converted to the lowest possible term. Wikipedia says that 3/2 is usually represented as 6/4, 10/3 is 100/30, but I&#8217;m pretty sure that this is not commonly used, at least for the online bookmakers where the odds are automatically converted in the different formats.</p>
<p>You can also download the source <a href="/wp-content/stuff/oddformatter/OddFormatter.as">here</a>.</p>
<p>As usual, this code is free, use it wherever you want <img src='http://flash.firstrowria.com/wp-includes/images/smilies/icon_wink.gif' alt=';)' class='wp-smiley' /> <br/></p>
<div class="code-box">
package com.firstrowria.formatters<br />
{<br />
&nbsp;&nbsp;&nbsp;public class OddFormatter<br />
&nbsp;&nbsp;&nbsp;{<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;public static const EU_FORMAT:uint = 0;<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;public static const US_FORMAT:uint = 1;<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;public static const UK_FORMAT:uint = 2;<br/><br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;public static function format(v:Number, f:uint = 0, c:String = &#8220;,&#8221;, p:int = 2):String<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;{<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;var formattedValue:String = &#8220;&#8221;;<br/><br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;if (f == UK_FORMAT)<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;{<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;var hundretValue:Number = Math.round(v * 100) &#8211; 100;<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;var ggt:int = ggt(hundretValue, 100);<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;formattedValue = (hundretValue / ggt) + &#8220;/&#8221; + (100 / ggt);<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;else if (f == US_FORMAT)<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;{<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;if (v >= 2)<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;formattedValue = &#8220;+&#8221; + Math.round(100 * (v &#8211; 1));<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;else if (v == 1)<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;formattedValue = &#8220;-0&#8243;;<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;else<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;formattedValue = &#8220;&#8221; + Math.round(100 / (1 &#8211; v));<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;else if (f == EU_FORMAT)<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;{<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;formattedValue = v.toFixed(p)<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;if (c != &#8220;.&#8221;)<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;formattedValue = formattedValue.replace(&#8221;.&#8221;, c);<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}<br/><br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;return formattedValue;<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}<br/><br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;private static function ggt(u:int, v:int):int<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;{<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;return ((u > 0) ? ggt(v % u, u) : v);<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}<br />
&nbsp;&nbsp;&nbsp;}<br />
}</p>
</div>
]]></content:encoded>
			<wfw:commentRss>http://flash.firstrowria.com/2010/01/as3-introducing-the-oddformatter-class/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>[AS3] Precise Timer approach #1</title>
		<link>http://flash.firstrowria.com/2009/09/as3-precise-timer-approach-1/</link>
		<comments>http://flash.firstrowria.com/2009/09/as3-precise-timer-approach-1/#comments</comments>
		<pubDate>Thu, 24 Sep 2009 12:00:08 +0000</pubDate>
		<dc:creator>Bernd</dc:creator>
				<category><![CDATA[AS3]]></category>
		<category><![CDATA[accurate]]></category>
		<category><![CDATA[flash]]></category>
		<category><![CDATA[precise]]></category>
		<category><![CDATA[timer]]></category>

		<guid isPermaLink="false">http://www.firstrowria.com/?p=488</guid>
		<description><![CDATA[If you need to implement a ordinary countdown in your Flex/AIR or plain Flash application there is no way around the Flash built in Timer (flash.utils.Timer, since 9.0). Unfortunately this Timer isn&#8217;t accurate, not even close. Even worse, the longer it runs, the more it will be off time. Traced out the first 20 seconds [...]]]></description>
			<content:encoded><![CDATA[<p>If you need to implement a ordinary countdown in your Flex/AIR or plain Flash application there is no way around the Flash built in Timer (flash.utils.Timer, since 9.0). Unfortunately this Timer isn&#8217;t accurate, not even close. Even worse, the longer it runs, the more it will be off time. Traced out the first 20 seconds of a simple Timer which fires every 1000ms, we are 1800ms off!</p>
<div class="code-box">
1001<br />
2110<br />
3262<br />
4340<br />
5583<br />
6678<br />
7757<br />
8836<br />
9908<br />
10986<br />
12081<br />
13149<br />
14235<br />
15312<br />
16383<br />
17460<br />
18543<br />
19633<br />
20712<br />
21837
</div>
<p>So I did some tests with setInterval, a hangover function from AS2, which lead me to the same result. Since I needed a timer that runs accurate my idea was to calculate the gap on every cycle and adjust the internal timer. Use it just like the normal Timer.</p>
<div class="code-box">
package<br />
{</p>
<p style="padding-left: 30px;">import flash.events.EventDispatcher;<br />
import flash.events.TimerEvent;<br />
import flash.utils.Timer;<br />
import flash.utils.getTimer;<br />
<br/><br />
public class PreciseTimer extends EventDispatcher<br />
{</p>
<p style="padding-left: 60px;">private const INSPECT_TIME:int = 100;<br />
<br/><br />
private var _timer:Timer;<br />
private var _startTime:int = 0;<br />
<br/><br />
private var _delay:int = 0;<br />
private var _repeatCount:int = 0;<br />
private var _continueForever:Boolean;<br />
<br/><br />
public function PreciseTimer(delay:int, repeatCount:int)<br />
{</p>
<p style="padding-left: 90px;">_delay = delay;<br />
_repeatCount = repeatCount;<br />
_continueForever = repeatCount <= 0;<br />
init();</p>
<p style="padding-left: 60px;">}</p>
<p><br/></p>
<p style="padding-left: 60px;">private function init():void<br />
{</p>
<p style="padding-left: 90px;">_timer = new Timer(INSPECT_TIME, 0);<br />
_timer.addEventListener(TimerEvent.TIMER, onTimer);</p>
<p style="padding-left: 60px;">}<br />
<br/><br />
public function start():void<br />
{</p>
<p style="padding-left: 90px;">_startTime = getTimer();<br />
_timer.start();</p>
<p style="padding-left: 60px;">}<br />
<br/><br />
public function stop():void<br />
{</p>
<p style="padding-left: 90px;">_timer.stop();</p>
<p style="padding-left: 60px;">}<br />
<br/><br />
private function onTimer(event:TimerEvent):void<br />
{</p>
<p style="padding-left: 90px;">var timer:int = getTimer();<br />
var durations:int = timer &#8211; _startTime;<br />
<br/><br />
if (durations > _delay)<br />
{</p>
<p style="padding-left: 120px;">if (_continueForever)<br />
{</p>
<p style="padding-left: 150px;">dispatchEvent(new TimerEvent(TimerEvent.TIMER));</p>
<p style="padding-left: 120px;">}<br />
else if (_repeatCount <b>-</b><b>-</b> == 1)<br />
{</p>
<p style="padding-left: 150px;">stop();<br />
dispatchEvent(new TimerEvent(TimerEvent.TIMER));<br />
dispatchEvent(new TimerEvent(TimerEvent.TIMER_COMPLETE));</p>
<p style="padding-left: 120px;">}<br />
else<br />
{</p>
<p style="padding-left: 150px;">dispatchEvent(new TimerEvent(TimerEvent.TIMER));</p>
<p style="padding-left: 120px;">}<br />
<br/><br />
_startTime = timer &#8211; ((durations &#8211; _delay))</p>
<p style="padding-left: 90px;">}</p>
<p style="padding-left: 60px;">}</p>
<p style="padding-left: 30px;">}</p>
<p>}
</p></div>
<p>So far, so good, here are the figures. For my purposes, this is close enough!</p>
<div class="code-box">
1093<br />
2044<br />
3069<br />
4003<br />
5025<br />
6077<br />
7044<br />
8054<br />
9002<br />
10070<br />
11116<br />
12022<br />
13040<br />
14084<br />
15003<br />
16046<br />
17049<br />
18094<br />
19020<br />
20056
</div>
]]></content:encoded>
			<wfw:commentRss>http://flash.firstrowria.com/2009/09/as3-precise-timer-approach-1/feed/</wfw:commentRss>
		<slash:comments>5</slash:comments>
		</item>
		<item>
		<title>[AS3] Let&#8217;s LOOP FOR a WHILE, a short performance comparison over loops in Actionscript 3</title>
		<link>http://flash.firstrowria.com/2009/07/as3-lets-loop-for-a-while-a-short-performance-comparison-over-loops-in-actionscript-3/</link>
		<comments>http://flash.firstrowria.com/2009/07/as3-lets-loop-for-a-while-a-short-performance-comparison-over-loops-in-actionscript-3/#comments</comments>
		<pubDate>Wed, 22 Jul 2009 22:40:36 +0000</pubDate>
		<dc:creator>Bernd</dc:creator>
				<category><![CDATA[AS3]]></category>
		<category><![CDATA[comparison]]></category>
		<category><![CDATA[counter]]></category>
		<category><![CDATA[fast]]></category>
		<category><![CDATA[for]]></category>
		<category><![CDATA[int]]></category>
		<category><![CDATA[iterations]]></category>
		<category><![CDATA[Joa Ebert]]></category>
		<category><![CDATA[loop]]></category>
		<category><![CDATA[Number]]></category>
		<category><![CDATA[performance]]></category>
		<category><![CDATA[slow]]></category>
		<category><![CDATA[uint]]></category>
		<category><![CDATA[while]]></category>

		<guid isPermaLink="false">http://www.firstrowria.com/?p=444</guid>
		<description><![CDATA[Months ago someone pointed me at Joa Ebert&#8217;s wiki, which has a interesting category: Code Optimization. In this post I want to test some performance statements made in the loop article
I tested for and while loops with different data types (uint and int, Number is 4-5 times slower) and counting mechanisms (i++ or ++i), with [...]]]></description>
			<content:encoded><![CDATA[<p>Months ago someone pointed me at <a href="http://wiki.joa-ebert.com/">Joa Ebert&#8217;s wiki</a>, which has a interesting category: <a href="http://wiki.joa-ebert.com/index.php/Category:Code_Optimization">Code Optimization</a>. In this post I want to test some performance statements made in the <a href="http://wiki.joa-ebert.com/index.php/Loops">loop article</a></p>
<p>I tested for and while loops with different data types (uint and int, <b>Number is 4-5 times slower</b>) and counting mechanisms (i++ or ++i), with and without accessing the counter variable. All loops had 268435455 (int.MAX_VALUE/8) iterations on my tripple core 2,1Ghz machine, 32bit WinXP, Flash player 10. The y-axis shows us the average time in milliseconds of at least 10 iterations. The highest and lowest value is not included.</p>
<p><a href="http://flash.firstrowria.com/wp-content/uploads/2009/07/loopcomparison_1.png"><img src="http://flash.firstrowria.com/wp-content/uploads/2009/07/loopcomparison_1.png" alt="AS3 Loop comparison" title="AS3 Loop comparison" width="646" height="365" class="alignleft size-full wp-image-445" /></a></p>
<p>We can see that for is faster than while. Why? Well .. I just don&#8217;t know, if you have any idea, please leave a comment!</p>
<p>So the fasted two loops, nearly head to head, were:</p>
<div class="code-box">
//for uint i++<br />
private function f1():void<br />
{</p>
<p style="padding-left: 30px;">var i:int = 0;</p>
<p style="padding-left: 30px;">var n:int = int.MAX_VALUE/8;</p>
<p style="padding-left: 30px;">for( i = 0; i < n; i++ ) { }</p>
<p>}
</p></div>
<div class="code-box">
//for int ++i<br />
private function f3():void<br />
{</p>
<p style="padding-left: 30px;">var i:int = 0;</p>
<p style="padding-left: 30px;">var n:int = int.MAX_VALUE/8;</p>
<p style="padding-left: 30px;">for( i = 0; i < n; ++i ) { }</p>
<p>}
</p></div>
<h3>&nbsp;</h3>
<p>Then I took a closer look on the for loops. Why is the ordinary loop with int as data type and i++ value increase slower?</p>
<p><a href="http://flash.firstrowria.com/wp-content/uploads/2009/07/diagramm2.png"><img src="http://flash.firstrowria.com/wp-content/uploads/2009/07/diagramm2.png" alt="AS3 for loops" title="AS3 for loops" width="645" height="285" class="alignleft size-full wp-image-447" /></a></p>
<h2>&nbsp;</h2>
<p>What if the loop body is not empty and the value of the counter is needed? Well, here are the results. At this time 17895697 (int.MAX_VALUE/120) were enough.</p>
<p><a href="http://flash.firstrowria.com/wp-content/uploads/2009/07/diagramm3.png"><img src="http://flash.firstrowria.com/wp-content/uploads/2009/07/diagramm3.png" alt="AS3 for loops with access to counter var" title="AS3 for loops with access to counter var" width="656" height="368" class="alignleft size-full wp-image-458" /></a></p>
<p>Ok, now we are nearly at the same level, regardless of which data type or counting style is used. The only (negative) abnormality is the uint while, which is about 9% slower than the fastest loop. </p>
<p>Here we have the slow performer:</p>
<div class="code-box">
//while uint &#8211;n<br />
private function f8():void<br />
{</p>
<p style="padding-left: 30px;">var i:uint = 0;</p>
<p style="padding-left: 30px;">var n:uint = int.MAX_VALUE/120;</p>
<p style="padding-left: 30px;">while( &#8211;n >= i )</p>
<p style="padding-left: 30px;">{</p>
<p style="padding-left: 60px;">n;</p>
<p style="padding-left: 30px;">}</p>
<p>}
</p></div>
<h3>&nbsp;</h3>
<p><b>Conclusion:</b> It&#8217;s totally up to you which loop you prefer (if you have to access the counter variable). For me I will continue to use the ordinary for loop, just like I ever did.</p>
<h3>&nbsp;</h3>
]]></content:encoded>
			<wfw:commentRss>http://flash.firstrowria.com/2009/07/as3-lets-loop-for-a-while-a-short-performance-comparison-over-loops-in-actionscript-3/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>[Flex] Top 5 memory leaks in Flex, #5: </title>
		<link>http://flash.firstrowria.com/2009/03/flex-top-5-memory-leaks-in-flex-5/</link>
		<comments>http://flash.firstrowria.com/2009/03/flex-top-5-memory-leaks-in-flex-5/#comments</comments>
		<pubDate>Fri, 13 Mar 2009 10:23:30 +0000</pubDate>
		<dc:creator>Bernd</dc:creator>
				<category><![CDATA[Flex]]></category>
		<category><![CDATA[AddChild]]></category>
		<category><![CDATA[DeferredInstanceFromClass]]></category>
		<category><![CDATA[DeferredInstanceFromFunction]]></category>
		<category><![CDATA[garbage collector]]></category>
		<category><![CDATA[IDeferredInstance]]></category>
		<category><![CDATA[instance]]></category>
		<category><![CDATA[memory leak]]></category>
		<category><![CDATA[mx:AddChild]]></category>
		<category><![CDATA[private]]></category>

		<guid isPermaLink="false">http://www.firstrowria.com/?p=250</guid>
		<description><![CDATA[Issue: When using states in mxml, components that have been added with the &#60;mx:AddChild&#62; tag, can not be cleanly removed and therefore they stuck in memory
Tested version: Flex Milestone 3.2
Workaround: Unfortunately there is none. Either you do not use States any more or you compile your own Flex-SDK and fix the classes DeferredInstanceFromFunction and DeferredInstanceFromClass, [...]]]></description>
			<content:encoded><![CDATA[<p><strong>Issue:</strong> When using states in mxml, components that have been added with the &lt;mx:AddChild&gt; tag, can not be cleanly removed and therefore they stuck in memory</p>
<p><strong>Tested version:</strong> Flex Milestone 3.2</p>
<p><strong>Workaround: </strong>Unfortunately there is none. Either you do not use States any more or you compile your own Flex-SDK and fix the classes DeferredInstanceFromFunction and DeferredInstanceFromClass, which holds instances of your added component, even when the corresponding state is not active any more. Another possibility would be to create your own AddChild class that does not use the DeferredInstance classes, see Nick Bilyk&#8217;s blog post: <a href="http://www.nbilyk.com/flex-states-memory-leak" target="_blank">Flex states retaining memory</a></p>
<p><strong>Note:</strong> These is the (shortened) source code of DeferredInstanceFromClass (nearly same source in DeferredInstanceFromFunction), where I&#8217;ve highlighted the retained reference to the instance that has been created. I have no idea why they store the instance in a private variable, must be some performance intentions.</p>
<div class="code-box">
<p>package mx.core<br />
{</p>
<p style="padding-left: 30px;">public class DeferredInstanceFromClass implements IDeferredInstance<br />
{</p>
<p style="padding-left: 60px;">[..]</p>
<p style="padding-left: 60px;">private var instance:Object = null;</p>
<p style="padding-left: 60px;">/**<br />
*    Creates and returns an instance of the class specified in the<br />
*  DeferredInstanceFromClass constructor, if it does not yet exist;<br />
*  otherwise, returns the already-created class instance.<br />
*<br />
*  @return An instance of the class specified in the<br />
*  DeferredInstanceFromClass constructor.<br />
*/</p>
<p style="padding-left: 60px;">public function getInstance():Object<br />
{</p>
<p style="padding-left: 90px;"><span style="color: #c43a3a;"><strong>if (!instance)<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;instance = new generator();</strong></span></p>
<p style="padding-left: 90px;">//this should be: return new generator();<br />
return instance;</p>
<p style="padding-left: 60px;">}</p>
<p style="padding-left: 30px;">}</p>
<p>}</p></div>
]]></content:encoded>
			<wfw:commentRss>http://flash.firstrowria.com/2009/03/flex-top-5-memory-leaks-in-flex-5/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>[Flex] Top 5 memory leaks in Flex, #4: effects</title>
		<link>http://flash.firstrowria.com/2009/02/flex-top-5-memory-leaks-in-flex-4-effects/</link>
		<comments>http://flash.firstrowria.com/2009/02/flex-top-5-memory-leaks-in-flex-4-effects/#comments</comments>
		<pubDate>Mon, 23 Feb 2009 17:01:23 +0000</pubDate>
		<dc:creator>Bernd</dc:creator>
				<category><![CDATA[Flex]]></category>
		<category><![CDATA[garbage collector]]></category>
		<category><![CDATA[memory leak]]></category>
		<category><![CDATA[running effects]]></category>

		<guid isPermaLink="false">http://www.firstrowria.com/?p=4</guid>
		<description><![CDATA[Issue: Running effects prevent components from being garbage collected
Tested version: Flex Milestone 3.2
Workaround: Call end()-method of effect before removing the component.
Note: This example consists of 2 files and extends the example from the previous post by a simple effect. The main application (nothing changed here), seen in the first box, adds the self made-component from [...]]]></description>
			<content:encoded><![CDATA[<p><strong>Issue:</strong> Running effects prevent components from being garbage collected</p>
<p><strong>Tested version:</strong> Flex Milestone 3.2</p>
<p><strong>Workaround:</strong> Call end()-method of effect before removing the component.</p>
<p><strong>Note:</strong> This example consists of 2 files and extends the example from the previous post by a simple effect. The main application (nothing changed here), seen in the first box, adds the self made-component from box 2. It uses a move effect, that restarts automatically and a timer to demonstrate how this combination could lead to memory leaks. Like in the previous blog post, <span style="text-decoration: underline;">it is also necessary to nullify the component</span> after removing it from the display list, otherwise it will remain in memory, even when listeners are correctly removed and effects are not running any more!</p>
<div class="code-box">&lt;?xml version=&#8221;1.0&#8243; encoding=&#8221;utf-8&#8243;?&gt;<br />
&lt;mx:Application xmlns:mx=&#8221;http://www.adobe.com/2006/mxml&#8221; layout=&#8221;absolute&#8221; width=&#8221;150&#8243; height=&#8221;150&#8243; xmlns:local=&#8221;*&#8221;&gt;</p>
<p style="padding-left: 30px;">&lt;mx:Script&gt;<br />
&lt;![CDATA[</p>
<p style="padding-left: 60px;">private function remove():void<br />
{</p>
<p style="padding-left: 90px;">myComponent.destroy();<br />
removeChild(myComponent);</p>
<p style="padding-left: 90px;">//IF NOT NULLIFIED, then no garbage collection!!!<br />
myComponent = null;</p>
<p style="padding-left: 60px;">}</p>
<p style="padding-left: 30px;">]]&gt;<br />
&lt;/mx:Script&gt;</p>
<p style="padding-left: 30px;">&lt;mx:Button label=&#8221;Remove component&#8221; click=&#8221;remove()&#8221; /&gt;</p>
<p style="padding-left: 30px;">&lt;local:MyComponent id=&#8221;myComponent&#8221; y=&#8221;50&#8243; /&gt;</p>
<p>&lt;/mx:Application&gt;</p></div>
<div class="code-box">package<br />
{</p>
<p style="padding-left: 30px;">import flash.events.TimerEvent;<br />
import flash.utils.Timer;<br />
import mx.controls.Label;<br />
import mx.core.UIComponent;<br />
import mx.effects.Move;<br />
import mx.events.EffectEvent;</p>
<p style="padding-left: 30px;">public class MyComponent extends UIComponent<br />
{</p>
<p style="padding-left: 60px;">private var myTimer:Timer;<br />
private var myMoveEffect:Move;<br />
private var label:Label;<br />
private var i:uint = 0;</p>
<p style="padding-left: 60px;">public function MyComponent()<br />
{</p>
<p style="padding-left: 90px;">label = new Label();<br />
label.setActualSize(100,20);<br />
addChild(label);</p>
<p style="padding-left: 90px;">myTimer = new Timer(100,999);<br />
myTimer.addEventListener(TimerEvent.TIMER, onTimer);<br />
myTimer.start();</p>
<p style="padding-left: 90px;">myMoveEffect = new Move();<br />
myMoveEffect.addEventListener(EffectEvent.EFFECT_END, onEffectEnd);<br />
myMoveEffect.duration = 3000;<br />
myMoveEffect.xBy = 100;<br />
myMoveEffect.play([label]);</p>
<p style="padding-left: 60px;">}</p>
<p style="padding-left: 60px;">private function onTimer(event:TimerEvent):void<br />
{</p>
<p style="padding-left: 90px;">i++;<br />
label.text = i.toString();</p>
<p style="padding-left: 60px;">}</p>
<p style="padding-left: 60px;">private function onEffectEnd(event:EffectEvent):void<br />
{</p>
<div style="padding-left: 90px;">if (myMoveEffect.xBy &gt; 0)</div>
<div style="padding-left: 110px;">myMoveEffect.xBy = -100;</div>
<div style="padding-left: 90px;">else</div>
<div style="padding-left: 110px;">myMoveEffect.xBy = 100;</div>
<div>&nbsp;</div>
<div style="padding-left: 90px;">myMoveEffect.play([label]);</div>
<p style="padding-left: 60px;">}</p>
<p style="padding-left: 60px;">public function destroy():void<br />
{</p>
<p style="padding-left: 90px;">if (myTimer)<br />
{</p>
<p style="padding-left: 120px;">myTimer.removeEventListener(TimerEvent.TIMER, onTimer);<br />
myTimer.stop();</p>
<p style="padding-left: 90px;">}</p>
<p style="padding-left: 90px;">if (myMoveEffect)<br />
{</p>
<p style="padding-left: 120px;">myMoveEffect.removeEventListener(EffectEvent.EFFECT_END, onEffectEnd);<br />
myMoveEffect.end();</p>
<p style="padding-left: 90px;">}</p>
<p style="padding-left: 60px;">}</p>
<p style="padding-left: 30px;">}</p>
<p>}</p></div>
]]></content:encoded>
			<wfw:commentRss>http://flash.firstrowria.com/2009/02/flex-top-5-memory-leaks-in-flex-4-effects/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>[Flex] Top 5 memory leaks in Flex, #3: event listeners</title>
		<link>http://flash.firstrowria.com/2009/02/flex-top-5-memory-leaks-in-flex-3-event-listeners/</link>
		<comments>http://flash.firstrowria.com/2009/02/flex-top-5-memory-leaks-in-flex-3-event-listeners/#comments</comments>
		<pubDate>Fri, 06 Feb 2009 23:33:00 +0000</pubDate>
		<dc:creator>Bernd</dc:creator>
				<category><![CDATA[Flex]]></category>
		<category><![CDATA[event listener]]></category>
		<category><![CDATA[garbage collector]]></category>
		<category><![CDATA[memory leak]]></category>
		<category><![CDATA[weak references]]></category>

		<guid isPermaLink="false">http://www.firstrowria.com/?p=5</guid>
		<description><![CDATA[Issue: Open listeners prevent components from being garbage collected
Tested version: Flex Milestone 3.2
Workaround: Add and remove listeners by yourself. Implement somekind of destroy-function, that clears all listeners. Other possibility is to use weak references when adding listeners. For further information see this blog post from Ted Patrick: useWeakReferences:Boolean = false
Note: This example consists of 2 [...]]]></description>
			<content:encoded><![CDATA[<p><strong>Issue:</strong> Open listeners prevent components from being garbage collected</p>
<p><strong>Tested version:</strong> Flex Milestone 3.2</p>
<p><strong>Workaround:</strong> Add and remove listeners by yourself. Implement somekind of destroy-function, that clears all listeners. Other possibility is to use weak references when adding listeners. For further information see this blog post from Ted Patrick: <a href="http://www.onflex.org/ted/2008/09/useweakreferencesboolean-false.php">useWeakReferences:Boolean = false</a></p>
<p><strong>Note:</strong> This example consists of 2 files. The main application, seen in the first box, adds the self made-component from box 2. It uses a timer to demonstrate listener functionality. If the timer is still running, it is stopped and the event listener is removed manually. <span style="text-decoration: underline;">It is also necessary to nullify the component</span> after removing it from the display list, otherwise it will remain in memory, even when listeners are removed correctly!</p>
<div class="code-box">&lt;?xml version=&#8221;1.0&#8243; encoding=&#8221;utf-8&#8243;?&gt;</p>
<p>&lt;mx:Application xmlns:mx=&#8221;http://www.adobe.com/2006/mxml&#8221; layout=&#8221;absolute&#8221; width=&#8221;150&#8243; height=&#8221;150&#8243; xmlns:local=&#8221;*&#8221;&gt;</p>
<p style="padding-left: 30px;">&lt;mx:Script&gt;<br />
&lt;![CDATA[</p>
<p style="padding-left: 60px;">private function remove():void<br />
{</p>
<p style="padding-left: 90px;">myComponent.destroy();<br />
removeChild(myComponent);</p>
<p style="padding-left: 90px;">//IF NOT NULLIFIED, then no garbage collection!!!<br />
myComponent = null;</p>
<p style="padding-left: 60px;">}</p>
<p style="padding-left: 30px;">]]&gt;<br />
&lt;/mx:Script&gt;</p>
<p style="padding-left: 30px;">&lt;mx:Button label=&#8221;Remove component&#8221; click=&#8221;remove()&#8221; /&gt;</p>
<p style="padding-left: 30px;">&lt;local:MyComponent id=&#8221;myComponent&#8221; y=&#8221;50&#8243; /&gt;</p>
<p>&lt;/mx:Application&gt;</p></div>
<div class="code-box">
package<br />
{</p>
<p style="padding-left: 30px;">import flash.events.TimerEvent;<br />
import flash.utils.Timer;<br />
import mx.controls.Label;<br />
import mx.core.UIComponent;</p>
<p style="padding-left: 30px;">public class MyComponent extends UIComponent<br />
{</p>
<p style="padding-left: 60px;">private var myTimer:Timer;<br />
private var label:Label;<br />
private var i:uint = 0;</p>
<p style="padding-left: 60px;">public function MyComponent()<br />
{</p>
<p style="padding-left: 90px;">label = new Label();<br />
label.setActualSize(100,20);<br />
addChild(label);</p>
<p style="padding-left: 90px;">myTimer = new Timer(100,999);<br />
myTimer.addEventListener(TimerEvent.TIMER, onTimer);<br />
myTimer.start();</p>
<p style="padding-left: 60px;">}</p>
<p style="padding-left: 60px;">private function onTimer(event:TimerEvent):void<br />
{</p>
<p style="padding-left: 90px;">i++;<br />
label.text = i.toString();</p>
<p style="padding-left: 60px;">}</p>
<p style="padding-left: 60px;">public function destroy():void<br />
{</p>
<p style="padding-left: 90px;">if (myTimer)<br />
{</p>
<p style="padding-left: 120px;">myTimer.removeEventListener(TimerEvent.TIMER, onTimer);<br />
myTimer.stop();</p>
<p style="padding-left: 90px;">}</p>
<p style="padding-left: 60px;">}</p>
<p style="padding-left: 30px;">}</p>
<p>}</p></div>
]]></content:encoded>
			<wfw:commentRss>http://flash.firstrowria.com/2009/02/flex-top-5-memory-leaks-in-flex-3-event-listeners/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>[Flex] Top 5 memory leaks in Flex, #2: skinning of components, e.g Button</title>
		<link>http://flash.firstrowria.com/2009/01/flex-top-5-memory-leaks-in-flex-2-skinning-of-components-eg-button/</link>
		<comments>http://flash.firstrowria.com/2009/01/flex-top-5-memory-leaks-in-flex-2-skinning-of-components-eg-button/#comments</comments>
		<pubDate>Wed, 07 Jan 2009 19:59:33 +0000</pubDate>
		<dc:creator>Bernd</dc:creator>
				<category><![CDATA[Flex]]></category>
		<category><![CDATA[garbage collector]]></category>
		<category><![CDATA[memory leak]]></category>
		<category><![CDATA[skins]]></category>
		<category><![CDATA[style]]></category>

		<guid isPermaLink="false">http://www.firstrowria.com/?p=6</guid>
		<description><![CDATA[Issue: Embed skins does not get removed and stays in memory
Tested version: Flex Milestone 3.2
Workaround: Clear the style by yourself by setting the styleName property to null
Note: See the example how to clear the style exactly. Download the style swf here to get this application working. This probably works with every skinable component. Be aware [...]]]></description>
			<content:encoded><![CDATA[<p><strong>Issue:</strong> Embed skins does not get removed and stays in memory</p>
<p><strong>Tested version:</strong> Flex Milestone 3.2</p>
<p><strong>Workaround:</strong> Clear the style by yourself by setting the styleName property to null</p>
<p><strong>Note:</strong> See the example how to clear the style exactly. <a href="/wp-content/stuff/button.swf">Download the style swf here</a> to get this application working. This probably works with every skinable component. <del datetime="2009-08-20T22:59:55+00:00">Be aware that every skin you define in css has to be cleaned</del> You can clean all skins at once with styleName=&#8221;null&#8221;</p>
<div class="code-box">&lt;?xml version=&#8221;1.0&#8243; encoding=&#8221;utf-8&#8243;?&gt;</p>
<p>&lt;mx:Application xmlns:mx=&#8221;http://www.adobe.com/2006/mxml&#8221; layout=&#8221;absolute&#8221; width=&#8221;150&#8243; height=&#8221;150&#8243;&gt;</p>
<p style="padding-left: 30px;">&lt;mx:Script&gt;<br />
&lt;![CDATA[</p>
<p style="padding-left: 60px;">private function remove():void<br />
{</p>
<p style="padding-left: 90px;">/*<br />
myButton.setStyle("overSkin", null);<br />
myButton.setStyle("upSkin", null);<br />
myButton.setStyle("downSkin", null);<br />
*/
</p>
<p style="padding-left: 90px;">
//better and faster version than above<br />
myButton.styleName = null;
</p>
<p style="padding-left: 90px;">
removeChild(myButton);</p>
<p style="padding-left: 60px;">}</p>
<p style="padding-left: 30px;">]]&gt;<br />
&lt;/mx:Script&gt;</p>
<p style="padding-left: 30px;">&lt;mx:Style&gt;</p>
<p style="padding-left: 60px;">.myButton<br />
{</p>
<p style="padding-left: 90px;">over-skin:Embed(source=&#8221;button.swf&#8221;, symbol=&#8221;buttonover&#8221;);<br />
up-skin:Embed(source=&#8221;button.swf&#8221;, symbol=&#8221;buttonup&#8221;);<br />
down-skin:Embed(source=&#8221;button.swf&#8221;, symbol=&#8221;buttondown&#8221;);</p>
<p style="padding-left: 60px;">}</p>
<p style="padding-left: 30px;">&lt;/mx:Style&gt;</p>
<p style="padding-left: 30px;">&lt;mx:Button label=&#8221;Remove button&#8221; click=&#8221;remove()&#8221; /&gt;</p>
<p style="padding-left: 30px;">&lt;mx:Button id=&#8221;myButton&#8221; y=&#8221;50&#8243; styleName=&#8221;myButton&#8221;/&gt;</p>
<p>&lt;/mx:Application&gt;</p></div>
]]></content:encoded>
			<wfw:commentRss>http://flash.firstrowria.com/2009/01/flex-top-5-memory-leaks-in-flex-2-skinning-of-components-eg-button/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
		<item>
		<title>[Flex] Top 5 memory leaks in Flex, #1: background-image in containers</title>
		<link>http://flash.firstrowria.com/2009/01/flex-top-5-memory-leaks-in-flex-1-background-image-in-containers/</link>
		<comments>http://flash.firstrowria.com/2009/01/flex-top-5-memory-leaks-in-flex-1-background-image-in-containers/#comments</comments>
		<pubDate>Wed, 07 Jan 2009 18:11:09 +0000</pubDate>
		<dc:creator>Bernd</dc:creator>
				<category><![CDATA[Flex]]></category>
		<category><![CDATA[background image]]></category>
		<category><![CDATA[CodeBehind]]></category>
		<category><![CDATA[container]]></category>
		<category><![CDATA[flex builder profiler]]></category>
		<category><![CDATA[garbage collector]]></category>
		<category><![CDATA[lightweight]]></category>
		<category><![CDATA[memory leak]]></category>
		<category><![CDATA[UIComponent]]></category>

		<guid isPermaLink="false">http://www.firstrowria.com/?p=7</guid>
		<description><![CDATA[I know, I&#8217;ve been lazy in blogging in the last months, but this is changing now. I was involved in a huge Flex3 project (not allowed to name it right now). The size of the application made it impossible to develop in a classical way, so the team decided the following points:

Build a own lightweight [...]]]></description>
			<content:encoded><![CDATA[<p>I know, I&#8217;ve been lazy in blogging in the last months, but this is changing now. I was involved in a huge Flex3 project (not allowed to name it right now). The size of the application made it impossible to develop in a classical way, so the team decided the following points:</p>
<ul>
<li>Build a own lightweight framework that fits our needs in widget handling</li>
<li><a href="http://livedocs.adobe.com/flex/3/html/help.html?content=ascomponents_advanced_3.html">Build components from scratch by extenting UIComponent and handle the life-cycle by ourselfs</a></li>
<li>Do not use flex components if not necessary, this also includes containers, e.g. boxes</li>
<li><a href="http://www.mxml.it/index.php/2008/09/09/introduction-to-mvp-for-flex/">Use MVP Pattern</a></li>
<li><a href="http://learn.adobe.com/wiki/display/Flex/Code+Behind">CodeBehind Classes for enabling inheritance in MXML<br />
</a></li>
</ul>
<p>and in general:</p>
<ul>
<li>Save performance wherever possible</li>
<li>Save memory wherever possible</li>
</ul>
<p>In the end stage of the project we had to deal with several memory leaks, so we started to investigate in this topic. With help of the Flex Builder Profiler (<a href="http://blogs.adobe.com/aharui/profiler/ProfilerScenarios.swf">see this link how to use the profile</a>) we could identify the leaks and solve most of them. This and following posts point out the top 5 memory leaks, starting with the most common leak we had.</p>
<h3>&nbsp;</h3>
<h3>background-image in containers</h3>
<h6>&nbsp;</h6>
<p><strong>Issue:</strong> Background image stays in memory after removing container from display list</p>
<p><strong>Tested version:</strong> Flex Milestone 3.2</p>
<p><strong>Workaround:</strong> Clear the style by yourself</p>
<p><strong>Note:</strong> See the example how to clear the style exactly. Choose any background image you like. This also works with every container not just Canvas, e.g HBox, VBox,..</p>
<p><strong>Adobe Bug:</strong> <a href="https://bugs.adobe.com/jira/browse/SDK-1893">SDK-1893</a></p>
<div class="code-box">&lt;?xml version=&#8221;1.0&#8243; encoding=&#8221;utf-8&#8243;?&gt;</p>
<p>&lt;mx:Application xmlns:mx=&#8221;http://www.adobe.com/2006/mxml&#8221; layout=&#8221;absolute&#8221; width=&#8221;400&#8243; height=&#8221;350&#8243; &gt;</p>
<p style="padding-left: 30px;"><span style="white-space: pre;"> </span>&lt;mx:Script&gt;<br />
&lt;![CDATA[</p>
<p style="padding-left: 60px;"><span style="white-space: pre;"> </span>private function remove():void<br />
{</p>
<p style="padding-left: 90px;">//has no effect<br />
//myCanvas.clearStyle("background-image");<br />
//myCanvas.clearStyle("backroundImage");<br />
//myCanvas.setStyle("background-image",null);</p>
<p style="padding-left: 90px;"><span style="white-space: pre;"> </span>//works<br />
myCanvas.setStyle("backgroundImage",null);<br />
removeChild(myCanvas);</p>
<p style="padding-left: 60px;"><span style="white-space: pre;"> </span>}</p>
<p style="padding-left: 30px;">]]&gt;<br />
&lt;/mx:Script&gt;</p>
<p style="padding-left: 30px;">&lt;mx:Style&gt;</p>
<p style="padding-left: 60px;">.myCanvas<br />
{</p>
<p style="padding-left: 90px;">background-image: Embed(source=&#8221;bgImage.jpg&#8221;);</p>
<p style="padding-left: 60px;">}</p>
<p style="padding-left: 30px;">&lt;/mx:Style&gt;</p>
<p style="padding-left: 30px;">&lt;mx:Button label=&#8221;Remove canvas&#8221; click=&#8221;remove()&#8221; /&gt;</p>
<p style="padding-left: 30px;">&lt;mx:Canvas id=&#8221;myCanvas&#8221; width=&#8221;400&#8243; height=&#8221;300&#8243; y=&#8221;50&#8243;  styleName=&#8221;myCanvas&#8221; horizontalScrollPolicy=&#8221;off&#8221; verticalScrollPolicy=&#8221;off&#8221; /&gt;</p>
<p>&lt;/mx:Application&gt;</p></div>
]]></content:encoded>
			<wfw:commentRss>http://flash.firstrowria.com/2009/01/flex-top-5-memory-leaks-in-flex-1-background-image-in-containers/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>[AS3] Accessing private/protected properties via wrapper or mx_internal</title>
		<link>http://flash.firstrowria.com/2008/08/as3-accessing-privateprotected-properties-via-wrapper-or-mx_internal/</link>
		<comments>http://flash.firstrowria.com/2008/08/as3-accessing-privateprotected-properties-via-wrapper-or-mx_internal/#comments</comments>
		<pubDate>Sun, 10 Aug 2008 20:29:26 +0000</pubDate>
		<dc:creator>Bernd</dc:creator>
				<category><![CDATA[AIR]]></category>
		<category><![CDATA[AS3]]></category>
		<category><![CDATA[Flex]]></category>
		<category><![CDATA[mx internal]]></category>
		<category><![CDATA[private]]></category>
		<category><![CDATA[protected]]></category>
		<category><![CDATA[wrapper]]></category>

		<guid isPermaLink="false">http://www.firstrowria.com/?p=8</guid>
		<description><![CDATA[Ever wanted to access a private or protected property of a class, for example the internal flash.text.TextField of an Label?
Since the textField is protected you have the option of extending the class and create a wrapper class as seen in the following lines:
package com.firstrowria.mxInternal
{
import mx.controls.Label;
import mx.core.IUITextField;
public class WrapperLabel extends Label
{
public function WrapperLabel()
{
super();
}
public function get internalTextField():IUITextField
{
return [...]]]></description>
			<content:encoded><![CDATA[<p>Ever wanted to access a private or protected property of a class, for example the internal flash.text.TextField of an Label?</p>
<p>Since the textField is protected you have the option of extending the class and create a wrapper class as seen in the following lines:</p>
<div class="code-box">package com.firstrowria.mxInternal<br />
{</p>
<p style="padding-left: 30px;">import mx.controls.Label;<br />
import mx.core.IUITextField;</p>
<p style="padding-left: 30px;">public class WrapperLabel extends Label<br />
{</p>
<p style="padding-left: 60px;">public function WrapperLabel()<br />
{</p>
<p style="padding-left: 90px;">super();</p>
<p style="padding-left: 60px;">}</p>
<p style="padding-left: 60px;">public function get internalTextField():IUITextField<br />
{</p>
<p style="padding-left: 90px;">return super.textField;</p>
<p style="padding-left: 60px;">}</p>
<p style="padding-left: 30px;">}</p>
<p>}</p></div>
<h3>&nbsp;</h3>
<p>But there is another method, the usage of an internal namespace mx_internal. The only requirement is that the function/property has to be marked. If you step through the source of the Label component you can see that the textField property itself is not in this namespace but there is a function getTextField which is.</p>
<p><img alt="" src="/wp-content/stuff/mx_internal.jpg" title="mx internal" class="alignnone" width="629" height="192" /></p>
<h6>&nbsp;</h6>
<p>This is an quick example, which demonstrates the things that need to be done:</p>
<div class="code-box">
<p>import mx.core.IUITextField;<br />
import mx.core.mx_internal;</p>
<p>use namespace mx_internal;</p>
<p>private function bla():void<br />
{</p>
<p style="padding-left: 30px;">var tf:IUITextField = myLabel.mx_internal::getTextField();</p>
<p>}</p></div>
<p>Make sure that you first do the import (it should also be the last one). Please note that there is no code hinting in Flex Builder when using this method of accessing functions/properties.</p>
]]></content:encoded>
			<wfw:commentRss>http://flash.firstrowria.com/2008/08/as3-accessing-privateprotected-properties-via-wrapper-or-mx_internal/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

