<?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>rialvalue.com &#187; architecture</title>
	<atom:link href="http://www.rialvalue.com/blog/category/architecture/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.rialvalue.com/blog</link>
	<description>No Flex No Fun</description>
	<lastBuildDate>Fri, 04 Feb 2011 08:09:27 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.9.2</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>Properties file based configuration mechanism for Parsley</title>
		<link>http://www.rialvalue.com/blog/2010/05/12/properties-file-based-configuration-mechanism-for-parsley/</link>
		<comments>http://www.rialvalue.com/blog/2010/05/12/properties-file-based-configuration-mechanism-for-parsley/#comments</comments>
		<pubDate>Wed, 12 May 2010 19:23:45 +0000</pubDate>
		<dc:creator>Xavi Beumala</dc:creator>
				<category><![CDATA[architecture]]></category>
		<category><![CDATA[flex]]></category>
		<category><![CDATA[parsley]]></category>
		<category><![CDATA[tips]]></category>

		<guid isPermaLink="false">http://www.rialvalue.com/blog/?p=204</guid>
		<description><![CDATA[In this post I introduce a new mechanism for Parsley to load part of a Context from a properties file. This way highly dynamic of changing properties can be managed externally from the properties file, avoiding the verbosity of an XML approach. As always, the source code is attached.
One of the things I like a [...]]]></description>
			<content:encoded><![CDATA[<p>In this post I introduce a new mechanism for Parsley to load part of a Context from a properties file. This way highly dynamic of changing properties can be managed externally from the properties file, avoiding the verbosity of an XML approach. As always, <a href="http://www.rialvalue.com/downloads/parsleyPropertiesProcessor.zip">the source code is attached</a>.</p>
<p>One of the things I like a lot about Parsley are all its extenstion points and available hooks to extends its native functionalities or default behaviours. In these regards a very useful extension point is, <a href="http://blogs.adobe.com/tomsugden/2010/02/the_flexible_configuration_opt.html#more">Tom explained a while ago</a>, the different configuration mechanisms.</p>
<p><a href="http://www.spicefactory.org/parsley/docs/2.2/manual/config.php#combine">As explained in the documentation</a> you can use a combined configuration mechanism to separate more dynamic or change-prone definitions from the more static ones. You could use an XML-based context defintion for the former and an MXML-based context definition for the latter.</p>
<p>While the XML-based context definition might work in most of the cases it might not be the best solution in some scenarios due to its verbosity.</p>
<p>Imagine I have an AIR2 based application which creates an HTTPServer instance. The server instance is created an managed by a Parsley Context:</p>
<div class="codecolorer-container xml mac-classic" style="overflow:auto;white-space:nowrap;border: 1px solid #9F9F9F;width:515px;"><div class="xml codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;spicefactory:Object</span> <span style="color: #000066;">id</span>=<span style="color: #ff0000;">&quot;httpServer&quot;</span></span><br />
<span style="color: #009900;"> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #000066;">type</span>=<span style="color: #ff0000;">&quot;{HTTPServerImpl}&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span><br />
<br />
&nbsp; &nbsp; <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;spicefactory:ConstructorArgs<span style="color: #000000; font-weight: bold;">&gt;</span></span></span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;spicefactory:NestedObject</span> <span style="color: #000066;">type</span>=<span style="color: #ff0000;">&quot;{RequestProcessorFactory}&quot;</span><span style="color: #000000; font-weight: bold;">/&gt;</span></span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;fx:Number<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>5000<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/fx:Number<span style="color: #000000; font-weight: bold;">&gt;</span></span></span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;fx:String<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>0.0.0.0<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/fx:String<span style="color: #000000; font-weight: bold;">&gt;</span></span></span><br />
&nbsp; &nbsp; <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/spicefactory:ConstructorArgs<span style="color: #000000; font-weight: bold;">&gt;</span></span></span><br />
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/spicefactory:Object<span style="color: #000000; font-weight: bold;">&gt;</span></span></span></div></div>
<p>The second constructor parameter, 5000, is the port the server will be listening to and the third-one, 0.0.0.0, is the network interface where the server will be binded to.<br />
These 2 parameters are potentially prone to change whereas the rest of the definition will be very static and rarely change. In my case these parameters should be configurable and maintained by IT administrators or even final users.</p>
<p>Moving this definition to a runtime configuration mechanism seems like the right thing. The main problem of moving this into an XML-based context is that it&#8217;d be too verbose and meaningless to the the targeted users who should maitain and drive the changes, thus making the configuration system of the application too weak and error-prone while exposing things that shouldn&#8217;t be changed (at least by these users).</p>
<p>What I would like to do is define in a more static way the server creation instance, making it safer to undesired configurations, but make more dynamic some of its arguments:</p>
<div class="codecolorer-container xml mac-classic" style="overflow:auto;white-space:nowrap;border: 1px solid #9F9F9F;width:515px;"><div class="xml codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;spicefactory:Object</span> <span style="color: #000066;">id</span>=<span style="color: #ff0000;">&quot;httpServer&quot;</span></span><br />
<span style="color: #009900;"> &nbsp; &nbsp;<span style="color: #000066;">type</span>=<span style="color: #ff0000;">&quot;{HTTPServerImpl}&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span><br />
<br />
&nbsp; &nbsp; <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;spicefactory:ConstructorArgs<span style="color: #000000; font-weight: bold;">&gt;</span></span></span> &nbsp; &nbsp;<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;spicefactory:NestedObject</span> <span style="color: #000066;">type</span>=<span style="color: #ff0000;">&quot;{RequestProcessorFactory}&quot;</span><span style="color: #000000; font-weight: bold;">/&gt;</span></span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;spicefactory:ObjectRef</span> <span style="color: #000066;">idRef</span>=<span style="color: #ff0000;">&quot;port&quot;</span><span style="color: #000000; font-weight: bold;">/&gt;</span></span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;spicefactory:ObjectRef</span> <span style="color: #000066;">idRef</span>=<span style="color: #ff0000;">&quot;host&quot;</span><span style="color: #000000; font-weight: bold;">/&gt;</span></span><br />
&nbsp; &nbsp; <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/spicefactory:ConstructorArgs<span style="color: #000000; font-weight: bold;">&gt;</span></span></span><br />
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/spicefactory:Object<span style="color: #000000; font-weight: bold;">&gt;</span></span></span></div></div>
<p>Then we could define the <b>port</b> and <b>host</b> parameters using any other mechanism.</p>
<p>My approach has been to create a properties file based configuation. I create config.properties like:</p>
<div class="codecolorer-container actionscript3 mac-classic" style="overflow:auto;white-space:nowrap;border: 1px solid #9F9F9F;width:515px;"><div class="actionscript3 codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">port=<span style="color: #000000; font-weight:bold;">5000</span><br />
host=0<span style="color: #000066; font-weight: bold;">.</span>0<span style="color: #000066; font-weight: bold;">.</span>0<span style="color: #000066; font-weight: bold;">.</span>0</div></div>
<p>And then the following combined configuration mechanism:</p>
<div class="codecolorer-container xml mac-classic" style="overflow:auto;white-space:nowrap;border: 1px solid #9F9F9F;width:515px;"><div class="xml codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;spicefactory:ContextBuilder<span style="color: #000000; font-weight: bold;">&gt;</span></span></span><br />
&nbsp; &nbsp; <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;spicefactory:FlexConfig</span> <span style="color: #000066;">type</span>=<span style="color: #ff0000;">&quot;{ CommonConfiguration }&quot;</span><span style="color: #000000; font-weight: bold;">/&gt;</span></span><br />
&nbsp; &nbsp; <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;processor:PropertiesConfig</span> <span style="color: #000066;">file</span>=<span style="color: #ff0000;">&quot;data/config.properties&quot;</span><span style="color: #000000; font-weight: bold;">/&gt;</span></span><br />
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/spicefactory:ContextBuilder<span style="color: #000000; font-weight: bold;">&gt;</span></span></span></div></div>
<p>This way the Parsley Context is built using an standard mxml approach together with a properties file based configuation. The PropertiesConfig implementation uses ContextBuilderProcessor and AsyncConfigurationProcessor extensions, load and parse the specified properties file and inject the property definitions into the context as simple strings. These definitions can then be used elsewhere normally.</p>
<p>You can find attached the entire implementation. Note that I implemented this against trunk (v.2.3.M1-snapshot) so it might not work out-of-the-box for other versions.</p>
<p>This technique could be used in a wide range of scenarios. You could define RemoteObjects and ChannelSet in an MXML compiled configuration file but inject from a properties file the  url of the Channel. i.e.</p>
<div class="codecolorer-container xml mac-classic" style="overflow:auto;white-space:nowrap;border: 1px solid #9F9F9F;width:515px;"><div class="xml codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;spicefactory:Object</span> <span style="color: #000066;">id</span>=<span style="color: #ff0000;">&quot;amfChannel&quot;</span> <span style="color: #000066;">type</span>=<span style="color: #ff0000;">&quot;{AMFChannel}&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span><br />
&nbsp; &nbsp; &nbsp;<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;spicefactory:Property</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">&quot;uri&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;spicefactory:ObjectRef</span> <span style="color: #000066;">idRef</span>=<span style="color: #ff0000;">&quot;amfChannelUri&quot;</span><span style="color: #000000; font-weight: bold;">/&gt;</span></span><br />
&nbsp; &nbsp; &nbsp;<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/spicefactory:Property<span style="color: #000000; font-weight: bold;">&gt;</span></span></span><br />
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/spicefactory:Object<span style="color: #000000; font-weight: bold;">&gt;</span></span></span></div></div>
<p>In the config.properties:</p>
<div class="codecolorer-container actionscript3 mac-classic" style="overflow:auto;white-space:nowrap;border: 1px solid #9F9F9F;width:515px;"><div class="actionscript3 codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">amfChannelUri=http<span style="color: #000066; font-weight: bold;">:</span><span style="color: #009900; font-style: italic;">//my.domain.com/messagebroker</span></div></div>
<p>And the declare the ContextBuilder as:</p>
<div class="codecolorer-container xml mac-classic" style="overflow:auto;white-space:nowrap;border: 1px solid #9F9F9F;width:515px;"><div class="xml codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;spicefactory:ContextBuilder<span style="color: #000000; font-weight: bold;">&gt;</span></span></span><br />
&nbsp; &nbsp; <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;spicefactory:FlexConfig</span> <span style="color: #000066;">type</span>=<span style="color: #ff0000;">&quot;{ CommonConfiguration }&quot;</span><span style="color: #000000; font-weight: bold;">/&gt;</span></span><br />
&nbsp; &nbsp; <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;processor:PropertiesConfig</span> <span style="color: #000066;">file</span>=<span style="color: #ff0000;">&quot;data/config.properties&quot;</span><span style="color: #000000; font-weight: bold;">/&gt;</span></span><br />
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/spicefactory:ContextBuilder<span style="color: #000000; font-weight: bold;">&gt;</span></span></span></div></div>
<p>Note, as suggested by Jens, that there might be scenarios where a tag like ObjectRef is not a good fit (like when using some of the built-in Flex tags like mx:RemoteObject). Being able to use a plain Flex binding on a simple MXML attribute might be a nice alternative to having &#8220;heavyweight&#8221; top-level String objects.<br />
Other very intersting ways to achieve this same behaviour suggested by Jens (all kudos to him):</p>
<p>1. Use XML Configuration declaring strings like:</p>
<div class="codecolorer-container xml mac-classic" style="overflow:auto;white-space:nowrap;border: 1px solid #9F9F9F;width:515px;"><div class="xml codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;object</span> <span style="color: #000066;">id</span>=<span style="color: #ff0000;">&quot;host&quot;</span> <span style="color: #000066;">type</span>=<span style="color: #ff0000;">&quot;String&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span><br />
&nbsp; &nbsp; <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;constructor-args<span style="color: #000000; font-weight: bold;">&gt;</span></span></span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;string<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>0.0.0.0<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/string<span style="color: #000000; font-weight: bold;">&gt;</span></span></span><br />
&nbsp; &nbsp; <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/constructor-args<span style="color: #000000; font-weight: bold;">&gt;</span></span></span><br />
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/object<span style="color: #000000; font-weight: bold;">&gt;</span></span></span></div></div>
<p>2. Create a custom tag that does the above in a more concise syntax using the Spicelib XML-Object-Mapper and a Parsley XMLConfigurationNamespace. You can see an example of this approach in Cairngorm3 Module library</p>
<div class="codecolorer-container xml mac-classic" style="overflow:auto;white-space:nowrap;border: 1px solid #9F9F9F;width:515px;"><div class="xml codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;custom:property</span> <span style="color: #000066;">id</span>=<span style="color: #ff0000;">&quot;host&quot;</span> <span style="color: #000066;">value</span>=<span style="color: #ff0000;">&quot;0.0.0.0&quot;</span><span style="color: #000000; font-weight: bold;">/&gt;</span></span></div></div>
<p>3. Use the approach of an Environment class holding these values in the XML file, but use a custom <PropertyRef> tag in MXML:</p>
<div class="codecolorer-container xml mac-classic" style="overflow:auto;white-space:nowrap;border: 1px solid #9F9F9F;width:515px;"><div class="xml codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;spicefactory:ConstructorArgs<span style="color: #000000; font-weight: bold;">&gt;</span></span></span><br />
&nbsp; &nbsp;<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;spicefactory:NestedObject</span> <span style="color: #000066;">type</span>=<span style="color: #ff0000;">&quot;{RequestProcessorFactory}&quot;</span><span style="color: #000000; font-weight: bold;">/&gt;</span></span><br />
&nbsp; &nbsp;<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;custom:PropertyRef</span> <span style="color: #000066;">idRef</span>=<span style="color: #ff0000;">&quot;environment&quot;</span> <span style="color: #000066;">property</span>=<span style="color: #ff0000;">&quot;port&quot;</span><span style="color: #000000; font-weight: bold;">/&gt;</span></span> <br />
&nbsp; &nbsp;<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;custom:PropertyRef</span> <span style="color: #000066;">idRef</span>=<span style="color: #ff0000;">&quot;environment&quot;</span> <span style="color: #000066;">property</span>=<span style="color: #ff0000;">&quot;host&quot;</span><span style="color: #000000; font-weight: bold;">/&gt;</span></span><br />
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/spicefactory:ConstrunctorArgs<span style="color: #000000; font-weight: bold;">&gt;</span></span></span></div></div>
<p>The PropertyRef tag would require a bit of work (and it would be different for Parsley 2.2 and 2.3 due to some changes in internal APIs.</p>
<p><a href="http://www.rialvalue.com/downloads/parsleyPropertiesProcessor.zip">Download PropertiesConfig for Parsley.</a>.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.rialvalue.com/blog/2010/05/12/properties-file-based-configuration-mechanism-for-parsley/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>String Templating in Flex</title>
		<link>http://www.rialvalue.com/blog/2010/05/10/string-templating-in-flex/</link>
		<comments>http://www.rialvalue.com/blog/2010/05/10/string-templating-in-flex/#comments</comments>
		<pubDate>Mon, 10 May 2010 09:51:29 +0000</pubDate>
		<dc:creator>Xavi Beumala</dc:creator>
				<category><![CDATA[architecture]]></category>
		<category><![CDATA[flex]]></category>
		<category><![CDATA[tips]]></category>

		<guid isPermaLink="false">http://www.rialvalue.com/blog/?p=199</guid>
		<description><![CDATA[When working with String templates, code can easily become quite difficult to read and, consequently, to understand, maintain and modify. This blog post explains 2 techniques that can help you dealing with String concatenation and templating: StringUtil.substitue and [Embed] compiler directive.
For simple String concatenation like:
var value : String = &#34;The value &#34; + user + [...]]]></description>
			<content:encoded><![CDATA[<p>When working with String templates, code can easily become quite difficult to read and, consequently, to understand, maintain and modify. This blog post explains 2 techniques that can help you dealing with String concatenation and templating: StringUtil.substitue and [Embed] compiler directive.</p>
<p>For simple String concatenation like:</p>
<div class="codecolorer-container actionscript3 mac-classic" style="overflow:auto;white-space:nowrap;border: 1px solid #9F9F9F;width:515px;"><div class="actionscript3 codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #6699cc; font-weight: bold;">var</span> <span style="color: #004993;">value</span> <span style="color: #000066; font-weight: bold;">:</span> <a href="http://www.google.com/search?q=string%20inurl:http://livedocs.adobe.com/flex/201/langref/%20inurl:string.html"><span style="color: #004993;">String</span></a> = <span style="color: #990000;">&quot;The value &quot;</span> <span style="color: #000066; font-weight: bold;">+</span> user <span style="color: #000066; font-weight: bold;">+</span> <span style="color: #990000;">&quot; requested is <span style="">\&quot;</span>&quot;</span> <span style="color: #000066; font-weight: bold;">+</span> <span style="color: #004993;">value</span> <span style="color: #990000;">&quot;<span style="">\&quot;</span>&quot;</span><span style="color: #000066; font-weight: bold;">;</span></div></div>
<p>You can alwayus use StringUtil.substitue, which will help you having a wider vision of the message being built:</p>
<div class="codecolorer-container actionscript3 mac-classic" style="overflow:auto;white-space:nowrap;border: 1px solid #9F9F9F;width:515px;"><div class="actionscript3 codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #0033ff; font-weight: bold;">import</span> mx<span style="color: #000066; font-weight: bold;">.</span>utils<span style="color: #000066; font-weight: bold;">.</span>StringUtil<span style="color: #000066; font-weight: bold;">;</span><br />
<span style="color: #6699cc; font-weight: bold;">var</span> <span style="color: #004993;">value</span> <span style="color: #000066; font-weight: bold;">:</span> <a href="http://www.google.com/search?q=string%20inurl:http://livedocs.adobe.com/flex/201/langref/%20inurl:string.html"><span style="color: #004993;">String</span></a> = StringUtil<span style="color: #000066; font-weight: bold;">.</span>substitute<span style="color: #000000;">&#40;</span><span style="color: #990000;">&quot;The value {0} requested is <span style="">\&quot;</span>{1}<span style="">\&quot;</span>&quot;</span><span style="color: #000066; font-weight: bold;">,</span> user<span style="color: #000066; font-weight: bold;">,</span> <span style="color: #004993;">value</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span></div></div>
<p>When creating multi-line Strings, things can easily get uglier:</p>
<div class="codecolorer-container actionscript3 mac-classic" style="overflow:auto;white-space:nowrap;border: 1px solid #9F9F9F;width:515px;"><div class="actionscript3 codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #6699cc; font-weight: bold;">var</span> errorCode<span style="color: #000066; font-weight: bold;">:</span><a href="http://www.google.com/search?q=string%20inurl:http://livedocs.adobe.com/flex/201/langref/%20inurl:string.html"><span style="color: #004993;">String</span></a><span style="color: #000066; font-weight: bold;">;</span><br />
<span style="color: #6699cc; font-weight: bold;">var</span> errorString<span style="color: #000066; font-weight: bold;">:</span><a href="http://www.google.com/search?q=string%20inurl:http://livedocs.adobe.com/flex/201/langref/%20inurl:string.html"><span style="color: #004993;">String</span></a><span style="color: #000066; font-weight: bold;">;</span><br />
<span style="color: #6699cc; font-weight: bold;">var</span> errorMessage<span style="color: #000066; font-weight: bold;">:</span><a href="http://www.google.com/search?q=string%20inurl:http://livedocs.adobe.com/flex/201/langref/%20inurl:string.html"><span style="color: #004993;">String</span></a><span style="color: #000066; font-weight: bold;">;</span><br />
<br />
<span style="color: #6699cc; font-weight: bold;">var</span> str<span style="color: #000066; font-weight: bold;">:</span><a href="http://www.google.com/search?q=string%20inurl:http://livedocs.adobe.com/flex/201/langref/%20inurl:string.html"><span style="color: #004993;">String</span></a> = <span style="color: #990000;">&quot;&lt;!DOCTYPE HTML PUBLIC <span style="">\&quot;</span>-//IETF//DTD HTML 2.0//EN<span style="">\&quot;</span>&gt;<span style="">\n</span>&quot;</span><br />
str <span style="color: #000066; font-weight: bold;">+</span>= <span style="color: #990000;">&quot;&lt;html&gt;&lt;head&gt;<span style="">\n</span>&quot;</span><span style="color: #000066; font-weight: bold;">;</span><br />
str <span style="color: #000066; font-weight: bold;">+</span>= <span style="color: #990000;">&quot;&lt;title&gt;&quot;</span> <span style="color: #000066; font-weight: bold;">+</span> errorCode <span style="color: #000066; font-weight: bold;">+</span> <span style="color: #990000;">&quot; &quot;</span> <span style="color: #000066; font-weight: bold;">+</span> errorString <span style="color: #000066; font-weight: bold;">+</span> <span style="color: #990000;">&quot;&lt;/title&gt;<span style="">\n</span>&quot;</span><br />
str <span style="color: #000066; font-weight: bold;">+</span>= <span style="color: #990000;">&quot;&lt;/head&gt;&lt;body&gt;<span style="">\n</span>&quot;</span><span style="color: #000066; font-weight: bold;">;</span><br />
str <span style="color: #000066; font-weight: bold;">+</span>= <span style="color: #990000;">&quot;&lt;h1&gt;&quot;</span> <span style="color: #000066; font-weight: bold;">+</span> errorCode <span style="color: #000066; font-weight: bold;">+</span> <span style="color: #990000;">&quot;&lt;/h1&gt;<span style="">\n</span>&quot;</span><span style="color: #000066; font-weight: bold;">;</span><br />
str <span style="color: #000066; font-weight: bold;">+</span>= <span style="color: #990000;">&quot;&lt;p&gt;&quot;</span> <span style="color: #000066; font-weight: bold;">+</span> errorMessage <span style="color: #000066; font-weight: bold;">+</span> <span style="color: #990000;">&quot;&lt;/p&gt;<span style="">\n</span>&quot;</span><span style="color: #000066; font-weight: bold;">;</span><br />
str <span style="color: #000066; font-weight: bold;">+</span>= <span style="color: #990000;">&quot;&lt;/body&gt;&lt;/html&gt;&quot;</span><span style="color: #000066; font-weight: bold;">;</span></div></div>
<p>Not to say that this could get worse. A way to make it a little bit more readable would be using the StringUtil substitution technique:</p>
<div class="codecolorer-container actionscript3 mac-classic" style="overflow:auto;white-space:nowrap;border: 1px solid #9F9F9F;width:515px;"><div class="actionscript3 codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #6699cc; font-weight: bold;">var</span> str<span style="color: #000066; font-weight: bold;">:</span><a href="http://www.google.com/search?q=string%20inurl:http://livedocs.adobe.com/flex/201/langref/%20inurl:string.html"><span style="color: #004993;">String</span></a> = <span style="color: #990000;">&quot;&lt;!DOCTYPE HTML PUBLIC <span style="">\&quot;</span>-//IETF//DTD HTML 2.0//EN<span style="">\&quot;</span>&gt;<span style="">\n</span>&quot;</span><br />
str <span style="color: #000066; font-weight: bold;">+</span>= <span style="color: #990000;">&quot;&lt;html&gt;&lt;head&gt;<span style="">\n</span>&quot;</span><span style="color: #000066; font-weight: bold;">;</span><br />
str <span style="color: #000066; font-weight: bold;">+</span>= <span style="color: #990000;">&quot;&lt;title&gt;{0}{1}&lt;/title&gt;<span style="">\n</span>&quot;</span><br />
str <span style="color: #000066; font-weight: bold;">+</span>= <span style="color: #990000;">&quot;&lt;/head&gt;&lt;body&gt;<span style="">\n</span>&quot;</span><span style="color: #000066; font-weight: bold;">;</span><br />
str <span style="color: #000066; font-weight: bold;">+</span>= <span style="color: #990000;">&quot;&lt;h1&gt;{0}&lt;/h1&gt;<span style="">\n</span>&quot;</span><span style="color: #000066; font-weight: bold;">;</span><br />
str <span style="color: #000066; font-weight: bold;">+</span>= <span style="color: #990000;">&quot;&lt;p&gt;{2}&lt;/p&gt;<span style="">\n</span>&quot;</span><span style="color: #000066; font-weight: bold;">;</span><br />
str <span style="color: #000066; font-weight: bold;">+</span>= <span style="color: #990000;">&quot;&lt;/body&gt;&lt;/html&gt;&quot;</span><span style="color: #000066; font-weight: bold;">;</span><br />
<br />
StringUtil<span style="color: #000066; font-weight: bold;">.</span>substitute<span style="color: #000000;">&#40;</span> str<span style="color: #000066; font-weight: bold;">,</span> errorCode<span style="color: #000066; font-weight: bold;">,</span> errorString<span style="color: #000066; font-weight: bold;">,</span> errorMessage<span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span></div></div>
<p>The problem with this is that there&#8217;s still too much infrastructure to create the base template and it&#8217;s difficult, at first sight, to see where are the substitution tokens. On the other hand, the templated text by itself might not have that much relevance in the code and might distract developers from other imporntant things.</p>
<p>A nice way to achieve the same result consists in externalizing the template to a text file and get some help from the compiler:</p>
<div class="codecolorer-container actionscript3 mac-classic" style="overflow:auto;white-space:nowrap;border: 1px solid #9F9F9F;width:515px;"><div class="actionscript3 codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #000000;">&#91;</span>Embed<span style="color: #000000;">&#40;</span><span style="color: #004993;">source</span>=<span style="color: #990000;">&quot;yourTemplate.txt&quot;</span><span style="color: #000066; font-weight: bold;">,</span> mimeType=<span style="color: #990000;">&quot;application/octet-stream&quot;</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">&#93;</span><br />
<span style="color: #0033ff; font-weight: bold;">private</span> <span style="color: #6699cc; font-weight: bold;">var</span> templateDefinition <span style="color: #000066; font-weight: bold;">:</span> <a href="http://www.google.com/search?q=class%20inurl:http://livedocs.adobe.com/flex/201/langref/%20inurl:class.html"><span style="color: #004993;">Class</span></a><span style="color: #000066; font-weight: bold;">;</span><br />
<br />
StringUtil<span style="color: #000066; font-weight: bold;">.</span>substitute<span style="color: #000000;">&#40;</span> <span style="color: #0033ff; font-weight: bold;">new</span> templateDefinition<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">,</span> errorCode<span style="color: #000066; font-weight: bold;">,</span> errorString<span style="color: #000066; font-weight: bold;">,</span> errorMessage<span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span></div></div>
<p>Where yourTemplate.txt is a simple text file with the template itself:</p>
<div class="codecolorer-container actionscript3 mac-classic" style="overflow:auto;white-space:nowrap;border: 1px solid #9F9F9F;width:515px;"><div class="actionscript3 codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #000066; font-weight: bold;">&lt;!</span>DOCTYPE HTML PUBLIC <span style="color: #990000;">&quot;-//IETF//DTD HTML 2.0//EN&quot;</span><span style="color: #000066; font-weight: bold;">&gt;</span><br />
<span style="color: #000066; font-weight: bold;">&lt;</span>html<span style="color: #000066; font-weight: bold;">&gt;&lt;</span>head<span style="color: #000066; font-weight: bold;">&gt;</span><br />
<span style="color: #000066; font-weight: bold;">&lt;</span>title<span style="color: #000066; font-weight: bold;">&gt;</span><span style="color: #000000;">&#123;</span><span style="color: #000000; font-weight:bold;">0</span><span style="color: #000000;">&#125;</span> <span style="color: #000000;">&#123;</span><span style="color: #000000; font-weight:bold;">1</span><span style="color: #000000;">&#125;</span><span style="color: #000066; font-weight: bold;">&lt;/</span>title<span style="color: #000066; font-weight: bold;">&gt;</span><br />
<span style="color: #000066; font-weight: bold;">&lt;/</span>head<span style="color: #000066; font-weight: bold;">&gt;&lt;</span>body<span style="color: #000066; font-weight: bold;">&gt;</span><br />
<span style="color: #000066; font-weight: bold;">&lt;</span>h1<span style="color: #000066; font-weight: bold;">&gt;</span><span style="color: #000000;">&#123;</span><span style="color: #000000; font-weight:bold;">1</span><span style="color: #000000;">&#125;</span><span style="color: #000066; font-weight: bold;">&lt;/</span>h1<span style="color: #000066; font-weight: bold;">&gt;</span><br />
<span style="color: #000066; font-weight: bold;">&lt;</span>p<span style="color: #000066; font-weight: bold;">&gt;</span><span style="color: #000000;">&#123;</span><span style="color: #000000; font-weight:bold;">2</span><span style="color: #000000;">&#125;</span><span style="color: #000066; font-weight: bold;">&lt;/</span>p<span style="color: #000066; font-weight: bold;">&gt;</span><br />
<span style="color: #000066; font-weight: bold;">&lt;/</span>body<span style="color: #000066; font-weight: bold;">&gt;&lt;/</span>html<span style="color: #000066; font-weight: bold;">&gt;</span></div></div>
<p>Note that using the [Embed] metadata instructs the compiler to link the file content at compile time, making our code completely synchronous.</p>
<p>Also note that we&#8217;re substituting the parameters using the order, it&#8217;d would fairly easy to do a named-parameter subsitution instead (i.e. using tokens like ${var1})</p>
<p>Finally, in MXML you can use this other technique to compile an external text file:</p>
<div class="codecolorer-container actionscript3 mac-classic" style="overflow:auto;white-space:nowrap;border: 1px solid #9F9F9F;width:515px;"><div class="actionscript3 codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #000066; font-weight: bold;">&lt;</span>fx<span style="color: #000066; font-weight: bold;">:</span><a href="http://www.google.com/search?q=string%20inurl:http://livedocs.adobe.com/flex/201/langref/%20inurl:string.html"><span style="color: #004993;">String</span></a> id=<span style="color: #990000;">&quot;template&quot;</span> <span style="color: #004993;">source</span>=<span style="color: #990000;">&quot;path/to/your/template.txt&quot;</span><span style="color: #000066; font-weight: bold;">/&gt;</span></div></div>
]]></content:encoded>
			<wfw:commentRss>http://www.rialvalue.com/blog/2010/05/10/string-templating-in-flex/feed/</wfw:commentRss>
		<slash:comments>7</slash:comments>
		</item>
		<item>
		<title>DualPanel Reversible Component</title>
		<link>http://www.rialvalue.com/blog/2010/05/05/dualpanel-reversible-component/</link>
		<comments>http://www.rialvalue.com/blog/2010/05/05/dualpanel-reversible-component/#comments</comments>
		<pubDate>Wed, 05 May 2010 17:01:44 +0000</pubDate>
		<dc:creator>Xavi Beumala</dc:creator>
				<category><![CDATA[architecture]]></category>
		<category><![CDATA[components]]></category>
		<category><![CDATA[flex]]></category>
		<category><![CDATA[tips]]></category>

		<guid isPermaLink="false">http://www.rialvalue.com/blog/?p=173</guid>
		<description><![CDATA[This week I&#8217;ve been discussing with Alberto from undefined.es different ways to implement a reversible panel. Basically a reversible panel would be a 2-sides panel. In the front part you could have the component or widget and in the back you could have a configuration panel (same concept as in the OSX Dashboard widgets).
One way [...]]]></description>
			<content:encoded><![CDATA[<p>This week I&#8217;ve been discussing with Alberto from <a href="http://www.undefined.es">undefined.es</a> different ways to implement a reversible panel. Basically a reversible panel would be a 2-sides panel. In the front part you could have the component or widget and in the back you could have a configuration panel (same concept as in the OSX Dashboard widgets).</p>
<p>One way to implement it, would be as an extended concept of <a href="http://www.rialvalue.com/blog/2010/05/05">a template component as explained in my previous post</a>. It would basically be a template component with 2 customizable areas: the frontView and the backView. As a developer I&#8217;d then use it like:</p>
<div class="codecolorer-container actionscript3 mac-classic" style="overflow:auto;white-space:nowrap;border: 1px solid #9F9F9F;width:515px;"><div class="actionscript3 codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #000066; font-weight: bold;">&lt;</span>dualpanel<span style="color: #000066; font-weight: bold;">:</span>DualPanel <br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #004993;">width</span>=<span style="color: #990000;">&quot;200&quot;</span> <span style="color: #004993;">height</span>=<span style="color: #990000;">&quot;200&quot;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; transitionDuration=<span style="color: #990000;">&quot;200&quot;</span><span style="color: #000066; font-weight: bold;">&gt;</span><br />
<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000066; font-weight: bold;">&lt;</span>dualpanel<span style="color: #000066; font-weight: bold;">:</span>frontView<span style="color: #000066; font-weight: bold;">&gt;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000066; font-weight: bold;">&lt;</span>local<span style="color: #000066; font-weight: bold;">:</span>SampleComponent <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #004993;">width</span>=<span style="color: #990000;">&quot;100%&quot;</span> <span style="color: #004993;">height</span>=<span style="color: #990000;">&quot;100%&quot;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #004993;">backgroundColor</span>=<span style="color: #990000;">&quot;0x000000&quot;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; label=<span style="color: #990000;">&quot;Front&quot;</span><span style="color: #000066; font-weight: bold;">/&gt;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000066; font-weight: bold;">&lt;/</span>dualpanel<span style="color: #000066; font-weight: bold;">:</span>frontView<span style="color: #000066; font-weight: bold;">&gt;</span><br />
<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000066; font-weight: bold;">&lt;</span>dualpanel<span style="color: #000066; font-weight: bold;">:</span>backView<span style="color: #000066; font-weight: bold;">&gt;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000066; font-weight: bold;">&lt;</span>local<span style="color: #000066; font-weight: bold;">:</span>SampleComponent <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #004993;">width</span>=<span style="color: #990000;">&quot;100%&quot;</span> <span style="color: #004993;">height</span>=<span style="color: #990000;">&quot;100%&quot;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #004993;">backgroundColor</span>=<span style="color: #990000;">&quot;0x999999&quot;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; label=<span style="color: #990000;">&quot;Back&quot;</span><span style="color: #000066; font-weight: bold;">/&gt;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000066; font-weight: bold;">&lt;/</span>dualpanel<span style="color: #000066; font-weight: bold;">:</span>backView<span style="color: #000066; font-weight: bold;">&gt;</span><br />
<span style="color: #000066; font-weight: bold;">&lt;/</span>dualpanel<span style="color: #000066; font-weight: bold;">:</span>DualPanel<span style="color: #000066; font-weight: bold;">&gt;</span></div></div>
<p>The interesting thing about this component is that there&#8217;re a bunch of different ways to present 2 panels and to transition between them i.e. flip, wipe, zoom, etc. If we encapsulate the logic of having 2 areas or content holders we can extract the presentation or view customizations into skins. </p>
<p><a href="http://www.rialvalue.com/components/dualpanel/">See sample fullScreen</a><br />
<a href="http://www.rialvalue.com/components/dualpanel/srcview">Browse code.</a></p>
<p>The component is implemented using states, although it could be implemented without using states to prevent the views to be mutually exclusive, the base idea would be essentially the same: define contentHolders where we addElements set in certain properties.</p>
<p>A very interesting feature we still to add is deferred instantiation of the frontView and backView. By typing frontView and backView as IDeferredInstance will prevent the application from paying the cost of initializing the views until the user actually wants to see them. This means that if the user doesn&#8217;t click on the button the back view won&#8217;t be instantiated. </p>
<p>
<object width="525" height="350">
<param name="movie" value="http://www.rialvalue.com/components/deferreddualpanel/Main.swf" />
<param name="quality" value="high" />
<param name="wmode" value="window" />
<param name="menu" value="false" />
<param name="bgcolor" value="#FFFFFF" />
<param name="allowFullScreen" value="true"></param>
<embed type="application/x-shockwave-flash" width="525" height="350" src="http://www.rialvalue.com/components/deferreddualpanel/Main.swf" quality="high" bgcolor="#FFFFFF" wmode="window" menu="false" allowFullScreen="true" ></embed>
</object>
</p>
<p><a href="http://www.rialvalue.com/components/deferreddualpanel/">See sample fullScreen</a><br />
<a href="http://www.rialvalue.com/components/deferreddualpanel/srcview">Browse code.</a></p>
<p>If you use this component make sure you grab the one with deferred instantiation.</p>
<p>This is just a proof of concept and the code might have some problems. You can use it at your own risk.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.rialvalue.com/blog/2010/05/05/dualpanel-reversible-component/feed/</wfw:commentRss>
		<slash:comments>9</slash:comments>
		</item>
		<item>
		<title>Template Components in Flex4</title>
		<link>http://www.rialvalue.com/blog/2010/05/05/template-components-in-flex4/</link>
		<comments>http://www.rialvalue.com/blog/2010/05/05/template-components-in-flex4/#comments</comments>
		<pubDate>Wed, 05 May 2010 17:01:32 +0000</pubDate>
		<dc:creator>Xavi Beumala</dc:creator>
				<category><![CDATA[architecture]]></category>
		<category><![CDATA[components]]></category>
		<category><![CDATA[flex]]></category>
		<category><![CDATA[component]]></category>
		<category><![CDATA[flex4]]></category>
		<category><![CDATA[template]]></category>

		<guid isPermaLink="false">http://www.rialvalue.com/blog/?p=171</guid>
		<description><![CDATA[Template Components can be quite common in different sort of applications. Maybe the most common one is the Panel, which has a predefined set of components (title bar, status bar, close button, etc) and an specific area where we can instantiate any other component we wish.
In Flex3 you could use the technique explained in the [...]]]></description>
			<content:encoded><![CDATA[<p>Template Components can be quite common in different sort of applications. Maybe the most common one is the Panel, which has a predefined set of components (title bar, status bar, close button, etc) and an specific area where we can instantiate any other component we wish.</p>
<p>In Flex3 you could use the technique <a href="http://livedocs.adobe.com/flex/3/html/help.html?content=templating_1.html">explained in the Flex documentation</a> in combination with [DefaultProperty] metadata. The technique basically consists in creating a subclass of a Container component who defines properties with a general data type that lets the component user specify an object of a concrete data type and then reparents it.</p>
<p>Flex4 Skins, by definition, serve the purpose of a templating system. If you consider the example of a s:Panel you have the PanelSkin where you can really easily change and adapt the template and where and how the provided / customizable content will be placed.</p>
<p>If you have to create a templated component with just one customizable area, maybe the best approach to create it would be to use an s:SkinnableComponent. In the following example I&#8217;ve created a very simple template that places a header an a footer around a given component.</p>
<div class="codecolorer-container actionscript3 mac-classic" style="overflow:auto;white-space:nowrap;border: 1px solid #9F9F9F;width:515px;height:330px;"><div class="actionscript3 codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #000066; font-weight: bold;">&lt;?</span>xml <span style="color: #004993;">version</span>=<span style="color: #990000;">&quot;1.0&quot;</span> encoding=<span style="color: #990000;">&quot;utf-8&quot;</span><span style="color: #000066; font-weight: bold;">?&gt;</span><br />
<span style="color: #000066; font-weight: bold;">&lt;</span>s<span style="color: #000066; font-weight: bold;">:</span>Application <br />
&nbsp; &nbsp; minWidth=<span style="color: #990000;">&quot;955&quot;</span> minHeight=<span style="color: #990000;">&quot;600&quot;</span><br />
&nbsp; &nbsp; xmlns<span style="color: #000066; font-weight: bold;">:</span>fx=<span style="color: #990000;">&quot;http://ns.adobe.com/mxml/2009&quot;</span><br />
&nbsp; &nbsp; xmlns<span style="color: #000066; font-weight: bold;">:</span>s=<span style="color: #990000;">&quot;library://ns.adobe.com/flex/spark&quot;</span><br />
&nbsp; &nbsp; xmlns<span style="color: #000066; font-weight: bold;">:</span>mx=<span style="color: #990000;">&quot;library://ns.adobe.com/flex/mx&quot;</span><br />
&nbsp; &nbsp; xmlns<span style="color: #000066; font-weight: bold;">:</span>local=<span style="color: #990000;">&quot;*&quot;</span><span style="color: #000066; font-weight: bold;">&gt;</span><br />
<br />
&nbsp; &nbsp; <span style="color: #000066; font-weight: bold;">&lt;</span>s<span style="color: #000066; font-weight: bold;">:</span>layout<span style="color: #000066; font-weight: bold;">&gt;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000066; font-weight: bold;">&lt;</span>s<span style="color: #000066; font-weight: bold;">:</span>VerticalLayout <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; horizontalAlign=<span style="color: #990000;">&quot;center&quot;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; verticalAlign=<span style="color: #990000;">&quot;middle&quot;</span><span style="color: #000066; font-weight: bold;">/&gt;</span><br />
&nbsp; &nbsp; <span style="color: #000066; font-weight: bold;">&lt;/</span>s<span style="color: #000066; font-weight: bold;">:</span>layout<span style="color: #000066; font-weight: bold;">&gt;</span><br />
<br />
&nbsp; &nbsp; <span style="color: #000066; font-weight: bold;">&lt;</span>s<span style="color: #000066; font-weight: bold;">:</span>SkinnableContainer <br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #004993;">width</span>=<span style="color: #990000;">&quot;200&quot;</span> <span style="color: #004993;">height</span>=<span style="color: #990000;">&quot;200&quot;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; skinClass=<span style="color: #990000;">&quot;TemplateSkin1&quot;</span><span style="color: #000066; font-weight: bold;">&gt;</span><br />
<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000066; font-weight: bold;">&lt;</span>local<span style="color: #000066; font-weight: bold;">:</span>MyComponent <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #004993;">width</span>=<span style="color: #990000;">&quot;100%&quot;</span> <span style="color: #004993;">height</span>=<span style="color: #990000;">&quot;100%&quot;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #004993;">backgroundColor</span>=<span style="color: #990000;">&quot;0xff0000&quot;</span><span style="color: #000066; font-weight: bold;">/&gt;</span><br />
<br />
&nbsp; &nbsp; <span style="color: #000066; font-weight: bold;">&lt;/</span>s<span style="color: #000066; font-weight: bold;">:</span>SkinnableContainer<span style="color: #000066; font-weight: bold;">&gt;</span><br />
<br />
&nbsp; &nbsp; <span style="color: #000066; font-weight: bold;">&lt;</span>s<span style="color: #000066; font-weight: bold;">:</span>SkinnableContainer <br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #004993;">width</span>=<span style="color: #990000;">&quot;200&quot;</span> <span style="color: #004993;">height</span>=<span style="color: #990000;">&quot;200&quot;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; skinClass=<span style="color: #990000;">&quot;TemplateSkin1&quot;</span><span style="color: #000066; font-weight: bold;">&gt;</span><br />
<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000066; font-weight: bold;">&lt;</span>local<span style="color: #000066; font-weight: bold;">:</span>MyComponent <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #004993;">width</span>=<span style="color: #990000;">&quot;100%&quot;</span> <span style="color: #004993;">height</span>=<span style="color: #990000;">&quot;100%&quot;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #004993;">backgroundColor</span>=<span style="color: #990000;">&quot;0x00ff00&quot;</span><span style="color: #000066; font-weight: bold;">/&gt;</span><br />
<br />
&nbsp; &nbsp; <span style="color: #000066; font-weight: bold;">&lt;/</span>s<span style="color: #000066; font-weight: bold;">:</span>SkinnableContainer<span style="color: #000066; font-weight: bold;">&gt;</span><br />
<span style="color: #000066; font-weight: bold;">&lt;/</span>s<span style="color: #000066; font-weight: bold;">:</span>Application<span style="color: #000066; font-weight: bold;">&gt;</span></div></div>
<p>Where TemplateSkin1 is:</p>
<div class="codecolorer-container actionscript3 mac-classic" style="overflow:auto;white-space:nowrap;border: 1px solid #9F9F9F;width:515px;height:330px;"><div class="actionscript3 codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #000066; font-weight: bold;">&lt;?</span>xml <span style="color: #004993;">version</span>=<span style="color: #990000;">&quot;1.0&quot;</span> encoding=<span style="color: #990000;">&quot;utf-8&quot;</span><span style="color: #000066; font-weight: bold;">?&gt;</span><br />
<span style="color: #000066; font-weight: bold;">&lt;</span>s<span style="color: #000066; font-weight: bold;">:</span>Skin xmlns<span style="color: #000066; font-weight: bold;">:</span>fx=<span style="color: #990000;">&quot;http://ns.adobe.com/mxml/2009&quot;</span><br />
&nbsp; &nbsp; xmlns<span style="color: #000066; font-weight: bold;">:</span>s=<span style="color: #990000;">&quot;library://ns.adobe.com/flex/spark&quot;</span><br />
&nbsp; &nbsp; <span style="color: #004993;">alpha</span><span style="color: #000066; font-weight: bold;">.</span>disabled=<span style="color: #990000;">&quot;0.5&quot;</span><br />
&nbsp; &nbsp; xmlns<span style="color: #000066; font-weight: bold;">:</span>local=<span style="color: #990000;">&quot;*&quot;</span><span style="color: #000066; font-weight: bold;">&gt;</span><br />
<br />
&nbsp; &nbsp; <span style="color: #000066; font-weight: bold;">&lt;</span>fx<span style="color: #000066; font-weight: bold;">:</span>Metadata<span style="color: #000066; font-weight: bold;">&gt;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000066; font-weight: bold;">&lt;!</span><span style="color: #000000;">&#91;</span>CDATA<span style="color: #000000;">&#91;</span> <br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000;">&#91;</span>HostComponent<span style="color: #000000;">&#40;</span><span style="color: #990000;">&quot;spark.components.SkinnableContainer&quot;</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">&#93;</span><br />
&nbsp; &nbsp; <span style="color: #000000;">&#93;</span><span style="color: #000000;">&#93;</span><span style="color: #000066; font-weight: bold;">&gt;</span><br />
&nbsp; &nbsp; <span style="color: #000066; font-weight: bold;">&lt;/</span>fx<span style="color: #000066; font-weight: bold;">:</span>Metadata<span style="color: #000066; font-weight: bold;">&gt;</span><br />
<br />
&nbsp; &nbsp; <span style="color: #000066; font-weight: bold;">&lt;</span>s<span style="color: #000066; font-weight: bold;">:</span>states<span style="color: #000066; font-weight: bold;">&gt;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000066; font-weight: bold;">&lt;</span>s<span style="color: #000066; font-weight: bold;">:</span>State <span style="color: #004993;">name</span>=<span style="color: #990000;">&quot;normal&quot;</span><span style="color: #000066; font-weight: bold;">/&gt;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000066; font-weight: bold;">&lt;</span>s<span style="color: #000066; font-weight: bold;">:</span>State <span style="color: #004993;">name</span>=<span style="color: #990000;">&quot;disabled&quot;</span><span style="color: #000066; font-weight: bold;">/&gt;</span><br />
&nbsp; &nbsp; <span style="color: #000066; font-weight: bold;">&lt;/</span>s<span style="color: #000066; font-weight: bold;">:</span>states<span style="color: #000066; font-weight: bold;">&gt;</span><br />
<br />
&nbsp; &nbsp; <span style="color: #000066; font-weight: bold;">&lt;</span>s<span style="color: #000066; font-weight: bold;">:</span>layout<span style="color: #000066; font-weight: bold;">&gt;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000066; font-weight: bold;">&lt;</span>s<span style="color: #000066; font-weight: bold;">:</span>VerticalLayout gap=<span style="color: #990000;">&quot;0&quot;</span><span style="color: #000066; font-weight: bold;">/&gt;</span><br />
&nbsp; &nbsp; <span style="color: #000066; font-weight: bold;">&lt;/</span>s<span style="color: #000066; font-weight: bold;">:</span>layout<span style="color: #000066; font-weight: bold;">&gt;</span><br />
<br />
&nbsp; &nbsp; <span style="color: #000066; font-weight: bold;">&lt;</span>local<span style="color: #000066; font-weight: bold;">:</span>Bar <br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #004993;">width</span>=<span style="color: #990000;">&quot;100%&quot;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #004993;">text</span>=<span style="color: #990000;">&quot;Header&quot;</span><span style="color: #000066; font-weight: bold;">/&gt;</span><br />
<br />
&nbsp; &nbsp; <span style="color: #000066; font-weight: bold;">&lt;</span>s<span style="color: #000066; font-weight: bold;">:</span>Group id=<span style="color: #990000;">&quot;contentGroup&quot;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #004993;">width</span>=<span style="color: #990000;">&quot;100%&quot;</span> <span style="color: #004993;">height</span>=<span style="color: #990000;">&quot;100%&quot;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; minWidth=<span style="color: #990000;">&quot;0&quot;</span> minHeight=<span style="color: #990000;">&quot;0&quot;</span><span style="color: #000066; font-weight: bold;">&gt;</span><br />
<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000066; font-weight: bold;">&lt;</span>s<span style="color: #000066; font-weight: bold;">:</span>layout<span style="color: #000066; font-weight: bold;">&gt;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000066; font-weight: bold;">&lt;</span>s<span style="color: #000066; font-weight: bold;">:</span>BasicLayout<span style="color: #000066; font-weight: bold;">/&gt;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000066; font-weight: bold;">&lt;/</span>s<span style="color: #000066; font-weight: bold;">:</span>layout<span style="color: #000066; font-weight: bold;">&gt;</span><br />
&nbsp; &nbsp; <span style="color: #000066; font-weight: bold;">&lt;/</span>s<span style="color: #000066; font-weight: bold;">:</span>Group<span style="color: #000066; font-weight: bold;">&gt;</span><br />
<br />
&nbsp; &nbsp; <span style="color: #000066; font-weight: bold;">&lt;</span>local<span style="color: #000066; font-weight: bold;">:</span>Bar <br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #004993;">width</span>=<span style="color: #990000;">&quot;100%&quot;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #004993;">text</span>=<span style="color: #990000;">&quot;Footer&quot;</span><span style="color: #000066; font-weight: bold;">/&gt;</span><br />
<span style="color: #000066; font-weight: bold;">&lt;/</span>s<span style="color: #000066; font-weight: bold;">:</span>Skin<span style="color: #000066; font-weight: bold;">&gt;</span></div></div>
<p>The SkinnableContainer base class provides a series of functionalities like creationPolicy and layout property proxying or deferred instantiation that makes very easy the task of creating templated components.</p>
<p>
<object width="525" height="500">
<param name="movie" value="http://www.rialvalue.com/components/templating/templating.swf" />
<param name="quality" value="high" />
<param name="wmode" value="window" />
<param name="menu" value="false" />
<param name="bgcolor" value="#FFFFFF" />
<param name="allowFullScreen" value="true"></param>
<embed type="application/x-shockwave-flash" width="525" height="500" src="http://www.rialvalue.com/components/templating/templating.swf" quality="high" bgcolor="#FFFFFF" wmode="window" menu="false" allowFullScreen="true" ></embed>
</object>
</p>
<p><a href="http://www.rialvalue.com/components/templating/">See sample fullScreen</a><br />
<a href="http://www.rialvalue.com/components/templating/srcview">Browse code.</a></p>
<p>In more complex scenarios where the template has more than one customizable area SkinnableContainer might not be the best choice. You can find further information about this scenario in the <a href="http://www.rialvalue.com/blog/2010/05/05/dualpanel-reversible-component/">DualPanel component post</a>.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.rialvalue.com/blog/2010/05/05/template-components-in-flex4/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Logging and catching (async) exceptions during invalidation</title>
		<link>http://www.rialvalue.com/blog/2009/08/25/logging-and-catching-exceptions-during-invalidation/</link>
		<comments>http://www.rialvalue.com/blog/2009/08/25/logging-and-catching-exceptions-during-invalidation/#comments</comments>
		<pubDate>Tue, 25 Aug 2009 12:21:44 +0000</pubDate>
		<dc:creator>Xavi Beumala</dc:creator>
				<category><![CDATA[architecture]]></category>
		<category><![CDATA[components]]></category>
		<category><![CDATA[flex]]></category>
		<category><![CDATA[testing]]></category>
		<category><![CDATA[tips]]></category>
		<category><![CDATA[actionscript]]></category>
		<category><![CDATA[error handling]]></category>
		<category><![CDATA[logging]]></category>

		<guid isPermaLink="false">http://www.rialvalue.com/blog/?p=81</guid>
		<description><![CDATA[Sometimes, due to many different reasons, there&#8217;re exceptions that happen during the invalidation/validation cycle of the flex SDK. Most times these exceptions end up being unveiled in the very core of the SDK, being not possible to catch them up because their async nature and the place where they happen.
The stacktrace of these exceptiosn, normally, [...]]]></description>
			<content:encoded><![CDATA[<p>Sometimes, due to many different reasons, there&#8217;re exceptions that happen during the invalidation/validation cycle of the flex SDK. Most times these exceptions end up being unveiled in the very core of the SDK, being not possible to catch them up because their async nature and the place where they happen.</p>
<p>The stacktrace of these exceptiosn, normally, looks like the lines below:</p>
<div class="codecolorer-container text mac-classic" style="overflow:auto;white-space:nowrap;border: 1px solid #9F9F9F;width:515px;"><div class="text codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">...<br />
at mx.core::UIComponent/validateProperties()[C:\autobuild\3.x\frameworks\projects\framework\src\mx\core\UIComponent.as:5807]<br />
at mx.managers::LayoutManager/validateProperties()[C:\autobuild\3.x\frameworks\projects\framework\src\mx\managers\LayoutManager.as:539]<br />
at mx.managers::LayoutManager/doPhasedInstantiation()[C:\autobuild\3.x\frameworks\projects\framework\src\mx\managers\LayoutManager.as:689]<br />
at Function/http://adobe.com/AS3/2006/builtin::apply()<br />
at mx.core::UIComponent/callLaterDispatcher2()[C:\autobuild\3.x\frameworks\projects\framework\src\mx\core\UIComponent.as:8633]<br />
at mx.core::UIComponent/callLaterDispatcher()[C:\autobuild\3.x\frameworks\projects\framework\src\mx\core\UIComponent.as:8582]</div></div>
<p>Today, snooping around the UIComponent class, I&#8217;ve found a nice unexpected thing. Basically the invalidation pattern in the SDK is built around the LayoutManager and the UIComponent classes. The callLater method is the responsible to delay the execution of certain functionalities to the next frame. callLater implementation relies on the RENDER and ENTER_FRAME frames. The handler for these events is the method callLaterDispatcher.</p>
<div class="codecolorer-container actionscript3 mac-classic" style="overflow:auto;white-space:nowrap;border: 1px solid #9F9F9F;width:515px;height:330px;"><div class="actionscript3 codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #009900; font-style: italic;">// At run-time, callLaterDispatcher2() is called</span><br />
<span style="color: #009900; font-style: italic;">// without a surrounding try-catch.</span><br />
<span style="color: #0033ff; font-weight: bold;">if</span> <span style="color: #000000;">&#40;</span><span style="color: #000066; font-weight: bold;">!</span>UIComponentGlobals<span style="color: #000066; font-weight: bold;">.</span>catchCallLaterExceptions<span style="color: #000000;">&#41;</span><br />
<span style="color: #000000;">&#123;</span><br />
&nbsp; &nbsp; callLaterDispatcher2<span style="color: #000000;">&#40;</span>event<span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span><br />
<span style="color: #000000;">&#125;</span><br />
<br />
<span style="color: #009900; font-style: italic;">// At design-time, callLaterDispatcher2() is called</span><br />
<span style="color: #009900; font-style: italic;">// with a surrounding try-catch.</span><br />
<span style="color: #0033ff; font-weight: bold;">else</span><br />
<span style="color: #000000;">&#123;</span><br />
&nbsp; &nbsp; <span style="color: #0033ff; font-weight: bold;">try</span><br />
&nbsp; &nbsp; <span style="color: #000000;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; callLaterDispatcher2<span style="color: #000000;">&#40;</span>event<span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span><br />
&nbsp; &nbsp; <span style="color: #000000;">&#125;</span><br />
&nbsp; &nbsp; <span style="color: #0033ff; font-weight: bold;">catch</span><span style="color: #000000;">&#40;</span>e<span style="color: #000066; font-weight: bold;">:</span><a href="http://www.google.com/search?q=error%20inurl:http://livedocs.adobe.com/flex/201/langref/%20inurl:error.html"><span style="color: #004993;">Error</span></a><span style="color: #000000;">&#41;</span><br />
&nbsp; &nbsp; <span style="color: #000000;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #6699cc; font-weight: bold;">var</span> callLaterErrorEvent<span style="color: #000066; font-weight: bold;">:</span>DynamicEvent = <span style="color: #0033ff; font-weight: bold;">new</span> DynamicEvent<span style="color: #000000;">&#40;</span><span style="color: #990000;">&quot;callLaterError&quot;</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; callLaterErrorEvent<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">error</span> = e<span style="color: #000066; font-weight: bold;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; systemManager<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">dispatchEvent</span><span style="color: #000000;">&#40;</span>callLaterErrorEvent<span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span><br />
&nbsp; &nbsp; <span style="color: #000000;">&#125;</span><br />
<span style="color: #000000;">&#125;</span></div></div>
<p>Here&#8217;s the surprise. If UIComponentGlobals.catchCallLaterExceptions is true, the execution of the validation cycle will be wrapped with a try..catch and a DynamicEvent will be dispatched through the systemManager with information about the error.</p>
<p>This opens the doors for at least catch the error and log it. In some cases, depending on the severity of the error and if the application is not too corrupted, we&#8217;ll even be able to display a message to the user notifying him the error. This is not a fix to <a href="http://bugs.adobe.com/jira/browse/FP-1499">FP-1499</a> nor <a href="http://bugs.adobe.com/jira/browse/FP-444">FP-444</a> but under some circumstances it can be really helpful if combined with <a href="http://blogs.adobe.com/tomsugden/2009/08/best_practices_for_the_flex_lo.html">great logging practices as explained by Tom</a>.</p>
<p>I&#8217;ve created a simple class that hooks into the systemManager, listens for the callLaterError event and logs it using the standard SDK logging mechanism. The AsyncErrorLogger is MXML friendly so that it can be instantiated in the root application. It provides an enable property to switch the behavior on and off. Additionally the property redispatchErrorEvent, which by default is false, redispatches the error causing the traditional flash player error dialog to appear (in debugger player versions) and not fail silently.</p>
<p>Here&#8217;s an example on how to use it:</p>
<div class="codecolorer-container xml mac-classic" style="overflow:auto;white-space:nowrap;border: 1px solid #9F9F9F;width:515px;height:330px;"><div class="xml codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;?xml</span> version = <span style="color: #ff0000;">&quot;1.0&quot;</span> encoding = <span style="color: #ff0000;">&quot;utf-8&quot;</span><span style="color: #000000; font-weight: bold;">?&gt;</span></span><br />
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;mx:WindowedApplication</span> xmlns:mx = <span style="color: #ff0000;">&quot;http://www.adobe.com/2006/mxml&quot;</span> xmlns:utils = <span style="color: #ff0000;">&quot;com.adobe.ac.utils.*&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span><br />
<br />
&nbsp; &nbsp; <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;mx:Script<span style="color: #000000; font-weight: bold;">&gt;</span></span></span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #339933;">&lt;![CDATA[</span><br />
<span style="color: #339933;"> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;import mx.logging.LogEventLevel;</span><br />
<span style="color: #339933;"> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;</span><br />
<span style="color: #339933;"> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;//---------------------------------------------</span><br />
<span style="color: #339933;"> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;// THAT'S THE WAY TO SIMULATE THE ASYNC ERROR</span><br />
<span style="color: #339933;"> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;//---------------------------------------------</span><br />
<span style="color: #339933;"> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;</span><br />
<span style="color: #339933;"> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;private var doItChange : Boolean = false;</span><br />
<span style="color: #339933;"> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;</span><br />
<span style="color: #339933;"> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;private function doIt() : void </span><br />
<span style="color: #339933;"> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;{</span><br />
<span style="color: #339933;"> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;doItChange = true;</span><br />
<span style="color: #339933;"> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;invalidateProperties();</span><br />
<span style="color: #339933;"> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;}</span><br />
<span style="color: #339933;"> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;</span><br />
<span style="color: #339933;"> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;override protected function commitProperties() : void{</span><br />
<span style="color: #339933;"> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;super.commitProperties();</span><br />
<span style="color: #339933;"> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;</span><br />
<span style="color: #339933;"> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;if( doItChange )</span><br />
<span style="color: #339933;"> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;{</span><br />
<span style="color: #339933;"> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;doItChange = false;</span><br />
<span style="color: #339933;"> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;throw new Error(&quot;CallLater exception&quot;);</span><br />
<span style="color: #339933;"> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;}</span><br />
<span style="color: #339933;"> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;}</span><br />
<span style="color: #339933;"> &nbsp; &nbsp; &nbsp; &nbsp;]]&gt;</span><br />
&nbsp; &nbsp; <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/mx:Script<span style="color: #000000; font-weight: bold;">&gt;</span></span></span><br />
<br />
&nbsp; &nbsp; <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;mx:TraceTarget</span> level = <span style="color: #ff0000;">&quot;{ LogEventLevel.ALL }&quot;</span><span style="color: #000000; font-weight: bold;">/&gt;</span></span><br />
<br />
&nbsp; &nbsp; <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;utils:AsyncErrorLogger</span><span style="color: #000000; font-weight: bold;">/&gt;</span></span><br />
<br />
&nbsp; &nbsp; <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;mx:Button</span> click = <span style="color: #ff0000;">&quot;doIt()&quot;</span> label = <span style="color: #ff0000;">&quot;Throw exception&quot;</span><span style="color: #000000; font-weight: bold;">/&gt;</span></span><br />
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/mx:WindowedApplication<span style="color: #000000; font-weight: bold;">&gt;</span></span></span></div></div>
<p>Here&#8217;s the code. <a href="http://www.rialvalue.com/downloads/AsyncErrorLogger.as">You can download the class from here as well</a>.</p>
<div class="codecolorer-container actionscript3 mac-classic" style="overflow:auto;white-space:nowrap;border: 1px solid #9F9F9F;width:515px;height:330px;"><div class="actionscript3 codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #9900cc; font-weight: bold;">package</span> com<span style="color: #000066; font-weight: bold;">.</span>adobe<span style="color: #000066; font-weight: bold;">.</span>ac<span style="color: #000066; font-weight: bold;">.</span>utils<br />
<span style="color: #000000;">&#123;</span><br />
&nbsp; &nbsp; <span style="color: #0033ff; font-weight: bold;">import</span> <span style="color: #004993;">flash.events</span><span style="color: #000066; font-weight: bold;">.</span><a href="http://www.google.com/search?q=errorevent%20inurl:http://livedocs.adobe.com/flex/201/langref/%20inurl:errorevent.html"><span style="color: #004993;">ErrorEvent</span></a><span style="color: #000066; font-weight: bold;">;</span><br />
&nbsp; &nbsp; <span style="color: #0033ff; font-weight: bold;">import</span> <span style="color: #004993;">flash.events</span><span style="color: #000066; font-weight: bold;">.</span><a href="http://www.google.com/search?q=eventdispatcher%20inurl:http://livedocs.adobe.com/flex/201/langref/%20inurl:eventdispatcher.html"><span style="color: #004993;">EventDispatcher</span></a><span style="color: #000066; font-weight: bold;">;</span><br />
<br />
&nbsp; &nbsp; <span style="color: #0033ff; font-weight: bold;">import</span> mx<span style="color: #000066; font-weight: bold;">.</span>core<span style="color: #000066; font-weight: bold;">.</span>Application<span style="color: #000066; font-weight: bold;">;</span><br />
&nbsp; &nbsp; <span style="color: #0033ff; font-weight: bold;">import</span> mx<span style="color: #000066; font-weight: bold;">.</span>core<span style="color: #000066; font-weight: bold;">.</span>UIComponentGlobals<span style="color: #000066; font-weight: bold;">;</span><br />
&nbsp; &nbsp; <span style="color: #0033ff; font-weight: bold;">import</span> mx<span style="color: #000066; font-weight: bold;">.</span>events<span style="color: #000066; font-weight: bold;">.</span>DynamicEvent<span style="color: #000066; font-weight: bold;">;</span><br />
&nbsp; &nbsp; <span style="color: #0033ff; font-weight: bold;">import</span> mx<span style="color: #000066; font-weight: bold;">.</span>events<span style="color: #000066; font-weight: bold;">.</span>FlexEvent<span style="color: #000066; font-weight: bold;">;</span><br />
&nbsp; &nbsp; <span style="color: #0033ff; font-weight: bold;">import</span> mx<span style="color: #000066; font-weight: bold;">.</span>logging<span style="color: #000066; font-weight: bold;">.</span>ILogger<span style="color: #000066; font-weight: bold;">;</span><br />
&nbsp; &nbsp; <span style="color: #0033ff; font-weight: bold;">import</span> mx<span style="color: #000066; font-weight: bold;">.</span>logging<span style="color: #000066; font-weight: bold;">.</span>Log<span style="color: #000066; font-weight: bold;">;</span><br />
&nbsp; &nbsp; <span style="color: #0033ff; font-weight: bold;">import</span> mx<span style="color: #000066; font-weight: bold;">.</span>managers<span style="color: #000066; font-weight: bold;">.</span>ISystemManager<span style="color: #000066; font-weight: bold;">;</span><br />
<br />
&nbsp; &nbsp; <span style="color: #000000;">&#91;</span><a href="http://www.google.com/search?q=event%20inurl:http://livedocs.adobe.com/flex/201/langref/%20inurl:event.html"><span style="color: #004993;">Event</span></a><span style="color: #000000;">&#40;</span><span style="color: #004993;">name</span>=<span style="color: #990000;">&quot;error&quot;</span><span style="color: #000066; font-weight: bold;">,</span><span style="color: #004993;">type</span>=<span style="color: #990000;">&quot;flash.events.ErrorEvent&quot;</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">&#93;</span><br />
&nbsp; &nbsp; <span style="color: #0033ff; font-weight: bold;">public</span> <span style="color: #9900cc; font-weight: bold;">class</span> AsyncErrorLogger <span style="color: #0033ff; font-weight: bold;">extends</span> <a href="http://www.google.com/search?q=eventdispatcher%20inurl:http://livedocs.adobe.com/flex/201/langref/%20inurl:eventdispatcher.html"><span style="color: #004993;">EventDispatcher</span></a><br />
&nbsp; &nbsp; <span style="color: #000000;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900; font-style: italic;">//------------------------------------------------------------------------</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900; font-style: italic;">//</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900; font-style: italic;">// &nbsp;Constants</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900; font-style: italic;">//</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900; font-style: italic;">//------------------------------------------------------------------------</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0033ff; font-weight: bold;">private</span> static const CALL_LATER_ERROR<span style="color: #000066; font-weight: bold;">:</span><a href="http://www.google.com/search?q=string%20inurl:http://livedocs.adobe.com/flex/201/langref/%20inurl:string.html"><span style="color: #004993;">String</span></a> = <span style="color: #990000;">&quot;callLaterError&quot;</span><span style="color: #000066; font-weight: bold;">;</span><br />
<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0033ff; font-weight: bold;">private</span> static const LOG<span style="color: #000066; font-weight: bold;">:</span>ILogger = Log<span style="color: #000066; font-weight: bold;">.</span>getLogger<span style="color: #000000;">&#40;</span><span style="color: #990000;">&quot;com.adobe.cairngorm.AsyncErrorLogger&quot;</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span><br />
<br />
<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900; font-style: italic;">//------------------------------------------------------------------------</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900; font-style: italic;">//</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900; font-style: italic;">// &nbsp;Properties</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900; font-style: italic;">//</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900; font-style: italic;">//------------------------------------------------------------------------</span><br />
<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900; font-style: italic;">//-------------------------------</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900; font-style: italic;">// &nbsp;systemManager</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900; font-style: italic;">//-------------------------------</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0033ff; font-weight: bold;">private</span> <span style="color: #6699cc; font-weight: bold;">var</span> systemManager<span style="color: #000066; font-weight: bold;">:</span>ISystemManager<span style="color: #000066; font-weight: bold;">;</span><br />
<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900; font-style: italic;">//-------------------------------</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900; font-style: italic;">// &nbsp;logStackTrace</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900; font-style: italic;">//-------------------------------</span><br />
<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0033ff; font-weight: bold;">public</span> <span style="color: #6699cc; font-weight: bold;">var</span> logStackTrace<span style="color: #000066; font-weight: bold;">:</span><a href="http://www.google.com/search?q=boolean%20inurl:http://livedocs.adobe.com/flex/201/langref/%20inurl:boolean.html"><span style="color: #004993;">Boolean</span></a> = <span style="color: #0033ff; font-weight: bold;">true</span><span style="color: #000066; font-weight: bold;">;</span><br />
<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900; font-style: italic;">//-------------------------------</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900; font-style: italic;">// &nbsp;redispatchError</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900; font-style: italic;">//-------------------------------</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0033ff; font-weight: bold;">public</span> <span style="color: #6699cc; font-weight: bold;">var</span> redispatchError<span style="color: #000066; font-weight: bold;">:</span><a href="http://www.google.com/search?q=boolean%20inurl:http://livedocs.adobe.com/flex/201/langref/%20inurl:boolean.html"><span style="color: #004993;">Boolean</span></a> = <span style="color: #0033ff; font-weight: bold;">false</span><span style="color: #000066; font-weight: bold;">;</span><br />
<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900; font-style: italic;">//-------------------------------</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900; font-style: italic;">// &nbsp;enabled</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900; font-style: italic;">//-------------------------------</span><br />
<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000;">&#91;</span>Bindable<span style="color: #000000;">&#93;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0033ff; font-weight: bold;">public</span> <span style="color: #339966; font-weight: bold;">function</span> <span style="color: #0033ff; font-weight: bold;">get</span> <span style="color: #004993;">enabled</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">:</span><a href="http://www.google.com/search?q=boolean%20inurl:http://livedocs.adobe.com/flex/201/langref/%20inurl:boolean.html"><span style="color: #004993;">Boolean</span></a><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0033ff; font-weight: bold;">return</span> UIComponentGlobals<span style="color: #000066; font-weight: bold;">.</span>catchCallLaterExceptions<span style="color: #000066; font-weight: bold;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000;">&#125;</span><br />
<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0033ff; font-weight: bold;">public</span> <span style="color: #339966; font-weight: bold;">function</span> <span style="color: #0033ff; font-weight: bold;">set</span> <span style="color: #004993;">enabled</span><span style="color: #000000;">&#40;</span><span style="color: #004993;">value</span><span style="color: #000066; font-weight: bold;">:</span><a href="http://www.google.com/search?q=boolean%20inurl:http://livedocs.adobe.com/flex/201/langref/%20inurl:boolean.html"><span style="color: #004993;">Boolean</span></a><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">:</span><span style="color: #0033ff; font-weight: bold;">void</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; UIComponentGlobals<span style="color: #000066; font-weight: bold;">.</span>catchCallLaterExceptions = <span style="color: #004993;">value</span><span style="color: #000066; font-weight: bold;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000;">&#125;</span><br />
<br />
<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900; font-style: italic;">//------------------------------------------------------------------------</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900; font-style: italic;">//</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900; font-style: italic;">// &nbsp;Constructor</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900; font-style: italic;">//</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900; font-style: italic;">//------------------------------------------------------------------------</span><br />
<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0033ff; font-weight: bold;">public</span> <span style="color: #339966; font-weight: bold;">function</span> AsyncErrorLogger<span style="color: #000000;">&#40;</span>systemManager<span style="color: #000066; font-weight: bold;">:</span>ISystemManager = <span style="color: #0033ff; font-weight: bold;">null</span><span style="color: #000000;">&#41;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #004993;">enabled</span> = <span style="color: #0033ff; font-weight: bold;">true</span><span style="color: #000066; font-weight: bold;">;</span><br />
<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #004993;">init</span><span style="color: #000000;">&#40;</span>systemManager<span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000;">&#125;</span><br />
<br />
<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900; font-style: italic;">//------------------------------------------------------------------------</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900; font-style: italic;">//</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900; font-style: italic;">// &nbsp;Private Methods</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900; font-style: italic;">//</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900; font-style: italic;">//------------------------------------------------------------------------</span><br />
<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0033ff; font-weight: bold;">private</span> <span style="color: #339966; font-weight: bold;">function</span> <span style="color: #004993;">init</span><span style="color: #000000;">&#40;</span>systemManager<span style="color: #000066; font-weight: bold;">:</span>ISystemManager<span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">:</span><span style="color: #0033ff; font-weight: bold;">void</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0033ff; font-weight: bold;">if</span> <span style="color: #000000;">&#40;</span>systemManager<span style="color: #000000;">&#41;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; initializeListener<span style="color: #000000;">&#40;</span>systemManager<span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000;">&#125;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0033ff; font-weight: bold;">else</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #6699cc; font-weight: bold;">var</span> application<span style="color: #000066; font-weight: bold;">:</span><a href="http://www.google.com/search?q=object%20inurl:http://livedocs.adobe.com/flex/201/langref/%20inurl:object.html"><span style="color: #004993;">Object</span></a> = Application<span style="color: #000066; font-weight: bold;">.</span>application<span style="color: #000066; font-weight: bold;">;</span><br />
<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0033ff; font-weight: bold;">if</span> <span style="color: #000000;">&#40;</span><span style="color: #000066; font-weight: bold;">!</span>application<span style="color: #000066; font-weight: bold;">.</span>initialized<span style="color: #000000;">&#41;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; application<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">addEventListener</span><span style="color: #000000;">&#40;</span>FlexEvent<span style="color: #000066; font-weight: bold;">.</span>CREATION_COMPLETE<span style="color: #000066; font-weight: bold;">,</span> creationCompleteHandler<span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000;">&#125;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0033ff; font-weight: bold;">else</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; initializeListener<span style="color: #000000;">&#40;</span>application<span style="color: #000066; font-weight: bold;">.</span>systemManager<span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000;">&#125;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000;">&#125;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000;">&#125;</span><br />
<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0033ff; font-weight: bold;">private</span> <span style="color: #339966; font-weight: bold;">function</span> creationCompleteHandler<span style="color: #000000;">&#40;</span>event<span style="color: #000066; font-weight: bold;">:</span><a href="http://www.google.com/search?q=event%20inurl:http://livedocs.adobe.com/flex/201/langref/%20inurl:event.html"><span style="color: #004993;">Event</span></a><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">:</span><span style="color: #0033ff; font-weight: bold;">void</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #6699cc; font-weight: bold;">var</span> application<span style="color: #000066; font-weight: bold;">:</span><a href="http://www.google.com/search?q=object%20inurl:http://livedocs.adobe.com/flex/201/langref/%20inurl:object.html"><span style="color: #004993;">Object</span></a> = Application<span style="color: #000066; font-weight: bold;">.</span>application<span style="color: #000066; font-weight: bold;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; application<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">removeEventListener</span><span style="color: #000000;">&#40;</span>FlexEvent<span style="color: #000066; font-weight: bold;">.</span>INIT_COMPLETE<span style="color: #000066; font-weight: bold;">,</span> creationCompleteHandler<span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span><br />
<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; initializeListener<span style="color: #000000;">&#40;</span>application<span style="color: #000066; font-weight: bold;">.</span>systemManager<span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000;">&#125;</span><br />
<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0033ff; font-weight: bold;">private</span> <span style="color: #339966; font-weight: bold;">function</span> initializeListener<span style="color: #000000;">&#40;</span>systemManager<span style="color: #000066; font-weight: bold;">:</span>ISystemManager<span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">:</span><span style="color: #0033ff; font-weight: bold;">void</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0033ff; font-weight: bold;">this</span><span style="color: #000066; font-weight: bold;">.</span>systemManager = systemManager<span style="color: #000066; font-weight: bold;">;</span><br />
<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0033ff; font-weight: bold;">if</span> <span style="color: #000000;">&#40;</span><span style="color: #0033ff; font-weight: bold;">this</span><span style="color: #000066; font-weight: bold;">.</span>systemManager<span style="color: #000000;">&#41;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; LOG<span style="color: #000066; font-weight: bold;">.</span>debug<span style="color: #000000;">&#40;</span><span style="color: #990000;">&quot;AsynErrorLogger initialized.&quot;</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0033ff; font-weight: bold;">this</span><span style="color: #000066; font-weight: bold;">.</span>systemManager<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">addEventListener</span><span style="color: #000000;">&#40;</span>CALL_LATER_ERROR<span style="color: #000066; font-weight: bold;">,</span> errorHandler<span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000;">&#125;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000;">&#125;</span><br />
<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0033ff; font-weight: bold;">private</span> <span style="color: #339966; font-weight: bold;">function</span> errorHandler<span style="color: #000000;">&#40;</span>event<span style="color: #000066; font-weight: bold;">:</span>DynamicEvent<span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">:</span><span style="color: #0033ff; font-weight: bold;">void</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #6699cc; font-weight: bold;">var</span> <span style="color: #004993;">error</span><span style="color: #000066; font-weight: bold;">:</span><a href="http://www.google.com/search?q=error%20inurl:http://livedocs.adobe.com/flex/201/langref/%20inurl:error.html"><span style="color: #004993;">Error</span></a> = event<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">error</span> <span style="color: #0033ff; font-weight: bold;">as</span> <a href="http://www.google.com/search?q=error%20inurl:http://livedocs.adobe.com/flex/201/langref/%20inurl:error.html"><span style="color: #004993;">Error</span></a><span style="color: #000066; font-weight: bold;">;</span><br />
<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; LOG<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">error</span><span style="color: #000000;">&#40;</span><span style="color: #990000;">&quot;{0}&quot;</span><span style="color: #000066; font-weight: bold;">,</span> <span style="color: #004993;">error</span><span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">message</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span><br />
<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0033ff; font-weight: bold;">if</span> <span style="color: #000000;">&#40;</span>logStackTrace<span style="color: #000000;">&#41;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; LOG<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">error</span><span style="color: #000000;">&#40;</span><span style="color: #004993;">error</span><span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">getStackTrace</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000;">&#125;</span><br />
<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0033ff; font-weight: bold;">if</span> <span style="color: #000000;">&#40;</span>redispatchError<span style="color: #000000;">&#41;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #6699cc; font-weight: bold;">var</span> errorEvent<span style="color: #000066; font-weight: bold;">:</span><a href="http://www.google.com/search?q=errorevent%20inurl:http://livedocs.adobe.com/flex/201/langref/%20inurl:errorevent.html"><span style="color: #004993;">ErrorEvent</span></a> = <span style="color: #0033ff; font-weight: bold;">new</span> <a href="http://www.google.com/search?q=errorevent%20inurl:http://livedocs.adobe.com/flex/201/langref/%20inurl:errorevent.html"><span style="color: #004993;">ErrorEvent</span></a><span style="color: #000000;">&#40;</span><a href="http://www.google.com/search?q=errorevent%20inurl:http://livedocs.adobe.com/flex/201/langref/%20inurl:errorevent.html"><span style="color: #004993;">ErrorEvent</span></a><span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">ERROR</span><span style="color: #000066; font-weight: bold;">,</span> <span style="color: #0033ff; font-weight: bold;">false</span><span style="color: #000066; font-weight: bold;">,</span> <span style="color: #0033ff; font-weight: bold;">false</span><span style="color: #000066; font-weight: bold;">,</span> <span style="color: #004993;">error</span><span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">getStackTrace</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">,</span> <span style="color: #004993;">error</span><span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">errorID</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #004993;">dispatchEvent</span><span style="color: #000000;">&#40;</span>errorEvent<span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000;">&#125;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000;">&#125;</span><br />
&nbsp; &nbsp; <span style="color: #000000;">&#125;</span><br />
<span style="color: #000000;">&#125;</span></div></div>
]]></content:encoded>
			<wfw:commentRss>http://www.rialvalue.com/blog/2009/08/25/logging-and-catching-exceptions-during-invalidation/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
	</channel>
</rss>

