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

<channel>
	<title>.:. blog.screenshot.at .:. Flash, Flex, RIA .:.</title>
	<atom:link href="http://www.screenshot.at/blog/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.screenshot.at/blog</link>
	<description>This blog is about Flash, Flex, RIA related stuff</description>
	<pubDate>Sun, 01 Aug 2010 15:57:36 +0000</pubDate>
	<generator>http://wordpress.org/?v=abc</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>CMC Spreadbetting Application is now online</title>
		<link>http://www.screenshot.at/blog/2010/08/01/cmc-spreadbetting-application-is-now-online/</link>
		<comments>http://www.screenshot.at/blog/2010/08/01/cmc-spreadbetting-application-is-now-online/#comments</comments>
		<pubDate>Sun, 01 Aug 2010 15:50:29 +0000</pubDate>
		<dc:creator>Manfred Karrer</dc:creator>
		
		<category><![CDATA[Flash]]></category>

		<guid isPermaLink="false">http://www.screenshot.at/blog/?p=493</guid>
		<description><![CDATA[After quite a long time the project i have joined last November in now online:
http://www.cmcmarkets.co.uk
]]></description>
			<content:encoded><![CDATA[<p>After quite a long time the project i have joined last November in now online:</p>
<p><a href="http://www.cmcmarkets.co.uk" target="_blank">http://www.cmcmarkets.co.uk</a></p>
]]></content:encoded>
			<wfw:commentRss>http://www.screenshot.at/blog/2010/08/01/cmc-spreadbetting-application-is-now-online/feed/</wfw:commentRss>
		</item>
		<item>
		<title>Adobe whitepaper for performance optimization</title>
		<link>http://www.screenshot.at/blog/2010/02/15/adobe-whitepaper-for-performance-optimization/</link>
		<comments>http://www.screenshot.at/blog/2010/02/15/adobe-whitepaper-for-performance-optimization/#comments</comments>
		<pubDate>Mon, 15 Feb 2010 22:22:13 +0000</pubDate>
		<dc:creator>Manfred Karrer</dc:creator>
		
		<category><![CDATA[Actionscript]]></category>

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

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

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

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

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

		<category><![CDATA[garbage collector]]></category>

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

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

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

		<guid isPermaLink="false">http://www.screenshot.at/blog/?p=485</guid>
		<description><![CDATA[Thibault Imbert from Adobe has published a whitepaper for performance optimization, with a lot of useful information specially targeting Flash Player 10.1 and mobile content.
Some parts sounds somehow strange, like the recommendation to avoid Event Dispatching as for every event an object has to be created. On the other hand they recommend object pooling for [...]]]></description>
			<content:encoded><![CDATA[<p><a href="http://www.bytearray.org/" target="_blank">Thibault Imbert</a> from Adobe has published a <a href="http://help.adobe.com/en_US/as3/mobile/index.html" target="_blank">whitepaper</a> for performance optimization, with a lot of useful information specially targeting Flash Player 10.1 and mobile content.</p>
<p>Some parts sounds somehow strange, like the recommendation to avoid Event Dispatching as for every event an object has to be created. On the other hand they recommend object pooling for reusing objects. So the question pops up, why the native Event Dispatching is not implemented in the way that it benefits from a native object pooling? When performance optimization is leading to bad coding practice, something in the  technology seems to be wrong. The poor method execution performance in Flash is one of these issues.</p>
<p>Here just a few random issues discussed in the paper:</p>
<p>- Setting not used objects explicitely to null helps the garbage collector</p>
<p>- Call dispose() on the BitmapData object when not used anymore</p>
<p>- When using Filters 2 Bitmaps are created and kept in memory. Applying a filter is CPU intense, so try to use pre-rendered Bitmaps instead.</p>
<p>- Deactivate interactive objects when no Mouse interaction is needed (mouseEnabled, mouseChildren)</p>
<p>All in all it is good to see that Adobe is aware of the performance problems and hopefully will push the Flash Player forward using the optimization headroom available at the compiler level and the Flash Player itself. Maybe the current effort to make Flash &#8220;ready for mobile&#8221; will give us the same performance boost like with AS3 that was primarily introduced because of the greed of Flex which simply didn´t perform on the AVM1.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.screenshot.at/blog/2010/02/15/adobe-whitepaper-for-performance-optimization/feed/</wfw:commentRss>
		</item>
		<item>
		<title>A question of style</title>
		<link>http://www.screenshot.at/blog/2010/01/08/a-question-of-style/</link>
		<comments>http://www.screenshot.at/blog/2010/01/08/a-question-of-style/#comments</comments>
		<pubDate>Fri, 08 Jan 2010 00:03:02 +0000</pubDate>
		<dc:creator>Manfred Karrer</dc:creator>
		
		<category><![CDATA[Flex]]></category>

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

		<category><![CDATA[Add new tag]]></category>

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

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

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

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

		<guid isPermaLink="false">http://www.screenshot.at/blog/?p=454</guid>
		<description><![CDATA[If you ever had some strange problems with styles in Flex, you might want to know how styles are internally handled and implemented.
Ok this post will not cover too much of all the stuff going on there, but a bit of the basics how styles are finding their way from the css file to your [...]]]></description>
			<content:encoded><![CDATA[<p>If you ever had some strange problems with styles in Flex, you might want to know how styles are internally handled and implemented.<br />
Ok this post will not cover too much of all the stuff going on there, but a bit of the basics <span class="hl">how styles are finding their way</span> from the css file to your component.</p>
<p>Lets assume that we have a css file with type selectors and class selectors, a module based application and some custom components which are designed the way that you can use them out of the box and that they can be individually skinned and styled by other developers reusing them. That´s what custom components are for, right?</p>
<p>So the first question is:<br />
<span class="hl">How are the styles compiled into your swf file?</span><br />
Assume that they are defined in an external css file. You know you can compile css files to swf files and load them at runtime or simply compile them into your application at compile time with a simple assignment  like this:</p>
<pre>
<div class="codesnip-container" >
<div class="codesnip" style="font-family: monospace;">&nbsp;</div>
</div>
</pre>
<p>Here is the content of our simple css:</p>
<pre>
<div class="codesnip-container" >
<div class="codesnip" style="font-family: monospace;">Button
<span class="br0">&#123;</span>
&nbsp; &nbsp; &nbsp; &nbsp; <span class="kw7">color</span>: #<span class="nu0">990000</span>;
<span class="br0">&#125;</span>
.myCustomStyle1
<span class="br0">&#123;</span>
&nbsp; &nbsp; &nbsp; &nbsp; <span class="kw7">color</span>: #<span class="nu0">009900</span>;
<span class="br0">&#125;</span>
&nbsp;<span class="coMULTI">/*
&nbsp; &nbsp; &nbsp;some additional styles here...
&nbsp; &nbsp; &nbsp;like Button.myCustomStyle2
*/</span></div>
</div>
</pre>
<p>That´s what we will use for our example here.</p>
<p>In this case the MXML compiler creates a bunch of classes and inserts the css definitions right into a method called from the constructor in the generated Applications class.</p>
<pre>
<div class="codesnip-container" >
<div class="codesnip" style="font-family: monospace;"><span class="kw1">public</span> <span class="kw3">function</span> StyleExample<span class="br0">&#40;</span><span class="br0">&#41;</span> <span class="br0">&#123;</span>
&nbsp; &nbsp; &nbsp; &nbsp; mx_internal::_StyleExample_StylesInit<span class="br0">&#40;</span><span class="br0">&#41;</span>;
<span class="br0">&#125;</span>
mx_internal <span class="kw3">function</span> _StyleExample_StylesInit<span class="br0">&#40;</span><span class="br0">&#41;</span>:<span class="kw1">void</span> <span class="br0">&#123;</span>
&nbsp; &nbsp; &nbsp; &nbsp; <span class="kw2">var</span> style:CSSStyleDeclaration;
&nbsp; &nbsp; &nbsp; &nbsp; <span class="co1">// Button</span>
&nbsp; &nbsp; &nbsp; &nbsp; style = StyleManager.getStyleDeclaration<span class="br0">&#40;</span><span class="st0">&quot;Button&quot;</span><span class="br0">&#41;</span>;
&nbsp; &nbsp; &nbsp; &nbsp; <span class="kw1">if</span> <span class="br0">&#40;</span>!style<span class="br0">&#41;</span> <span class="br0">&#123;</span>
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; style = <span class="kw1">new</span> CSSStyleDeclaration<span class="br0">&#40;</span><span class="br0">&#41;</span>;
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; StyleManager.setStyleDeclaration<span class="br0">&#40;</span><span class="st0">&quot;Button&quot;</span>, style, <span class="kw1">false</span><span class="br0">&#41;</span>;
&nbsp; &nbsp; &nbsp; &nbsp; <span class="br0">&#125;</span>
&nbsp; &nbsp; &nbsp; &nbsp; <span class="kw1">if</span> <span class="br0">&#40;</span>style.factory == <span class="kw1">null</span><span class="br0">&#41;</span> <span class="br0">&#123;</span>
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; style.factory = <span class="kw3">function</span><span class="br0">&#40;</span><span class="br0">&#41;</span>:<span class="kw1">void</span> <span class="br0">&#123;</span>
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="kw1">this</span>.<span class="kw7">color</span> = 0x990000;
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="br0">&#125;</span>;
&nbsp; &nbsp; &nbsp; &nbsp; <span class="br0">&#125;</span>
&nbsp; &nbsp; &nbsp; &nbsp; <span class="co1">// myCustomStyle1</span>
&nbsp; &nbsp; &nbsp; &nbsp; style = StyleManager.getStyleDeclaration<span class="br0">&#40;</span><span class="st0">&quot;.myCustomStyle1&quot;</span><span class="br0">&#41;</span>;
&nbsp; &nbsp; &nbsp; &nbsp; <span class="kw1">if</span> <span class="br0">&#40;</span>!style<span class="br0">&#41;</span>
&nbsp; &nbsp; &nbsp; &nbsp; <span class="br0">&#123;</span>
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; style = <span class="kw1">new</span> CSSStyleDeclaration<span class="br0">&#40;</span><span class="br0">&#41;</span>;
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; StyleManager.setStyleDeclaration<span class="br0">&#40;</span><span class="st0">&quot;.myCustomStyle1&quot;</span>,
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;style, <span class="kw1">false</span><span class="br0">&#41;</span>;
&nbsp; &nbsp; &nbsp; &nbsp; <span class="br0">&#125;</span>
&nbsp; &nbsp; &nbsp; &nbsp; <span class="kw1">if</span> <span class="br0">&#40;</span>style.factory == <span class="kw1">null</span><span class="br0">&#41;</span>
&nbsp; &nbsp; &nbsp; &nbsp; <span class="br0">&#123;</span>
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; style.factory = <span class="kw3">function</span><span class="br0">&#40;</span><span class="br0">&#41;</span>:<span class="kw1">void</span>
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="br0">&#123;</span>
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="kw1">this</span>.<span class="kw7">color</span> = 0x009900;
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="br0">&#125;</span>;
&nbsp; &nbsp; &nbsp; &nbsp; <span class="br0">&#125;</span>
&nbsp; &nbsp; &nbsp; &nbsp; <span class="co1">// similar code follows here....</span>
<span class="br0">&#125;</span></div>
</div>
</pre>
<p>I only pasted the relevant code, so this is not complete but should give the basic idea.<br />
So what happens here?<br />
<span id="more-454"></span><br />
A CSSStyleDeclaration is created for the given stylename or class if it´s not already existing in the StyleManager (at a modular application some other application could have already created this style). Then the definitions from the css file (here the color property) are added to the factory function.<br />
It is interesting that the class selectors and type selectors are treated the same way regarding storing the style object in the StyleManager. It is simply the selector name which is used as the key in the _selectors Object (hashtable). Only the &#8220;.&#8221; in the selector name is the visible difference.</p>
<pre>
<div class="codesnip-container" >
<div class="codesnip" style="font-family: monospace;"><span class="kw1">public</span> <span class="kw3">function</span> setStyleDeclaration<span class="br0">&#40;</span>
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; selector:<a href="http://www.google.com/search?q=String%20inurl:http://livedocs.adobe.com/flex/201/langref/%20inurl:String.html&#038;filter=0&#038;num=100&#038;btnI=lucky"><span class="kw5">String</span></a>,
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; styleDeclaration:CSSStyleDeclaration,
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; update:<a href="http://www.google.com/search?q=Boolean%20inurl:http://livedocs.adobe.com/flex/201/langref/%20inurl:Boolean.html&#038;filter=0&#038;num=100&#038;btnI=lucky"><span class="kw5">Boolean</span></a><span class="br0">&#41;</span>:<span class="kw1">void</span>
&nbsp; &nbsp; <span class="br0">&#123;</span>
&nbsp; &nbsp; &nbsp; &nbsp; styleDeclaration.selectorRefCount++;

&nbsp; &nbsp; &nbsp; &nbsp; _selectors<span class="br0">&#91;</span>selector<span class="br0">&#93;</span> = styleDeclaration;

&nbsp; &nbsp; &nbsp; &nbsp; <span class="co1">// Flush cache and start over.</span>
&nbsp; &nbsp; &nbsp; &nbsp; typeSelectorCache = <span class="br0">&#123;</span><span class="br0">&#125;</span>;

&nbsp; &nbsp; &nbsp; &nbsp; <span class="kw1">if</span> <span class="br0">&#40;</span>update<span class="br0">&#41;</span>
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; styleDeclarationsChanged<span class="br0">&#40;</span><span class="br0">&#41;</span>;
&nbsp; &nbsp; <span class="br0">&#125;</span></div>
</div>
</pre>
<p>The CSSStyleDeclaration has also a defaultFactory which is used if there is no factory defined (no css file). Additionally there is an overrides Object which is used to store styles set at runtime vial setStyle(), but this will not be further considered yet.<br />
This leads us to the next part:<br />
<span class="hl">How should a default style be applied to a custom component?</span></p>
<p>How Flex is handling this? The MXML compiler generates a bunch of style classes:<br />
For instance a style class for the Button:</p>
<pre>
<div class="codesnip-container" >
<div class="codesnip" style="font-family: monospace;"><span class="kw1">public</span> <span class="kw4">class</span> _ButtonStyle
<span class="br0">&#123;</span>
&nbsp; &nbsp; <span class="kw1">public</span> static <span class="kw3">function</span> <span class="kw7">init</span><span class="br0">&#40;</span>fbs:IFlexModuleFactory<span class="br0">&#41;</span>:<span class="kw1">void</span>
&nbsp; &nbsp; <span class="br0">&#123;</span>
&nbsp; &nbsp; &nbsp; &nbsp; <span class="kw2">var</span> style:CSSStyleDeclaration =
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;StyleManager.getStyleDeclaration<span class="br0">&#40;</span><span class="st0">&quot;Button&quot;</span><span class="br0">&#41;</span>;
&nbsp; &nbsp; &nbsp; &nbsp; <span class="kw1">if</span> <span class="br0">&#40;</span>!style<span class="br0">&#41;</span>
&nbsp; &nbsp; &nbsp; &nbsp; <span class="br0">&#123;</span>
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; style = <span class="kw1">new</span> CSSStyleDeclaration<span class="br0">&#40;</span><span class="br0">&#41;</span>;
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; StyleManager.setStyleDeclaration<span class="br0">&#40;</span><span class="st0">&quot;Button&quot;</span>, style, <span class="kw1">false</span><span class="br0">&#41;</span>;
&nbsp; &nbsp; &nbsp; &nbsp; <span class="br0">&#125;</span>
&nbsp; &nbsp; &nbsp; &nbsp; <span class="kw1">if</span> <span class="br0">&#40;</span>style.defaultFactory == <span class="kw1">null</span><span class="br0">&#41;</span>
&nbsp; &nbsp; &nbsp; &nbsp; <span class="br0">&#123;</span>
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; style.defaultFactory = <span class="kw3">function</span><span class="br0">&#40;</span><span class="br0">&#41;</span>:<span class="kw1">void</span>
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="br0">&#123;</span>
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="kw1">this</span>.fontWeight = <span class="st0">&quot;bold&quot;</span>;
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="kw1">this</span>.paddingTop = <span class="nu0">2</span>;
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="kw1">this</span>.cornerRadius = <span class="nu0">4</span>;
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="kw1">this</span>.textAlign = <span class="st0">&quot;center&quot;</span>;
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="kw1">this</span>.verticalGap = <span class="nu0">2</span>;
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="kw1">this</span>.horizontalGap = <span class="nu0">2</span>;
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="kw1">this</span>.skin = mx.skins.halo.ButtonSkin;
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="kw1">this</span>.paddingLeft = <span class="nu0">10</span>;
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="kw1">this</span>.paddingBottom = <span class="nu0">2</span>;
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="kw1">this</span>.paddingRight = <span class="nu0">10</span>;
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="br0">&#125;</span>;
&nbsp; &nbsp; &nbsp; &nbsp; <span class="br0">&#125;</span>
&nbsp; &nbsp; <span class="br0">&#125;</span>
<span class="br0">&#125;</span></div>
</div>
</pre>
<p>This class is added to the mixins array at the generated _StyleExample_mx_managers_SystemManager class.<br />
The <span class="hl">mixins</span> are a strategy to get injected some code at application startup before anything else is instantiated. It calls the static init method, so it is executed before the actual classes constructor is called.<br />
A similar strategy with a static initializer is used in some classes in the datavisualisation package to pack some default styles into a component, so that there is no dependency that there are some styles assigned to the component from outside.<br />
That´s seems to be a pretty nice way to setup the default style a component needs. If the user of the component wants to set some different styles, it can be applied easily via css, styles set in mxml or at runtime via setStyle (if possible, this should be done in the preInitialize phase to avoid performance penalties).</p>
<p>One thing which should be considered when using styles (specially in a large application with modules) is the fact that the style declarations are stored with the selector name as key in an Object (hashtable). So if 2 developers are using the <span class="hl">same selector name</span> they end up with a conflict that the later instantiated module will use the already created style and not the one which was compiled to the module.<br />
The same applies if you use the same stylename inside one application, the first one used wins.<br />
To get rid of this problem a kind of namespace strategy can be used ([modulename] + &#8220;stylename&#8221;). Unfortunately the Flex framework does not give any support for this problem.<br />
Tell me if you know a more elegant solution!</p>
<div id="gmBFtt" style="border: 1px solid black ! important; margin: 0px ! important; padding: 2px ! important; background: #a8ecff none repeat scroll 0% 0% ! important; font-family: arial ! important; font-size: 12px ! important; color: #000000 ! important; line-height: normal ! important; font-weight: normal ! important; vertical-align: middle ! important; left: 194px ! important; top: 1926px ! important; visibility: visible ! important; display: inline ! important; width: auto; height: auto ! important; position: absolute ! important; text-align: left ! important; z-index: 1410065406 ! important;">
<div style="border-bottom: 1px dotted black ! important; background: #a8ecff none repeat scroll 0% 0% ! important; font-family: arial ! important; font-size: 12px ! important; color: #000000 ! important; line-height: normal ! important; font-weight: normal ! important; vertical-align: middle ! important; padding-bottom: 2px ! important; padding-top: 2px ! important;"><span id="bfconfigButton" style="border: 1px dotted gray ! important; margin: 1px ! important; padding: 0px 2px ! important; background: #a8ecff none repeat scroll 0% 0% ! important; font-family: arial ! important; font-size: 12px ! important; color: #000000 ! important; line-height: normal ! important; font-weight: normal ! important; vertical-align: middle ! important; cursor: pointer ! important;" title="Language configuration">Lang</span><span id="bfdetectButton" style="border: 1px dotted gray ! important; margin: 1px ! important; padding: 0px 2px ! important; background: #a8ecff none repeat scroll 0% 0% ! important; font-family: arial ! important; font-size: 12px ! important; color: #000000 ! important; line-height: normal ! important; font-weight: normal ! important; vertical-align: middle ! important; cursor: pointer;" title="Detect and set language">Detect</span><span id="bflangsSpan" style="border: 1px dotted gray ! important; margin: 1px ! important; padding: 0px 2px ! important; background: #a8ecff none repeat scroll 0% 0% ! important; font-family: arial ! important; font-size: 12px ! important; color: #000000 ! important; line-height: normal ! important; font-weight: normal ! important; vertical-align: middle ! important; cursor: pointer ! important;" title="From English To German (switch direction)">en&gt;de </span><span id="bfsvcSpan" style="border: 1px dotted gray ! important; margin: 1px ! important; padding: 0px 2px ! important; background: #a8ecff none repeat scroll 0% 0% ! important; font-family: arial ! important; font-size: 12px ! important; color: #000000 ! important; line-height: normal ! important; font-weight: normal ! important; vertical-align: middle ! important; cursor: pointer ! important;" title="Translation service: Yahoo (switch service)">Yahoo</span><span id="bfclipboardSpan" style="border: 1px dotted gray ! important; margin: 1px ! important; padding: 0px 2px ! important; background: #a8ecff none repeat scroll 0% 0% ! important; font-family: arial ! important; font-size: 12px ! important; color: #000000 ! important; line-height: normal ! important; font-weight: normal ! important; vertical-align: middle ! important; cursor: copy ! important;" title="Copy result to clipboard">C</span><img id="bffishImg" style="border: medium none  ! important; margin: 0px ! important; float: none ! important; vertical-align: top ! important; cursor: pointer ! important; display: inline ! important;" title="Click to translate" src="data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABwAAAAOCAYAAAA8E3wEAAAABmJLR0QA/wD/AP+gvaeTAAAACXBIWXMAAAsTAAALEwEAmpwYAAAAB3RJTUUH1QUUDyoqJjAqRwAAAN1JREFUOMu1lMkVwyAMBYe0JGpCNUFNVk3k4AUwxPGS+ILxkzX8jyTH/Sfu9nrmJ3cXlnMASyWRPwd2d5XlHCBZn1BthcbRAdxTZQDI8k3mQzg11rhF+QZ9jdNOcQib6GFQYJYgCFucSRf6GsLU6wEY5yubTFqF2yq1vRwr3INXdQUWG+je1pELX4ED1wDyRAR0WfuAA9gloITyvsFMIMgYInYRqF6rO9Sqz9qkO5ilyo0o3YBwJ+6vrdQonxWUQllhXeHcb/wabMPkP2n81ocAIoLZrMqn/4y2RwP8DcQ+d6rT9ATiAAAAAElFTkSuQmCC" alt="" /></div>
<div style="background: #a8ecff none repeat scroll 0% 0% ! important; font-family: arial ! important; font-size: 12px ! important; color: #000000 ! important; line-height: normal ! important; font-weight: normal ! important; vertical-align: middle ! important; width: auto;">MXML</div>
</div>
]]></content:encoded>
			<wfw:commentRss>http://www.screenshot.at/blog/2010/01/08/a-question-of-style/feed/</wfw:commentRss>
		</item>
		<item>
		<title>MacBook anti-theft software and firewall</title>
		<link>http://www.screenshot.at/blog/2009/07/05/macbook-anti-theft-software-and-firewall/</link>
		<comments>http://www.screenshot.at/blog/2009/07/05/macbook-anti-theft-software-and-firewall/#comments</comments>
		<pubDate>Sun, 05 Jul 2009 10:12:40 +0000</pubDate>
		<dc:creator>Manfred Karrer</dc:creator>
		
		<category><![CDATA[Software]]></category>

		<category><![CDATA[Anti Theft]]></category>

		<category><![CDATA[Anti-theft software]]></category>

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

		<category><![CDATA[Firewall For Mac]]></category>

		<category><![CDATA[Firewall Mac]]></category>

		<category><![CDATA[Incoming Traffic]]></category>

		<category><![CDATA[little snitch]]></category>

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

		<category><![CDATA[Outgoing Connections]]></category>

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

		<category><![CDATA[Software Firewall]]></category>

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

		<guid isPermaLink="false">http://www.screenshot.at/blog/?p=399</guid>
		<description><![CDATA[I just found a promising anti-theft software for my brand new MacBook Pro: Undercover from orbicule.
It´s important to activate apples firmeware password protection to ensure that a harddrive reformatting or replacement will not allow booting up your mac without password.
An alternative firewall for mac to control outgoing connections from your apps and services is little snitch. Unfortunately apples [...]]]></description>
			<content:encoded><![CDATA[<p>I just found a promising anti-theft software for my brand new MacBook Pro: <a href="http://www.orbicule.com/undercover/" target="_blank">Undercover</a> from orbicule.</p>
<p>It´s important to activate apples <a href="http://support.apple.com/kb/HT1352" target="_blank">firmeware password protection</a> to ensure that a harddrive reformatting or replacement will not allow booting up your mac without password.</p>
<p>An alternative firewall for mac to control outgoing connections from your apps and services is <a href="http://www.obdev.at/products/littlesnitch/index.html" target="_blank">little snitch</a>. Unfortunately apples built in firewall only allows control for incoming traffic.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.screenshot.at/blog/2009/07/05/macbook-anti-theft-software-and-firewall/feed/</wfw:commentRss>
		</item>
		<item>
		<title>Open source project: LocalConnectionService</title>
		<link>http://www.screenshot.at/blog/2009/05/26/open-source-project-localconnectionservice/</link>
		<comments>http://www.screenshot.at/blog/2009/05/26/open-source-project-localconnectionservice/#comments</comments>
		<pubDate>Tue, 26 May 2009 21:02:08 +0000</pubDate>
		<dc:creator>Manfred Karrer</dc:creator>
		
		<category><![CDATA[Actionscript]]></category>

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

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

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

		<category><![CDATA[Open Source Project]]></category>

		<guid isPermaLink="false">http://www.screenshot.at/blog/?p=386</guid>
		<description><![CDATA[LocalConnection is a great feature in flash, but unfortunately it has some limitations and the API is somehow &#8220;suboptimal&#8221;.
Evan Gifford from Blitz has set up an open source project where the size limitations of 40 kb are bypassed and the project provides a nice API.
Resources:
http://labs.blitzagency.com/?p=650
http://code.google.com/p/flashlcs/
http://rockonflash.wordpress.com/2009/03/05/new-localconnection-api-rocks-and-its-os/
http://livedocs.adobe.com/flash/9.0/ActionScriptLangRefV3/flash/net/LocalConnection.html
]]></description>
			<content:encoded><![CDATA[<p><a href="http://livedocs.adobe.com/flash/9.0/ActionScriptLangRefV3/flash/net/LocalConnection.html" target="_blank">LocalConnection</a> is a great feature in flash, but unfortunately it has some limitations and the API is somehow &#8220;suboptimal&#8221;.<br />
Evan Gifford from <a href="http://blitzagency.com" target="_blank">Blitz</a> has set up an <a href="http://code.google.com/p/flashlcs/" target="_blank">open source</a> project where the size limitations of 40 kb are bypassed and the project provides a nice API.</p>
<p>Resources:<br />
<a href="http://labs.blitzagency.com/?p=650" target="_blank">http://labs.blitzagency.com/?p=650</a><br />
<a href="http://code.google.com/p/flashlcs/" target="_blank">http://code.google.com/p/flashlcs/</a><br />
<a href="http://rockonflash.wordpress.com/2009/03/05/new-localconnection-api-rocks-and-its-os/" target="_blank">http://rockonflash.wordpress.com/2009/03/05/new-localconnection-api-rocks-and-its-os/</a><br />
<a href="http://livedocs.adobe.com/flash/9.0/ActionScriptLangRefV3/flash/net/LocalConnection.html" target="_blank">http://livedocs.adobe.com/flash/9.0/ActionScriptLangRefV3/flash/net/LocalConnection.html</a></p>
]]></content:encoded>
			<wfw:commentRss>http://www.screenshot.at/blog/2009/05/26/open-source-project-localconnectionservice/feed/</wfw:commentRss>
		</item>
		<item>
		<title>Flash high CPU usage in idle state</title>
		<link>http://www.screenshot.at/blog/2009/05/10/flash-high-cpu-usage-in-idle-state/</link>
		<comments>http://www.screenshot.at/blog/2009/05/10/flash-high-cpu-usage-in-idle-state/#comments</comments>
		<pubDate>Sun, 10 May 2009 20:24:55 +0000</pubDate>
		<dc:creator>Manfred Karrer</dc:creator>
		
		<category><![CDATA[Actionscript]]></category>

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

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

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

		<category><![CDATA[Bug Report]]></category>

		<category><![CDATA[Cpu Consumption]]></category>

		<category><![CDATA[Cpu Idle]]></category>

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

		<category><![CDATA[grant skinner]]></category>

		<category><![CDATA[High Cpu Usage]]></category>

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

		<category><![CDATA[Performance Problems]]></category>

		<category><![CDATA[Virtual Machine]]></category>

		<guid isPermaLink="false">http://www.screenshot.at/blog/?p=379</guid>
		<description><![CDATA[I have commited a bug report to Adobe about the high cpu usage in Flash applications at idle state.
Please vote for this bug, so it has higher chances to get fixed soon.
There is also another bug report by Grant Skinner regarding the same issue.
Here is a copy of the bug report (if you are too [...]]]></description>
			<content:encoded><![CDATA[<p>I have commited a <a href="http://bugs.adobe.com/jira/browse/FP-1149" target="_blank">bug report</a> to Adobe about the high cpu usage in Flash applications at idle state.</p>
<p>Please <a href="http://bugs.adobe.com/jira/browse/FP-1149" target="_blank">vote</a> for this bug, so it has higher chances to get fixed soon.</p>
<p>There is also <a href="http://bugs.adobe.com/jira/browse/FP-2009" target="_blank">another bug report</a> by <a href="http://www.gskinner.com/blog/archives/2009/05/idle_cpu_usage.html" target="_blank">Grant Skinner</a> regarding the same issue.</p>
<p>Here is a copy of the bug report (if you are too lazy to register @ Adobe <img src='http://www.screenshot.at/blog/wp-includes/images/smilies/icon_wink.gif' alt=';-)' class='wp-smiley' /> ).<br />
<span id="more-379"></span><br />
Steps to reproduce:<br />
1. create a hight number (&gt;1000) of displayobjects and add them to the stage (visible area)<br />
2. set the framerate to a hight value (&gt;50)<br />
3. move the mouse over the stage and don´t move it (idle state)</p>
<p>Actual Results:<br />
idle cpu usage (taskmanager) is quite high (&gt;10%) depending on the framerate, cpu and number of displayobjects</p>
<p>Expected Results:<br />
in idle state there should be nearly no cpu consumption (in AS2 -&gt; AVM1 it was quite low)</p>
<p>Workaround (if any):<br />
reduce the framerate, set mouseEnable and mouseChildren to false whenever possible</p>
<p>Here is a detailed discription and testresults:</p>
<p>Problem:<br />
We are working on a huge flex application (170 000 lines of code) and run into some performance problems.<br />
We have set the framerate to 60 fps and the cpu consumption of the application was about 20% on a 3Ghz quadcore machine. there were no user interactivity and rendering going on.<br />
So we investigated the problem.<br />
After setting the framerate to 25 fps and setting the mouseEnable and mouseChildren property to false at the displayObjects where we don´t need mouse interactivity, we got an acceptable cpu consumption in the idle state. I am still wondering for the reasons for this behavior and specially for the different behavior in comparison to the old virtual machine (AS2). A strange observation was also that when moving the mouse over a textField the cpu consumption goes down to 0%.</p>
<p>Test situation:<br />
I Create 2000 displayObjects and add them on the stage (visible area). I give the flashplayer (standalone flashplayer 10.0.r12, release version) the focus and put the mouse over the playerwindow. I don´t move the mouse and there is no rendering going on. The cpu consumption is quite high depending on the framerate.<br />
The same test scenario with AS2 (AVM1) does not show such a high cpu consumption.</p>
<p>When I set mouseChildren at the stage to false the cpu consumtion goes down to 0%. Setting the mouseEnabled property at every Sprite to false has just a small effect on reducing cpu consumption. I tried it also with a container sprite in which all the 2000 sprites where added, setting the containers mouseChildren to false also reduced the cpu consumption radically. The same when I set mouseEnabled of the container AND of all Sprites to false but don´t set mouseChildren of the container to false. Setting mouseEnabled of all Sprites to false but not at the container has only a small effect. Seems like the flashplayer recognize if no children has mouseEnabled set to true and then don´t need to traverse throught the displaylist.<br />
For me it seems that the flashplayer has to check every frame for the mouseEnable properties and this consumes resources. If mouseChildren is set to false it has not to go further up the displaylist, so this is much faster.<br />
Regarding the TextField: As long a the selected property is set tot true it reduces cpu consumption down to 0%. It seems that when moving the mouse over a selectable textField that the flashplayer don´t has to check any other displayObjects for mouse interactivity.</p>
<p>In the flex profiler I have seen an high growth of the consumed time by [reap] (98%) and Timer.tick (1%). ([reap] is an internal process: Flash Player reclaims DRC (deferred reference counting) objects.)</p>
<p>I am wondering which changes in the AVM2 has causes these problems and if there are options for optimizations. I am also wondering why there is no event based (like os interrupts) model possible, it seem that the flashplayer has to check every frame for possible os input (mouse move,&#8230;).<br />
I am also wondering if the strategy I have seen in the flex frameworks core classes to set the framerate up to 1000 fps for speeding up rendering and then reset it to the original framerate, could has negative side effects due these behavior.<br />
Could it be that it is related to the native support for the mouseWheel event passed from the os to the flashplayer? Because this was a change from the old virtual machine, where the mouseWheel where not passed to the player.</p>
<p>Test results:<br />
AS3 code (-&gt; AVM2)<br />
AS3: framerate 24:<br />
mouse over the stage: 3%<br />
mouse over the textField: 0%<br />
mouse over the one sprite: 3%<br />
mouse over the stack of 1000 sprites: 3%<br />
AS3: framerate 120:<br />
mouse over the stage: 9-14%<br />
mouse over the textField: 0%<br />
mouse over the one sprite: 10-13%<br />
mouse over the stack of 1000 sprites: 14-18%<br />
AS3: framerate 1000:<br />
mouse over the stage: 36-40%<br />
mouse over the textField: 0%<br />
mouse over the one sprite: 22-40%<br />
mouse over the stack of 1000 sprites: 17-33%</p>
<p>AS2 code (-&gt; AVM1)<br />
AS2: framerate 24:<br />
mouse over the stage: 0%<br />
mouse over the textField: 0%<br />
mouse over the one sprite: 0%<br />
mouse over the stack of 1000 sprites: 0%<br />
AS2: framerate 120:<br />
mouse over the stage: 6%<br />
mouse over the textField: 0%<br />
mouse over the one sprite: 6%<br />
mouse over the stack of 1000 sprites: 6%<br />
AS2: framerate 1000:<br />
mouse over the stage: 8%<br />
mouse over the textField: 0%<br />
mouse over the one sprite: 8%<br />
mouse over the stack of 1000 sprites: 8%</p>
<p>Environment:<br />
Flashplayer 10.0.r12 (release version)<br />
OS: Win XP pro SP2<br />
3Ghz Singlecore<br />
2 GB Ram</p>
<p>AS3 code:<br />
stage.frameRate = 1000;<br />
for(var i:uint = 0; i &lt; 2000; i++)<br />
{<br />
addChild(getSprite());<br />
}</p>
<p>var tf:TextField = new TextField();<br />
tf.x = 120;<br />
tf.width = tf.height = 100;<br />
tf.text = &#8220;test&#8221;;<br />
addChild(tf);</p>
<p>var s:Sprite = getSprite(0xFF0000);<br />
s.x = s.y = 120;<br />
addChild(s);</p>
<p>function getSprite(col:uint = 0&#215;00FF00):Sprite<br />
{<br />
var sprite:Sprite = new Sprite();<br />
with(sprite.graphics)<br />
{<br />
beginFill(col);<br />
drawRect(0, 0, 100, 100);<br />
endFill();<br />
}<br />
return sprite;<br />
}</p>
<p>AS2 code:<br />
this.frameRate = 1000;<br />
var i:Number;<br />
for(i = 0; i &lt; 2000; i++)<br />
{<br />
attachMovie(&#8221;mc&#8221;, &#8220;mc&#8221;+i, i);<br />
}</p>
<p>this.createTextField (&#8221;tf&#8221;, ++i, 120, 0, 100, 100);<br />
tf.text = &#8220;test&#8221;;</p>
<p>i++;<br />
var mc:MovieClip = attachMovie(&#8221;mc&#8221;, &#8220;mc&#8221;+i, i);;<br />
mc._x = mc._y = 120;</p>
<p>source file:<br />
<a href="http://bugs.adobe.com/jira/secure/attachment/27527/idleCpuTest.zip" target="_blank">http://bugs.adobe.com/jira/secure/attachment/27527/idleCpuTest.zip</a></p>
]]></content:encoded>
			<wfw:commentRss>http://www.screenshot.at/blog/2009/05/10/flash-high-cpu-usage-in-idle-state/feed/</wfw:commentRss>
		</item>
		<item>
		<title>Some nice tools and resources</title>
		<link>http://www.screenshot.at/blog/2009/05/09/some-nice-tools/</link>
		<comments>http://www.screenshot.at/blog/2009/05/09/some-nice-tools/#comments</comments>
		<pubDate>Sat, 09 May 2009 09:07:01 +0000</pubDate>
		<dc:creator>Manfred Karrer</dc:creator>
		
		<category><![CDATA[Actionscript]]></category>

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

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

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

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

		<category><![CDATA[Flex Builder]]></category>

		<category><![CDATA[CSS Inspector]]></category>

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

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

		<category><![CDATA[Free Libraries]]></category>

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

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

		<category><![CDATA[Open Source]]></category>

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

		<category><![CDATA[Security Analysis Tool]]></category>

		<category><![CDATA[Security Issues]]></category>

		<category><![CDATA[Security Tool]]></category>

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

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

		<guid isPermaLink="false">http://www.screenshot.at/blog/?p=362</guid>
		<description><![CDATA[My wishlist for a CSS inspector has had been already fulfilled: http://code.google.com/p/fxspy
A great code formatter as Eclipse plugin for Flex Builder: http://code.google.com/p/flexformatter
Download: http://sourceforge.net/projects/flexformatter/
HP has published a security analysis tool for Flash content. It´s also a decompiler to inspect the Actionscript code: SWFScan
Good overview about security issues in Flash:
http://www.owasp.org/index.php/Category:OWASP_Flash_Security_Project
http://www.adobe.com/devnet/flashplayer/articles/secure_swf_apps.html
A great resource for open source flash/flex tools [...]]]></description>
			<content:encoded><![CDATA[<p>My wishlist for a <a href="http://www.mieuxcoder.com/data/2007/12/FlexSpy-1.2/dashboard.html" target="_blank">CSS inspector</a> has had been already fulfilled: <a href="http://code.google.com/p/fxspy" target="_blank">http://code.google.com/p/fxspy</a></p>
<p>A great code formatter as Eclipse plugin for Flex Builder: <a href="http://code.google.com/p/flexformatter" target="_blank">http://code.google.com/p/flexformatter</a><br />
Download: <a href="http://sourceforge.net/projects/flexformatter/" target="_blank">http://sourceforge.net/projects/flexformatter/</a></p>
<p>HP has published a security analysis tool for Flash content. It´s also a decompiler to inspect the Actionscript code: <a href="https://h30406.www3.hp.com/campaigns/2009/wwcampaign/1-5TUVE/index.php?key=swf&amp;jumpid=go/swfscan" target="_blank">SWFScan</a></p>
<p>Good overview about security issues in Flash:<br />
<a href="http://www.owasp.org/index.php/Category:OWASP_Flash_Security_Project" target="_blank">http://www.owasp.org/index.php/Category:OWASP_Flash_Security_Project</a><br />
<a href="http://www.adobe.com/devnet/flashplayer/articles/secure_swf_apps.html" target="_blank">http://www.adobe.com/devnet/flashplayer/articles/secure_swf_apps.html</a></p>
<p>A great resource for open source flash/flex tools and projects: <a href="http://www.flashchemist.com/104-free-opensource-apis-libraries-and-tools-for-the-flash-platform.html" target="_blank">http://www.flashchemist.com/104-free-opensource-apis-libraries-and-tools-for-the-flash-platform.html</a></p>
]]></content:encoded>
			<wfw:commentRss>http://www.screenshot.at/blog/2009/05/09/some-nice-tools/feed/</wfw:commentRss>
		</item>
		<item>
		<title>The infamous callLater()</title>
		<link>http://www.screenshot.at/blog/2009/05/05/the-infamous-calllater/</link>
		<comments>http://www.screenshot.at/blog/2009/05/05/the-infamous-calllater/#comments</comments>
		<pubDate>Tue, 05 May 2009 23:03:24 +0000</pubDate>
		<dc:creator>Manfred Karrer</dc:creator>
		
		<category><![CDATA[Actionscript]]></category>

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

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

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

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

		<category><![CDATA[anatomy of a frame]]></category>

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

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

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

		<category><![CDATA[Half-Fram]]></category>

		<category><![CDATA[Layout Engine]]></category>

		<category><![CDATA[Layout Mechanism]]></category>

		<category><![CDATA[Life-Cycle]]></category>

		<category><![CDATA[Marshalled Slice]]></category>

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

		<category><![CDATA[Phased Instantiation]]></category>

		<category><![CDATA[player events]]></category>

		<category><![CDATA[player render]]></category>

		<category><![CDATA[prerender event]]></category>

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

		<category><![CDATA[Sean Christmann]]></category>

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

		<category><![CDATA[user code]]></category>

		<guid isPermaLink="false">http://www.screenshot.at/blog/?p=298</guid>
		<description><![CDATA[At my first posts I wrote about my favorite Flex feature: Databinding
Now I will take a look at the opposite, IMHO the most precarious &#8220;feature&#8221; in Flex: callLater()
If you have a dodgy problem that a certain property is not available when it already should be and you ask someone at flexcoders you often get the [...]]]></description>
			<content:encoded><![CDATA[<p>At my first posts I wrote about my favorite Flex feature: Databinding<br />
Now I will take a look at the opposite, IMHO the most precarious &#8220;feature&#8221; in Flex: <span class="hl">callLater()</span></p>
<p>If you have a dodgy problem that a certain property is not available when it already should be and you ask someone at <a href="http://tech.groups.yahoo.com/group/flexcoders/" target="_blank">flexcoders</a> you often get the advice, <em>&#8220;try callLater&#8221;</em> for a quick work-around. Sometimes this helps, but it leaves a bad smell, because often it´s just hiding some other problems in the code.<br />
So when we worked on a large-scale Flex application we have used it sometimes in the beginning, but after a while we decided to avoid callLater. To find and solve the real problem is simply the better solution - and we never needed it again - there was always another solution to solve a particular problem (maybe we just have had luck).</p>
<p>Unpleasantly we get confronted with the fact that callLater is used inside the Framework at the <strong>heart of the layout engine</strong>.<br />
We struggled with some strange problems. For instance we got a NullPointer exception in the updateDisplayList method of a custom component, which has already been cleaned up properly and removed from the displayList. It turned out that the layout mechanism delayed with callLater an invocation of updateDisplayList but our stuff there has already been removed and threw an exception.<br />
It was not hard to fix, but it demonstrated us that some asynchronous stuff was going on behind the scenes which was out of our direct control.</p>
<p>So for me callLater leaves always a certain bad smell.</p>
<p>Unfortunately I never found time to really investigate how it´s implemented and what are the concepts behind it.<br />
So it was time to <span class="hl">catch up</span> with this issue:<br />
CallLater is basically a method in UIComponent which delays a passed function to the next <strong>EnterFrame OR Render</strong> event.<br />
Often in den docs it´s just described that it will delay to the next frame, which is not correct because it could be that your function is executed already at the Render Event, which happens in the same frame and is the last opportunity where User code can be executed before the screen is rendered.</p>
<p>For more details about the internal concept of a frame in Flash and the relevant events see the great article by <a href="http://www.craftymind.com/2008/04/18/updated-elastic-racetrack-for-flash-9-and-avm2/" target="_blank">Sean Christmann</a>:</p>
<p>Here is a good illustration from his article about the <strong>anatomy of a frame</strong> in Flash:<br />
<span id="more-298"></span><br />
<img class="alignnone size-full wp-image-308" title="marshalledsliceexport" src="http://www.screenshot.at/blog/wp-content/uploads/2009/05/marshalledsliceexport.png" alt="marshalledsliceexport" width="500" height="220" /></p>
<p>All functions passed to callLater are queued up in an array and are executed at the EnterFrame event or Render event. It is possible that the executed function has some other callLater invocations again, so the final execution sequence could be delayed over several frames.</p>
<p>CallLater is used inside the Flex Framework in several classes. The main use case is probably inside the <strong>LayoutManager</strong>.<br />
There is a concept called <strong>phased instantiation</strong> which means basically that at application start-up the 3 phases in the UIComponents life-cycle (validate properties, validate size and validate displayList) are not executed in one pass, but are delayed with callLater to 3 half-frames. <strong>Half-frame</strong> because the Render event happens in the same frame as the EnterFrame event.<br />
This should reduce performance peaks at application-startup and should increase the UIs responsiveness.<br />
You can also use it later on in your application if you have to render heavy stuff, to balance the load across frames.</p>
<p><span class="hl">So far so good. But&#8230;</span><br />
First let me emphasis that I am sure that the SDK architects has had some good reasons for implementing callLater, but it <strong>introduces an asynchronism</strong> which could be hard to control. Normally with async stuff you have an event driven approach, so you get informed when the async task is done.<br />
With callLater it´s not so clear when the last callLater is really finished. There is an UpdateComplete event in UIComponent and LayoutManager which helps to get informed when the last callLater is executed, but in-between, you don´t have control about the distinct moments of your function calls.</p>
<p>Another issue is that you cannot control if your heavy load is really spread over 2 frames. It could be that it is just executed inside one frame at the EnterFrame event and at the Render event, so it could be that you don´t win anything from the load-balancing perspective.</p>
<p>Performance-wise there could also be perceptible delays caused by repeatedly callLater executions.</p>
<p>I guess there are many special situations in the framework code (probably mostly measurement stuff) which are difficult to handle, but i guess it <em>should</em> be possible (maybe I am too optimistic?).</p>
<p>There seems to be a problem to get the correct measurement when you set a new text in a TextField before the frame is actually rendered (see <a href="http://tech.groups.yahoo.com/group/flexcoders/message/121060" target="_blank"> this post</a> at flexcoders), but if this is an unsolvable problem then it should be urgently fixed in the Flash Player.</p>
<p>References@livedocs:<br />
<a href="http://livedocs.adobe.com/flex/3/langref/mx/core/UIComponent.html#callLater()" target="_blank">callLater()</a><br />
<a href="http://livedocs.adobe.com/flex/3/langref/mx/managers/LayoutManager.html#usePhasedInstantiation" target="_blank">usePhasedInstantiation</a></p>
]]></content:encoded>
			<wfw:commentRss>http://www.screenshot.at/blog/2009/05/05/the-infamous-calllater/feed/</wfw:commentRss>
		</item>
		<item>
		<title>Wishlist: CSS Inspector/Live-Editor for Flex</title>
		<link>http://www.screenshot.at/blog/2009/04/28/wishlist-css-inspectorlive-editor-for-flex/</link>
		<comments>http://www.screenshot.at/blog/2009/04/28/wishlist-css-inspectorlive-editor-for-flex/#comments</comments>
		<pubDate>Tue, 28 Apr 2009 20:11:54 +0000</pubDate>
		<dc:creator>Manfred Karrer</dc:creator>
		
		<category><![CDATA[Flash]]></category>

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

		<category><![CDATA[Flex Builder]]></category>

		<category><![CDATA[Adobe Bugbase]]></category>

		<category><![CDATA[Css Editor]]></category>

		<category><![CDATA[CSS Tools]]></category>

		<category><![CDATA[Custom Components]]></category>

		<category><![CDATA[Different Styles]]></category>

		<category><![CDATA[Download Adobe]]></category>

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

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

		<category><![CDATA[Flex Components]]></category>

		<category><![CDATA[Flex Style Exlorer]]></category>

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

		<category><![CDATA[Open Source]]></category>

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

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

		<category><![CDATA[Web Developer]]></category>

		<category><![CDATA[Web Developers]]></category>

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

		<guid isPermaLink="false">http://www.screenshot.at/blog/?p=271</guid>
		<description><![CDATA[At styling and changing my blog theme, i really fall in love with Web Developers (Firefox addon) CSS tools.
Just rollover or select an element and see the css used. Edit it live and see immediately the changes.
How nice would it be to have something inside Flex Builder?
For re-styling or adopting Flex projects this would be [...]]]></description>
			<content:encoded><![CDATA[<p>At styling and changing my blog theme, i really fall in love with Web Developers (<a href="https://addons.mozilla.org/de/firefox/addon/60" target="_blank">Firefox addon</a>) CSS tools.<br />
Just rollover or select an element and see the css used. Edit it live and see immediately the changes.<br />
How nice would it be to have something inside Flex Builder?<br />
For re-styling or adopting Flex projects this would be a great helper-tool, specially if you edit custom components from other developers.</p>
<p>If you feel this would be a nice feature, <a href="https://bugs.adobe.com/jira/browse/FB-19065" target="_blank">vote</a> for it on the <a href="https://bugs.adobe.com/jira/browse/FB-19065" target="_blank">Adobe Bugbase</a>.</p>
<p>You probably have seen already the <a href="http://examples.adobe.com/flex3/consulting/styleexplorer/Flex3StyleExplorer.html" target="_blank">Flex Style Explorer</a>. It gives a good overview of the different styles of the standard Flex components.</p>
<p>BTW: Did you know that parts of Flex Builder are open source (the derived stuff from Eclipse)? You can download it at <a href="http://kb.adobe.com/selfservice/viewContent.do?externalId=4b243413&amp;sliceId=1 " target="_blank">Adobe</a>.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.screenshot.at/blog/2009/04/28/wishlist-css-inspectorlive-editor-for-flex/feed/</wfw:commentRss>
		</item>
		<item>
		<title>DataBinding under the hood (part 3): Generated Code</title>
		<link>http://www.screenshot.at/blog/2009/04/26/databinding-under-the-hood-part3-generated-code/</link>
		<comments>http://www.screenshot.at/blog/2009/04/26/databinding-under-the-hood-part3-generated-code/#comments</comments>
		<pubDate>Sun, 26 Apr 2009 00:28:40 +0000</pubDate>
		<dc:creator>Manfred Karrer</dc:creator>
		
		<category><![CDATA[Actionscript]]></category>

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

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

		<category><![CDATA[compiler settings]]></category>

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

		<category><![CDATA[Flex Compiler]]></category>

		<category><![CDATA[Generated Code]]></category>

		<category><![CDATA[Mixin Classes]]></category>

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

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

		<guid isPermaLink="false">http://www.screenshot.at/blog/?p=230</guid>
		<description><![CDATA[So now lets get our hands dirty and check out the generated code which is created behind the scenes.
When you compile a Flex application the compiler runs the compilation in 2 steps:

The mxmlc compiler generates a lot of Actionscript classes
The compc compiler compiles from the generated classes plus your custom classes the swf file

These 2 [...]]]></description>
			<content:encoded><![CDATA[<p>So now lets get our hands dirty and check out the <span class="hl">generated code</span> which is created behind the scenes.</p>
<p>When you compile a Flex application the compiler runs the compilation in 2 steps:</p>
<ul>
<li>The mxmlc compiler generates a lot of Actionscript classes</li>
<li>The compc compiler compiles from the generated classes plus your custom classes the swf file</li>
</ul>
<p>These 2 steps are normally not visible, because the generated code is not stored in your project. If you add the compiler argument <em>-keep</em> (or <em>-keep-generated-actionscript=true</em>) in your compiler settings in Flex Builder, you will see a <em>generated</em> folder inside the src folder containing a lot of Actionscript files.</p>
<p>There are different kinds of files generated:</p>
<ul>
<li>Classes defining the default style for Flex components</li>
<li>Classes holding the Resourcebundle properties</li>
<li>Classes for embedded skins</li>
<li>Classes for Flex Application setup</li>
<li>Classes for Flex DataBinding</li>
</ul>
<p>The style, skin and property files are out of our scope here and has no direct relation to this topic.<br />
The classes which are used for setting up a Flex Application are our entry point, but will not be discussed in detail (even it would be very interesting to have a closer look to Mixins, [Frame] metadata tags and all these exotic stuff&#8230;).</p>
<p>So lets look at our <strong>relevant classes</strong> for DataBinding (all others has been removed):</p>
<p><img class="alignnone size-full wp-image-238" title="generated3" src="http://www.screenshot.at/blog/wp-content/uploads/2009/04/generated.gif" alt="generated" width="342" height="190" /><br />
<span id="more-230"></span><br />
The entry-point of our Flex application is <span class="hl">_DBGC_mx_managers_SystemManager</span>.<br />
This class extends SystemManager. The SystemManager is the main class and the first DisplayObject added to the stage. It does a lot of setup stuff.<br />
At the first frame in our MovieClip the preloading is handled. At the second frame the Application (DBGC) is instantiated. In the static info() method the mixins classes are defined. At frame 2 the mixin classes are inited via the static method call init().</p>
<p>The <span class="hl">DBCG</span> class (file: DBCG-generated.as) is our Application class.<br />
Here the MXML components are converted to UIComponentDescriptors which handles the instantiation of these Components.<br />
At initialize() an array of Binding objects are created.<br />
The Binding class use anonymous functions for resolving the source and destination properties.</p>
<pre>
<div class="codesnip-container" >
<div class="codesnip" style="font-family: monospace;"><span class="kw2">var</span> binding:Binding = <span class="kw1">new</span> mx.binding.Binding<span class="br0">&#40;</span><span class="kw1">this</span>,
&nbsp; &nbsp; <span class="kw3">function</span><span class="br0">&#40;</span><span class="br0">&#41;</span>:<a href="http://www.google.com/search?q=String%20inurl:http://livedocs.adobe.com/flex/201/langref/%20inurl:String.html&#038;filter=0&#038;num=100&#038;btnI=lucky"><span class="kw5">String</span></a>
&nbsp; &nbsp; <span class="br0">&#123;</span>
&nbsp; &nbsp; &nbsp; &nbsp; <span class="kw2">var</span> result:* = <span class="br0">&#40;</span>bindableVO.myBindableProp<span class="br0">&#41;</span>;
&nbsp; &nbsp; &nbsp; &nbsp; <span class="kw2">var</span> stringResult:<a href="http://www.google.com/search?q=String%20inurl:http://livedocs.adobe.com/flex/201/langref/%20inurl:String.html&#038;filter=0&#038;num=100&#038;btnI=lucky"><span class="kw5">String</span></a> = <span class="br0">&#40;</span>result == <span class="kw1">undefined</span> ? <span class="kw1">null</span> : <a href="http://www.google.com/search?q=String%20inurl:http://livedocs.adobe.com/flex/201/langref/%20inurl:String.html&#038;filter=0&#038;num=100&#038;btnI=lucky"><span class="kw5">String</span></a><span class="br0">&#40;</span>result<span class="br0">&#41;</span><span class="br0">&#41;</span>;
&nbsp; &nbsp; &nbsp; &nbsp; <span class="kw1">return</span> stringResult;
&nbsp; &nbsp; <span class="br0">&#125;</span>,
&nbsp; &nbsp; <span class="kw3">function</span><span class="br0">&#40;</span>_sourceFunctionReturnValue:<a href="http://www.google.com/search?q=String%20inurl:http://livedocs.adobe.com/flex/201/langref/%20inurl:String.html&#038;filter=0&#038;num=100&#038;btnI=lucky"><span class="kw5">String</span></a><span class="br0">&#41;</span>:<span class="kw1">void</span>
&nbsp; &nbsp; <span class="br0">&#123;</span>

&nbsp; &nbsp; &nbsp; &nbsp; myLabel.<span class="kw7">text</span> = _sourceFunctionReturnValue;
&nbsp; &nbsp; <span class="br0">&#125;</span>,
&nbsp; &nbsp; <span class="st0">&quot;myLabel.text&quot;</span><span class="br0">&#41;</span>;</div>
</div>
</pre>
<p>The <span class="hl">_DBGCWatcherSetupUtil</span> creates an array of PropertyWatcher objects, setup the relationship for chains and pass the Binding object to the PropertyWatcher.</p>
<pre>
<div class="codesnip-container" >
<div class="codesnip" style="font-family: monospace;">watchers<span class="br0">&#91;</span><span class="nu0">0</span><span class="br0">&#93;</span> = <span class="kw1">new</span> mx.binding.PropertyWatcher<span class="br0">&#40;</span><span class="st0">&quot;bindableVO&quot;</span>,
&nbsp; &nbsp; <span class="br0">&#123;</span> propertyChange: <span class="kw1">true</span> <span class="br0">&#125;</span>,<span class="br0">&#91;</span> bindings<span class="br0">&#91;</span><span class="nu0">0</span><span class="br0">&#93;</span> <span class="br0">&#93;</span>, propertyGetter<span class="br0">&#41;</span>;
watchers<span class="br0">&#91;</span><span class="nu0">1</span><span class="br0">&#93;</span> = <span class="kw1">new</span> mx.binding.PropertyWatcher<span class="br0">&#40;</span><span class="st0">&quot;myBindableProp&quot;</span>,
&nbsp; &nbsp; <span class="br0">&#123;</span> propertyChange: <span class="kw1">true</span> <span class="br0">&#125;</span>,<span class="br0">&#91;</span> bindings<span class="br0">&#91;</span><span class="nu0">0</span><span class="br0">&#93;</span> <span class="br0">&#93;</span>, <span class="kw1">null</span><span class="br0">&#41;</span>;
watchers<span class="br0">&#91;</span><span class="nu0">0</span><span class="br0">&#93;</span>.updateParent<span class="br0">&#40;</span><span class="kw7">target</span><span class="br0">&#41;</span>;
watchers<span class="br0">&#91;</span><span class="nu0">0</span><span class="br0">&#93;</span>.<span class="kw7">addChild</span><span class="br0">&#40;</span>watchers<span class="br0">&#91;</span><span class="nu0">1</span><span class="br0">&#93;</span><span class="br0">&#41;</span>;</div>
</div>
</pre>
<p>After the basic setup execute() is called on every Binding object.<br />
Here is the complete code:</p>
<pre>
<div class="codesnip-container" >
<div class="codesnip" style="font-family: monospace;">override <span class="kw1">public</span> <span class="kw3">function</span> initialize<span class="br0">&#40;</span><span class="br0">&#41;</span>:<span class="kw1">void</span>
<span class="br0">&#123;</span>
&nbsp;&nbsp; &nbsp; &nbsp; &nbsp;mx_internal::setDocumentDescriptor<span class="br0">&#40;</span>_documentDescriptor_<span class="br0">&#41;</span>;

&nbsp; &nbsp; &nbsp; &nbsp; <span class="kw2">var</span> bindings:<a href="http://www.google.com/search?q=Array%20inurl:http://livedocs.adobe.com/flex/201/langref/%20inurl:Array.html&#038;filter=0&#038;num=100&#038;btnI=lucky"><span class="kw5">Array</span></a> = _DBGC_bindingsSetup<span class="br0">&#40;</span><span class="br0">&#41;</span>;
&nbsp; &nbsp; &nbsp; &nbsp; <span class="kw2">var</span> watchers:<a href="http://www.google.com/search?q=Array%20inurl:http://livedocs.adobe.com/flex/201/langref/%20inurl:Array.html&#038;filter=0&#038;num=100&#038;btnI=lucky"><span class="kw5">Array</span></a> = <span class="br0">&#91;</span><span class="br0">&#93;</span>;

&nbsp; &nbsp; &nbsp; &nbsp; <span class="kw2">var</span> <span class="kw7">target</span>:DBGC = <span class="kw1">this</span>;

&nbsp; &nbsp; &nbsp; &nbsp; <span class="kw1">if</span> <span class="br0">&#40;</span>_watcherSetupUtil == <span class="kw1">null</span><span class="br0">&#41;</span>
&nbsp; &nbsp; &nbsp; &nbsp; <span class="br0">&#123;</span>
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="kw2">var</span> watcherSetupUtilClass:<a href="http://www.google.com/search?q=Object%20inurl:http://livedocs.adobe.com/flex/201/langref/%20inurl:Object.html&#038;filter=0&#038;num=100&#038;btnI=lucky"><span class="kw5">Object</span></a> = <span class="kw7">getDefinitionByName</span><span class="br0">&#40;</span><span class="st0">&quot;_DBGCWatcherSetupUtil&quot;</span><span class="br0">&#41;</span>;
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; watcherSetupUtilClass<span class="br0">&#91;</span><span class="st0">&quot;init&quot;</span><span class="br0">&#93;</span><span class="br0">&#40;</span><span class="kw1">null</span><span class="br0">&#41;</span>;
&nbsp; &nbsp; &nbsp; &nbsp; <span class="br0">&#125;</span>

&nbsp; &nbsp; &nbsp; &nbsp; _watcherSetupUtil.setup<span class="br0">&#40;</span><span class="kw1">this</span>,
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="kw3">function</span><span class="br0">&#40;</span>propertyName:<a href="http://www.google.com/search?q=String%20inurl:http://livedocs.adobe.com/flex/201/langref/%20inurl:String.html&#038;filter=0&#038;num=100&#038;btnI=lucky"><span class="kw5">String</span></a><span class="br0">&#41;</span>:* <span class="br0">&#123;</span>
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span class="kw1">return</span> <span class="kw7">target</span><span class="br0">&#91;</span>propertyName<span class="br0">&#93;</span>;
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="br0">&#125;</span>,
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; bindings,
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; watchers<span class="br0">&#41;</span>;

&nbsp; &nbsp; &nbsp; &nbsp; <span class="kw1">for</span> <span class="br0">&#40;</span><span class="kw2">var</span> i:<a href="http://www.google.com/search?q=uint%20inurl:http://livedocs.adobe.com/flex/201/langref/%20inurl:uint.html&#038;filter=0&#038;num=100&#038;btnI=lucky"><span class="kw5">uint</span></a> = <span class="nu0">0</span>; i &amp;lt; bindings.<span class="kw7">length</span>; i++<span class="br0">&#41;</span>
&nbsp; &nbsp; &nbsp; &nbsp; <span class="br0">&#123;</span>
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Binding<span class="br0">&#40;</span>bindings<span class="br0">&#91;</span>i<span class="br0">&#93;</span><span class="br0">&#41;</span>.execute<span class="br0">&#40;</span><span class="br0">&#41;</span>;
&nbsp; &nbsp; &nbsp; &nbsp; <span class="br0">&#125;</span>

&nbsp; &nbsp; &nbsp; &nbsp; mx_internal::_bindings = mx_internal::_bindings.<span class="kw7">concat</span><span class="br0">&#40;</span>bindings<span class="br0">&#41;</span>;
&nbsp; &nbsp; &nbsp; &nbsp; mx_internal::_watchers = mx_internal::_watchers.<span class="kw7">concat</span><span class="br0">&#40;</span>watchers<span class="br0">&#41;</span>;

&nbsp; &nbsp; &nbsp; &nbsp; <span class="kw1">super</span>.initialize<span class="br0">&#40;</span><span class="br0">&#41;</span>;
<span class="br0">&#125;</span>

<span class="kw1">private</span> <span class="kw3">function</span> _DBGC_bindingsSetup<span class="br0">&#40;</span><span class="br0">&#41;</span>:<a href="http://www.google.com/search?q=Array%20inurl:http://livedocs.adobe.com/flex/201/langref/%20inurl:Array.html&#038;filter=0&#038;num=100&#038;btnI=lucky"><span class="kw5">Array</span></a>
<span class="br0">&#123;</span>
&nbsp; &nbsp; <span class="kw2">var</span> result:<a href="http://www.google.com/search?q=Array%20inurl:http://livedocs.adobe.com/flex/201/langref/%20inurl:Array.html&#038;filter=0&#038;num=100&#038;btnI=lucky"><span class="kw5">Array</span></a> = <span class="br0">&#91;</span><span class="br0">&#93;</span>;
&nbsp; &nbsp; <span class="kw2">var</span> binding:Binding;

&nbsp; &nbsp; binding = <span class="kw1">new</span> mx.binding.Binding<span class="br0">&#40;</span><span class="kw1">this</span>,
&nbsp; &nbsp; &nbsp; &nbsp; <span class="kw3">function</span><span class="br0">&#40;</span><span class="br0">&#41;</span>:<a href="http://www.google.com/search?q=String%20inurl:http://livedocs.adobe.com/flex/201/langref/%20inurl:String.html&#038;filter=0&#038;num=100&#038;btnI=lucky"><span class="kw5">String</span></a>
&nbsp; &nbsp; &nbsp; &nbsp; <span class="br0">&#123;</span>
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="kw2">var</span> result:* = <span class="br0">&#40;</span>bindableVO.myBindableProp<span class="br0">&#41;</span>;
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="kw2">var</span> stringResult:<a href="http://www.google.com/search?q=String%20inurl:http://livedocs.adobe.com/flex/201/langref/%20inurl:String.html&#038;filter=0&#038;num=100&#038;btnI=lucky"><span class="kw5">String</span></a> = <span class="br0">&#40;</span>result == <span class="kw1">undefined</span> ? <span class="kw1">null</span> : <a href="http://www.google.com/search?q=String%20inurl:http://livedocs.adobe.com/flex/201/langref/%20inurl:String.html&#038;filter=0&#038;num=100&#038;btnI=lucky"><span class="kw5">String</span></a><span class="br0">&#40;</span>result<span class="br0">&#41;</span><span class="br0">&#41;</span>;
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="kw1">return</span> stringResult;
&nbsp; &nbsp; &nbsp; &nbsp; <span class="br0">&#125;</span>,
&nbsp; &nbsp; &nbsp; &nbsp; <span class="kw3">function</span><span class="br0">&#40;</span>_sourceFunctionReturnValue:<a href="http://www.google.com/search?q=String%20inurl:http://livedocs.adobe.com/flex/201/langref/%20inurl:String.html&#038;filter=0&#038;num=100&#038;btnI=lucky"><span class="kw5">String</span></a><span class="br0">&#41;</span>:<span class="kw1">void</span>
&nbsp; &nbsp; &nbsp; &nbsp; <span class="br0">&#123;</span>

&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; myLabel.<span class="kw7">text</span> = _sourceFunctionReturnValue;
&nbsp; &nbsp; &nbsp; &nbsp; <span class="br0">&#125;</span>,
&nbsp; &nbsp; &nbsp; &nbsp; <span class="st0">&quot;myLabel.text&quot;</span><span class="br0">&#41;</span>;
&nbsp; &nbsp; result<span class="br0">&#91;</span><span class="nu0">0</span><span class="br0">&#93;</span> = binding;

&nbsp; &nbsp; <span class="kw1">return</span> result;
<span class="br0">&#125;</span></div>
</div>
</pre>
<p>So lets jump into the <span class="hl">Binding</span> Class. This is a regular Framework class.<br />
The execute() method is basically applying the source value to the destination. In-between there is a lot of error handling going on, but basically it´s nothing else as reading out a value and setting it to the destination. No event dispatching is included until now.</p>
<p>The setting of the value happens on start-up. If the bindable property changes later, event dispatching comes in.<br />
This happens in the <span class="hl">PropertyWatcher</span> class:<br />
An event handler is added at the source object and the PropertyWatcher is listening for the defined event type. It is invoked with weak reference, so the fact that MXML Bindings cannot be removed will not lead to memory leaks.<br />
The event handler checks if the dispatched PropertyChangeEvent contains the same property name as our PropertyWatcher represents and calls notifyListeners() if the property name matches.<br />
On every Binding object which is registered as listener watcherFired() is called.<br />
And here again the execute() method is responsible for passing the value from the source over to the destination.</p>
<p>The last missing link is the class which dispatch the PropertyChangeEvent.<br />
The <span class="hl">BindableProperty</span> (file: _BindablePropertyVO-binding-generated.as) is the place where this happens.</p>
<pre>
<div class="codesnip-container" >
<div class="codesnip" style="font-family: monospace;"><span class="br0">&#91;</span><span class="kw1">Bindable</span><span class="br0">&#40;</span>event=<span class="st0">&quot;propertyChange&quot;</span><span class="br0">&#41;</span><span class="br0">&#93;</span>
<span class="kw1">public</span> <span class="kw3">function</span> <span class="kw1">get</span> myBindableProp<span class="br0">&#40;</span><span class="br0">&#41;</span>:<a href="http://www.google.com/search?q=String%20inurl:http://livedocs.adobe.com/flex/201/langref/%20inurl:String.html&#038;filter=0&#038;num=100&#038;btnI=lucky"><span class="kw5">String</span></a>
<span class="br0">&#123;</span>
&nbsp; &nbsp; <span class="kw1">return</span> <span class="kw1">this</span>._834029286myBindableProp;
<span class="br0">&#125;</span>

<span class="kw1">public</span> <span class="kw3">function</span> <span class="kw1">set</span> myBindableProp<span class="br0">&#40;</span><span class="kw7">value</span>:<a href="http://www.google.com/search?q=String%20inurl:http://livedocs.adobe.com/flex/201/langref/%20inurl:String.html&#038;filter=0&#038;num=100&#038;btnI=lucky"><span class="kw5">String</span></a><span class="br0">&#41;</span>:<span class="kw1">void</span>
<span class="br0">&#123;</span>
&nbsp; &nbsp; <span class="kw2">var</span> oldValue:<a href="http://www.google.com/search?q=Object%20inurl:http://livedocs.adobe.com/flex/201/langref/%20inurl:Object.html&#038;filter=0&#038;num=100&#038;btnI=lucky"><span class="kw5">Object</span></a> = <span class="kw1">this</span>._834029286myBindableProp;
&nbsp; &nbsp; <span class="kw1">if</span> <span class="br0">&#40;</span>oldValue !== <span class="kw7">value</span><span class="br0">&#41;</span>
&nbsp; &nbsp; <span class="br0">&#123;</span>
&nbsp; &nbsp; &nbsp; &nbsp; <span class="kw1">this</span>._834029286myBindableProp = <span class="kw7">value</span>;
&nbsp; &nbsp; &nbsp; &nbsp; <span class="kw1">this</span>.<span class="kw7">dispatchEvent</span><span class="br0">&#40;</span>mx.events.PropertyChangeEvent.createUpdateEvent<span class="br0">&#40;</span><span class="kw1">this</span>,
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="st0">&quot;myBindableProp&quot;</span>, oldValue, <span class="kw7">value</span><span class="br0">&#41;</span><span class="br0">&#41;</span>;
&nbsp; &nbsp; <span class="br0">&#125;</span>
<span class="br0">&#125;</span></div>
</div>
</pre>
<p>Here the gettter/setters are created for our [Bindable] property. The compiler defines &#8220;propertyChange&#8221; as event type - [Bindable(event="propertyChange")] and dispatches a PropertyChangeEvent if the value has changed.<br />
If the class containing the bindable property is not a subclass of EventDispatcher the compiler set the classes interface of BindableProperty to IEventDispatcher, adds the methods of IEventDispatcher and uses an instance of EventDispatcher via composition.</p>
<p>Note that this code is only generated when you don´t use custom events in the [Bindable] metadata tag ([Bindable(event="myCustonEvent")]).</p>
<p>I don´t know how this class is linked into the Application, it has no reference anywhere. I guess the compiler do this job behind the scenes, as well as with the interface classes and some other stuff.</p>
<p>Lets have a look to the <span class="hl">moments when DataBinding is executed:</span></p>
<p>At <strong>Application start-up</strong> the Binding is executed  for the first time.<br />
Here is the call stack (Breakpoint at Binding.execute():</p>
<p><img class="alignnone size-full wp-image-248" title="dbseq1" src="http://www.screenshot.at/blog/wp-content/uploads/2009/04/dbseq1.gif" alt="dbseq1" width="613" height="188" /></p>
<p>Due the fact that the component is not created yet, the Binding fails in a catch Block at wrapFunctionCall() in the Binding class. The catch block is pretty slow, i am wondering why this initial execute() is not prevented? At least the try/catch could be replaced with a check against null  which is much faster then falling into the catch block. I guess in large applications this could noticeable slow down start-up time.</p>
<p>At the time the <strong>component is added to the Application</strong> executeBinding() is called and triggers the second execute().</p>
<p><img class="alignnone size-full wp-image-249" title="dbseq2" src="http://www.screenshot.at/blog/wp-content/uploads/2009/04/dbseq2.gif" alt="dbseq2" width="613" height="321" /></p>
<p>At this point the component is valid but there is only the value passed which is defined in the property declaration. This value is often not set at this momens so it is null.</p>
<p>If you setup your initial value at the <strong>initialize</strong> event a third run will be triggered:</p>
<p><img class="alignnone size-full wp-image-250" title="dbseq3" src="http://www.screenshot.at/blog/wp-content/uploads/2009/04/dbseq3.gif" alt="dbseq3" width="590" height="494" /></p>
<p>You can prevent this if you set the value right at the variable declaration (if possible) and so prevent to trigger DataBindings third round.</p>
<p><span class="hl">Conclusion</span><br />
Finally we are through the basic parts how DataBinding is working behind the scenes. To go further it´s best to step through the generated code and try out different scenarios.<br />
We only have had a look into Binding in MXML. If you use BindingUtils just the code for event dispatching from the [Bindable] metadata tag is created.</p>
<p>The generated code for DataBinding with MXML do a lot of error handling. it´s clear that it has some performance drawbacks but gives the benefit that it is very fault-tolerant. You also should consider that there are a lot of different features and use cases for Binding (functions, expressions, 2-way Bindings,&#8230;) which has to be handled.</p>
<p>For large applications BindingUtils are the better choice and prevents several performance drawbacks, specially at start-up time.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.screenshot.at/blog/2009/04/26/databinding-under-the-hood-part3-generated-code/feed/</wfw:commentRss>
		</item>
	</channel>
</rss>
