<?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; tips</title>
	<atom:link href="http://www.rialvalue.com/blog/category/tips/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>Documenting functions and named parameters</title>
		<link>http://www.rialvalue.com/blog/2011/02/04/documenting-functions-and-named-parameters/</link>
		<comments>http://www.rialvalue.com/blog/2011/02/04/documenting-functions-and-named-parameters/#comments</comments>
		<pubDate>Fri, 04 Feb 2011 08:03:09 +0000</pubDate>
		<dc:creator>Xavi Beumala</dc:creator>
				<category><![CDATA[best practice]]></category>
		<category><![CDATA[best_practice]]></category>
		<category><![CDATA[clean code]]></category>
		<category><![CDATA[flex]]></category>
		<category><![CDATA[flexunit]]></category>
		<category><![CDATA[testing]]></category>
		<category><![CDATA[tips]]></category>

		<guid isPermaLink="false">http://www.rialvalue.com/blog/?p=299</guid>
		<description><![CDATA[Sometime ago someone asked me how I&#8217;d pass custom paramaters to event listeners. I don&#8217;t remember the exact use case neither who asked me but basically he was asking for something like:
mc.addEventListener&#40;MouseEvent.CLICK, myListener, &#34;myCustomParam&#34;, 2&#41;;
functoin myListener&#40;event: MouseEvent, custom :String, custom2 : int&#41; : void;
While the exact syntax above would not be possible, closures are in [...]]]></description>
			<content:encoded><![CDATA[<p>Sometime ago someone asked me how I&#8217;d pass custom paramaters to event listeners. I don&#8217;t remember the exact use case neither who asked me but basically he was asking for something 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">mc<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">addEventListener</span><span style="color: #000000;">&#40;</span><a href="http://www.google.com/search?q=mouseevent%20inurl:http://livedocs.adobe.com/flex/201/langref/%20inurl:mouseevent.html"><span style="color: #004993;">MouseEvent</span></a><span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">CLICK</span><span style="color: #000066; font-weight: bold;">,</span> myListener<span style="color: #000066; font-weight: bold;">,</span> <span style="color: #990000;">&quot;myCustomParam&quot;</span><span style="color: #000066; font-weight: bold;">,</span> 2<span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span><br />
functoin myListener<span style="color: #000000;">&#40;</span>event<span style="color: #000066; font-weight: bold;">:</span> <a href="http://www.google.com/search?q=mouseevent%20inurl:http://livedocs.adobe.com/flex/201/langref/%20inurl:mouseevent.html"><span style="color: #004993;">MouseEvent</span></a><span style="color: #000066; font-weight: bold;">,</span> custom <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> custom2 <span style="color: #000066; font-weight: bold;">:</span> <a href="http://www.google.com/search?q=int%20inurl:http://livedocs.adobe.com/flex/201/langref/%20inurl:int.html"><span style="color: #004993;">int</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><span style="color: #000066; font-weight: bold;">;</span></div></div>
<p>While the exact syntax above would not be possible, closures are in any case the way to go. I explained him how I&#8217;d do it and I forgot about the topic until today.</p>
<p>Today while waiting for a long compilation process to complete I&#8217;ve came up with an idea on how to improve code readability on cases similar to this. Here&#8217;s the cleaneast syntax I&#8217;ve came up with (ideas are more than welcome to improve it):</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">mc<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">addEventListener</span><span style="color: #000000;">&#40;</span> <a href="http://www.google.com/search?q=mouseevent%20inurl:http://livedocs.adobe.com/flex/201/langref/%20inurl:mouseevent.html"><span style="color: #004993;">MouseEvent</span></a><span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">CLICK</span><span style="color: #000066; font-weight: bold;">,</span> createListenerAdapterBasedOn<span style="color: #000000;">&#40;</span>myListener<span style="color: #000066; font-weight: bold;">,</span> withParameters<span style="color: #000000;">&#40;</span><span style="color: #990000;">&quot;myCustomParam&quot;</span><span style="color: #000066; font-weight: bold;">,</span> 2<span style="color: #000000;">&#41;</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span></div></div>
<p>Does it look too verbose? I guess it will highly depend on the exact use case where this is used. But under some circumstances I think the readability can be substantially improved.</p>
<p><b>createListenerAdapterBasedOn</b> is a <a href="http://www.rialvalue.com/blog/2011/01/25/as3-package-level-functions-and-java-static-imports/">package level method</a>. I could have used a utility static method like FunctionUtils.createListenerAdapter. But instead I&#8217;ve used a package function because I can reduce the length of the Class + method name (or use the same number of characters to add verbosity and clarity). On the other hand it&#8217;s unlikely that this utility class would have more methods.</p>
<h2>Documenting functions</h2>
<p>This is a concept I&#8217;ve never read about or used before, but I think I&#8217;ll start using in different places. <i>withParameters</i> method is a completely dummy method that simply returns the parameters it gets but <b>giving them a semantic and contextual meaning</b>. The solely purpose of this method is to improve the readability by converting the method invocation in a Fluent API that can be read as natural language. The method is simply documenting the usage of the call. Putting this together with the <a href="http://www.rialvalue.com/blog/2010/03/30/some-thoughts-on-method-parameters/">Builder pattern and named parameters I discussed a while ago</a> it gives us an incredible weapon to create self-documented code that doesn&#8217;t need most-of-the-times useless, needless and confusing ASDoc or inline comments.</p>
<p>If necessary when you have a method accepting several parameters of the same type and that can be confusing to read you could used Documenting functions to create kind of named-parameters:</p>
<div class="codecolorer-container actionscript mac-classic" style="overflow:auto;white-space:nowrap;border: 1px solid #9F9F9F;width:515px;"><div class="actionscript codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">myMethod<span style="color: #66cc66;">&#40;</span><span style="color: #0066CC;">name</span><span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">&quot;John&quot;</span><span style="color: #66cc66;">&#41;</span>, surname<span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">&quot;Green&quot;</span><span style="color: #66cc66;">&#41;</span>, age<span style="color: #66cc66;">&#40;</span><span style="color: #cc66cc;">33</span><span style="color: #66cc66;">&#41;</span>, weight<span style="color: #66cc66;">&#40;</span><span style="color: #cc66cc;">70</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span></div></div>
<p>Here are the details of the implementation in case you are interested in seeing the internal details and some of the tests.</p>
<h3>createListenerAdapterBasedOn.as</h3>
<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: #9900cc; font-weight: bold;">package</span> com<span style="color: #000066; font-weight: bold;">.</span>rialvalue<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;">public</span> <span style="color: #339966; font-weight: bold;">function</span> createListenerAdapterBasedOn<span style="color: #000000;">&#40;</span>callback<span style="color: #000066; font-weight: bold;">:</span><a href="http://www.google.com/search?q=function%20inurl:http://livedocs.adobe.com/flex/201/langref/%20inurl:function.html"><span style="color: #004993;">Function</span></a><span style="color: #000066; font-weight: bold;">,</span> <span style="color: #000066; font-weight: bold;">...</span> args<span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">:</span><a href="http://www.google.com/search?q=function%20inurl:http://livedocs.adobe.com/flex/201/langref/%20inurl:function.html"><span style="color: #004993;">Function</span></a><br />
&nbsp; &nbsp; <span style="color: #000000;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0033ff; font-weight: bold;">return</span> <span style="color: #339966; font-weight: bold;">function</span><span style="color: #000000;">&#40;</span><span style="color: #000066; font-weight: bold;">...</span> rest<span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">:*</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>args<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">length</span> == 1<span style="color: #000000;">&#41;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0033ff; font-weight: bold;">return</span> callback<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">apply</span><span style="color: #000000;">&#40;</span><span style="color: #0033ff; font-weight: bold;">null</span><span style="color: #000066; font-weight: bold;">,</span> rest<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">concat</span><span style="color: #000000;">&#40;</span>args<span style="color: #000000;">&#91;</span>0<span style="color: #000000;">&#93;</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: #0033ff; font-weight: bold;">else</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0033ff; font-weight: bold;">return</span> callback<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">apply</span><span style="color: #000000;">&#40;</span><span style="color: #0033ff; font-weight: bold;">null</span><span style="color: #000066; font-weight: bold;">,</span> rest<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">concat</span><span style="color: #000000;">&#40;</span>args<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; <span style="color: #000000;">&#125;</span><br />
&nbsp; &nbsp; <span style="color: #000000;">&#125;</span><br />
<span style="color: #000000;">&#125;</span></div></div>
<h3>withParameters.as</h3>
<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: #9900cc; font-weight: bold;">package</span> com<span style="color: #000066; font-weight: bold;">.</span>rialvalue<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;">public</span> <span style="color: #339966; font-weight: bold;">function</span> withParameters<span style="color: #000000;">&#40;</span><span style="color: #000066; font-weight: bold;">...</span> args<span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">:</span><a href="http://www.google.com/search?q=array%20inurl:http://livedocs.adobe.com/flex/201/langref/%20inurl:array.html"><span style="color: #004993;">Array</span></a><br />
&nbsp; &nbsp; <span style="color: #000000;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0033ff; font-weight: bold;">return</span> args<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>
<h3>createListenerAdapterBasedOnTest.as</h3>
<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>rialvalue<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.display</span><span style="color: #000066; font-weight: bold;">.</span><a href="http://www.google.com/search?q=movieclip%20inurl:http://livedocs.adobe.com/flex/201/langref/%20inurl:movieclip.html"><span style="color: #004993;">MovieClip</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=event%20inurl:http://livedocs.adobe.com/flex/201/langref/%20inurl:event.html"><span style="color: #004993;">Event</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=ieventdispatcher%20inurl:http://livedocs.adobe.com/flex/201/langref/%20inurl:ieventdispatcher.html"><span style="color: #004993;">IEventDispatcher</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=mouseevent%20inurl:http://livedocs.adobe.com/flex/201/langref/%20inurl:mouseevent.html"><span style="color: #004993;">MouseEvent</span></a><span style="color: #000066; font-weight: bold;">;</span><br />
&nbsp; &nbsp; <br />
&nbsp; &nbsp; <span style="color: #0033ff; font-weight: bold;">import</span> flashx<span style="color: #000066; font-weight: bold;">.</span>textLayout<span style="color: #000066; font-weight: bold;">.</span>debug<span style="color: #000066; font-weight: bold;">.</span>assert<span style="color: #000066; font-weight: bold;">;</span><br />
&nbsp; &nbsp; <br />
&nbsp; &nbsp; <span style="color: #0033ff; font-weight: bold;">import</span> org<span style="color: #000066; font-weight: bold;">.</span>flexunit<span style="color: #000066; font-weight: bold;">.</span>assertThat<span style="color: #000066; font-weight: bold;">;</span><br />
&nbsp; &nbsp; <span style="color: #0033ff; font-weight: bold;">import</span> org<span style="color: #000066; font-weight: bold;">.</span>hamcrest<span style="color: #000066; font-weight: bold;">.</span>object<span style="color: #000066; font-weight: bold;">.</span>equalTo<span style="color: #000066; font-weight: bold;">;</span><br />
<br />
&nbsp; &nbsp; <span style="color: #0033ff; font-weight: bold;">public</span> <span style="color: #9900cc; font-weight: bold;">class</span> ListenerUtilsTest<br />
&nbsp; &nbsp; <span style="color: #000000;">&#123;</span><br />
<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0033ff; font-weight: bold;">private</span> static const ORIGINAL_PARAMETER<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;originalParameter&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 FIRST_PARAM<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;firstParam&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 SECOND_PARAM<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;secondParam&quot;</span><span style="color: #000066; font-weight: bold;">;</span><br />
<br />
<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000;">&#91;</span>Test<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> createCallbackAdapterWithNoParameters<span style="color: #000000;">&#40;</span><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> callbackAdapter<span style="color: #000066; font-weight: bold;">:</span><a href="http://www.google.com/search?q=function%20inurl:http://livedocs.adobe.com/flex/201/langref/%20inurl:function.html"><span style="color: #004993;">Function</span></a> = createListenerAdapterBasedOn<span style="color: #000000;">&#40;</span><span style="color: #339966; font-weight: bold;">function</span><span style="color: #000000;">&#40;</span><span style="color: #004993;">data</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: #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; &nbsp; &nbsp; <span style="color: #000000;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; assertThat<span style="color: #000000;">&#40;</span>ORIGINAL_PARAMETER<span style="color: #000066; font-weight: bold;">,</span> equalTo<span style="color: #000000;">&#40;</span><span style="color: #004993;">data</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><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span><br />
<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; callbackAdapter<span style="color: #000000;">&#40;</span>ORIGINAL_PARAMETER<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: #000000;">&#91;</span>Test<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> createCallbackAdapterWithIndividualParameter<span style="color: #000000;">&#40;</span><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> callbackAdapter<span style="color: #000066; font-weight: bold;">:</span><a href="http://www.google.com/search?q=function%20inurl:http://livedocs.adobe.com/flex/201/langref/%20inurl:function.html"><span style="color: #004993;">Function</span></a> = createListenerAdapterBasedOn<span style="color: #000000;">&#40;</span><span style="color: #339966; font-weight: bold;">function</span><span style="color: #000000;">&#40;</span><span style="color: #004993;">data</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: #000066; font-weight: bold;">,</span> p1<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: #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; &nbsp; &nbsp; <span style="color: #000000;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; assertThat<span style="color: #000000;">&#40;</span>ORIGINAL_PARAMETER<span style="color: #000066; font-weight: bold;">,</span> equalTo<span style="color: #000000;">&#40;</span><span style="color: #004993;">data</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; &nbsp; &nbsp; assertThat<span style="color: #000000;">&#40;</span>FIRST_PARAM<span style="color: #000066; font-weight: bold;">,</span> equalTo<span style="color: #000000;">&#40;</span>p1<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><span style="color: #000066; font-weight: bold;">,</span> withParameters<span style="color: #000000;">&#40;</span>FIRST_PARAM<span style="color: #000000;">&#41;</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span><br />
<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; callbackAdapter<span style="color: #000000;">&#40;</span>ORIGINAL_PARAMETER<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: #000000;">&#91;</span>Test<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> createCallbackAdapterWithIndividualParameterNoFluent<span style="color: #000000;">&#40;</span><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> callbackAdapter<span style="color: #000066; font-weight: bold;">:</span><a href="http://www.google.com/search?q=function%20inurl:http://livedocs.adobe.com/flex/201/langref/%20inurl:function.html"><span style="color: #004993;">Function</span></a> = createListenerAdapterBasedOn<span style="color: #000000;">&#40;</span><span style="color: #339966; font-weight: bold;">function</span><span style="color: #000000;">&#40;</span><span style="color: #004993;">data</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: #000066; font-weight: bold;">,</span> p1<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: #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; &nbsp; &nbsp; <span style="color: #000000;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; assertThat<span style="color: #000000;">&#40;</span>ORIGINAL_PARAMETER<span style="color: #000066; font-weight: bold;">,</span> equalTo<span style="color: #000000;">&#40;</span><span style="color: #004993;">data</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; &nbsp; &nbsp; assertThat<span style="color: #000000;">&#40;</span>FIRST_PARAM<span style="color: #000066; font-weight: bold;">,</span> equalTo<span style="color: #000000;">&#40;</span>p1<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><span style="color: #000066; font-weight: bold;">,</span> FIRST_PARAM<span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span><br />
<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; callbackAdapter<span style="color: #000000;">&#40;</span>ORIGINAL_PARAMETER<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: #000000;">&#91;</span>Test<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> createCallbackAdapterWithIndividualParameters<span style="color: #000000;">&#40;</span><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> callbackAdapter<span style="color: #000066; font-weight: bold;">:</span><a href="http://www.google.com/search?q=function%20inurl:http://livedocs.adobe.com/flex/201/langref/%20inurl:function.html"><span style="color: #004993;">Function</span></a> = createListenerAdapterBasedOn<span style="color: #000000;">&#40;</span><span style="color: #339966; font-weight: bold;">function</span><span style="color: #000000;">&#40;</span><span style="color: #004993;">data</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: #000066; font-weight: bold;">,</span> p1<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> p2<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: #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; &nbsp; &nbsp; <span style="color: #000000;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; assertThat<span style="color: #000000;">&#40;</span>ORIGINAL_PARAMETER<span style="color: #000066; font-weight: bold;">,</span> equalTo<span style="color: #000000;">&#40;</span><span style="color: #004993;">data</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; &nbsp; &nbsp; assertThat<span style="color: #000000;">&#40;</span>FIRST_PARAM<span style="color: #000066; font-weight: bold;">,</span> equalTo<span style="color: #000000;">&#40;</span>p1<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; &nbsp; &nbsp; assertThat<span style="color: #000000;">&#40;</span>SECOND_PARAM<span style="color: #000066; font-weight: bold;">,</span> equalTo<span style="color: #000000;">&#40;</span>p2<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><span style="color: #000066; font-weight: bold;">,</span> withParameters<span style="color: #000000;">&#40;</span>FIRST_PARAM<span style="color: #000066; font-weight: bold;">,</span> SECOND_PARAM<span style="color: #000000;">&#41;</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span><br />
<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; callbackAdapter<span style="color: #000000;">&#40;</span>ORIGINAL_PARAMETER<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: #000000;">&#91;</span>Test<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> createCallbackAdapterWithIndividualParametersNoFluent<span style="color: #000000;">&#40;</span><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> callbackAdapter<span style="color: #000066; font-weight: bold;">:</span><a href="http://www.google.com/search?q=function%20inurl:http://livedocs.adobe.com/flex/201/langref/%20inurl:function.html"><span style="color: #004993;">Function</span></a> = createListenerAdapterBasedOn<span style="color: #000000;">&#40;</span><span style="color: #339966; font-weight: bold;">function</span><span style="color: #000000;">&#40;</span><span style="color: #004993;">data</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: #000066; font-weight: bold;">,</span> p1<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> p2<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: #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; &nbsp; &nbsp; <span style="color: #000000;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; assertThat<span style="color: #000000;">&#40;</span>ORIGINAL_PARAMETER<span style="color: #000066; font-weight: bold;">,</span> equalTo<span style="color: #000000;">&#40;</span><span style="color: #004993;">data</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; &nbsp; &nbsp; assertThat<span style="color: #000000;">&#40;</span>FIRST_PARAM<span style="color: #000066; font-weight: bold;">,</span> equalTo<span style="color: #000000;">&#40;</span>p1<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; &nbsp; &nbsp; assertThat<span style="color: #000000;">&#40;</span>SECOND_PARAM<span style="color: #000066; font-weight: bold;">,</span> equalTo<span style="color: #000000;">&#40;</span>p2<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><span style="color: #000066; font-weight: bold;">,</span> FIRST_PARAM<span style="color: #000066; font-weight: bold;">,</span> SECOND_PARAM<span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span><br />
<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; callbackAdapter<span style="color: #000000;">&#40;</span>ORIGINAL_PARAMETER<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 />
&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/2011/02/04/documenting-functions-and-named-parameters/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>AS3 Package level functions and Java static imports</title>
		<link>http://www.rialvalue.com/blog/2011/01/25/as3-package-level-functions-and-java-static-imports/</link>
		<comments>http://www.rialvalue.com/blog/2011/01/25/as3-package-level-functions-and-java-static-imports/#comments</comments>
		<pubDate>Tue, 25 Jan 2011 11:12:06 +0000</pubDate>
		<dc:creator>Xavi Beumala</dc:creator>
				<category><![CDATA[tips]]></category>

		<guid isPermaLink="false">http://www.rialvalue.com/blog/?p=290</guid>
		<description><![CDATA[It&#8217;s a hidden treasure for lot of people but AS3 provides a mechanism to declare functions like setTimeout or setInterval called package level functions. These functions are defined inside packages like flash.utils.setInterval or flash.utils.setTimeout but can be used as if they were static functions.
This is a feature widely used in FlexUnit but that can be [...]]]></description>
			<content:encoded><![CDATA[<p>It&#8217;s a hidden treasure for lot of people but AS3 provides a mechanism to declare functions like setTimeout or setInterval called package level functions. These functions are defined inside packages like flash.utils.setInterval or flash.utils.setTimeout but can be used as if they were static functions.</p>
<p>This is a feature widely used in FlexUnit but that can be used in lots of other circumstances to reduce the amount of code and reduce its verbosity.</p>
<p>The mechanism to create a package level function is pretty simple. Here are the steps required to create a custom package function:</p>
<ul>
<li>You create a class where the function will be defined. i.e: your/package/Assert.as</li>
<li>You declare a public function at the package level. Note that there&#8217;s no class definition.
<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: #9900cc; font-weight: bold;">package</span> my<span style="color: #000066; font-weight: bold;">.</span>pack<br />
<span style="color: #000000;">&#123;</span><br />
&nbsp; &nbsp; <span style="color: #0033ff; font-weight: bold;">public</span> <span style="color: #339966; font-weight: bold;">function</span> assert<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><br />
&nbsp; &nbsp; <span style="color: #000000;">&#123;</span><br />
&nbsp; &nbsp; <span style="color: #000000;">&#125;</span><br />
<span style="color: #000000;">&#125;</span></div></div>
</li>
<li>Then you can use it from every where you wish</li>
<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: #9900cc; font-weight: bold;">package</span> <br />
<span style="color: #000000;">&#123;</span><br />
&nbsp; &nbsp; <span style="color: #0033ff; font-weight: bold;">import</span> my<span style="color: #000066; font-weight: bold;">.</span>pack<span style="color: #000066; font-weight: bold;">.</span>assert<span style="color: #000066; font-weight: bold;">;</span><br />
&nbsp; &nbsp; <br />
&nbsp; &nbsp; <span style="color: #0033ff; font-weight: bold;">public</span> <span style="color: #9900cc; font-weight: bold;">class</span> testPackagefunctions<br />
&nbsp; &nbsp; <span style="color: #000000;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0033ff; font-weight: bold;">public</span> <span style="color: #339966; font-weight: bold;">function</span> testPackagefunctions<span style="color: #000000;">&#40;</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; assert<span style="color: #000000;">&#40;</span><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 />
&nbsp; &nbsp; <span style="color: #000000;">&#125;</span><br />
<span style="color: #000000;">&#125;</span></div></div>
</ul>
<p>When creating package level functions, the only restriction to bear in mind, is that the function name exposed must be the same name as the name of the file that contains it. i.e. If I expose the assert function, the filename that defines it must be assert.as. This implies that there can only be one function definition per file. If you need more you can create as many files as you need.</p>
<p>Package level functions in AS3 are directly comparable to static imports in Java. In java we can write code 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: #9900cc; font-weight: bold;">package</span> <span style="color: #000000;">&#123;</span><br />
&nbsp; &nbsp; <span style="color: #0033ff; font-weight: bold;">import</span> static my<span style="color: #000066; font-weight: bold;">.</span>pack<span style="color: #000066; font-weight: bold;">.</span>Assert<span style="color: #000066; font-weight: bold;">.*;</span><br />
<br />
&nbsp; &nbsp; <span style="color: #0033ff; font-weight: bold;">public</span> static <span style="color: #0033ff; font-weight: bold;">void</span> main<span style="color: #000000;">&#40;</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: #000000;">&#91;</span><span style="color: #000000;">&#93;</span> args<span style="color: #000000;">&#41;</span> <span style="color: #000000;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; assert<span style="color: #000000;">&#40;</span><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>By using an static import in Java, static methods defined in the Assert class (in the example above) are made available directly so there&#8217;s no need to write Assert.assert. Again this is a feature used a lot in <a href="http://www.junit.org">jUnit</a>, <a href="http://code.google.com/p/hamcrest/">Hamcrest</a> or <a href="http://code.google.com/p/lambdaj/">lamdaj</a> libraries.</p>
<p>Autocompletion in Java in regards to static imports is not automatic. If you want to have autocompletion with static imports you can use Preferences > Java > Editor > Favorites and add there the Types or classes you want to use static imports for.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.rialvalue.com/blog/2011/01/25/as3-package-level-functions-and-java-static-imports/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>HowTo create your developer ToolBox with Mixins</title>
		<link>http://www.rialvalue.com/blog/2010/05/21/howto-create-your-developer-toolbox-with-mixins/</link>
		<comments>http://www.rialvalue.com/blog/2010/05/21/howto-create-your-developer-toolbox-with-mixins/#comments</comments>
		<pubDate>Fri, 21 May 2010 11:25:33 +0000</pubDate>
		<dc:creator>Xavi Beumala</dc:creator>
				<category><![CDATA[components]]></category>
		<category><![CDATA[flex]]></category>
		<category><![CDATA[testing]]></category>
		<category><![CDATA[tips]]></category>
		<category><![CDATA[debug]]></category>
		<category><![CDATA[mixin]]></category>
		<category><![CDATA[toolbox]]></category>

		<guid isPermaLink="false">http://www.rialvalue.com/blog/?p=228</guid>
		<description><![CDATA[In this post I&#8217;ll explain how you can develop a flex library that automatically initializes itself avoiding developers the hassle of remembering how, when and where the libraries need to be initialized and hooked into the application. This can be particularly helpful for debugging libraries like fxSpy, DeMonsterDebugger, KaptInspect, mrdoob, etc. and extremely useful to [...]]]></description>
			<content:encoded><![CDATA[<p>In this post I&#8217;ll explain how you can develop a flex library that automatically initializes itself avoiding developers the hassle of remembering how, when and where the libraries need to be initialized and hooked into the application. This can be particularly helpful for debugging libraries like <a href="http://code.google.com/p/fxspy/">fxSpy</a>, <a href="http://demonsterdebugger.com/">DeMonsterDebugger</a>, <a href="http://lab.kapit.fr/display/kapinspect/Kap+Inspect">KaptInspect</a>, <a href="code.google.com/p/mrdoob">mrdoob</a>, etc. and extremely useful to create your own Flex toolbox that simply plugs-in and can go with you on all your developments.<br />
<span id="more-228"></span><br />
First, create a class in your library project with whatever name you pick, in my case I&#8217;ll call it LibraryInitializer.as, make sure you mark this class to be included on the final swc or even better use the new FB4 option &#8220;Include all classes from all sources&#8221;. Second and key point, add a public static method named init that receives a parameter and mark the class as a Mixin:</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>Mixin<span style="color: #000000;">&#93;</span><br />
<span style="color: #0033ff; font-weight: bold;">public</span> <span style="color: #9900cc; font-weight: bold;">class</span> LibraryInitializer <br />
<span style="color: #000000;">&#123;</span><br />
&nbsp; &nbsp; <span style="color: #0033ff; font-weight: bold;">public</span> static <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; <span style="color: #000000;">&#123;</span> &nbsp; <br />
&nbsp; &nbsp; <span style="color: #000000;">&#125;</span><br />
<span style="color: #000000;">&#125;</span></div></div>
<p>The [Mixin] metadata tag is extensively used in the Flex automation API and it basically gives you a very interesting hook. The static init method of any class marked as a [Mixin] will be invoked at a very early point during the application initialization phase by the SystemManager class or FlexModuleFactory. The Mixins are executed before the preInitialize event is triggered on the main Application. The parameter that the init method receives is a reference to the related SystemManager so you can mark the parameter as an ISystemManager, InteractiveObject or whatever better fits your needs. You can <a href="http://www.rialvalue.com/blog/2010/05/13/global-exception-or-error-handling-in-flex/">read about another interesting use of the [Mixin] on the Global Exception Handler post</a> .</p>
<p>By adding a Mixin class in a library and linking the library to an Application what you effectively get is a hook where the library can initialize itself and release the developer from manually initializing it.</p>
<p>Let&#8217;s see some real world examples.</p>
<p>Libraries like fxSpy, deMonsterDebugger, KaptInspect or mrdoob are extremely easy to use but on each project you end up doing some repetitive steps or adding conditionally compiled code to your Main application class. </p>
<p>I&#8217;ll focus on a sample with <a href="http://code.google.com/p/fxspy/">fxSpy</a> where you can launch it from a contextual option when you right click on the application and see <a href="code.google.com/p/mrdoob">mrdoob</a> memory monitor. The only step required to integrate this will is adding the following compiler option:</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">-include-libraries=libs/myToolbox.swc</div></div>
<p>And this is the library initializer, which basically adds a ContextMenuItem to the contextMenu of the systemManager. Note that we have to wait for the APPLICATION_COMPLETE event, otherwise the Flex SDK will override our contextMenu (it happens on the pre-initialize phase).</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><br />
<span style="color: #000000;">&#123;</span><br />
&nbsp; &nbsp; <span style="color: #0033ff; font-weight: bold;">import</span> com<span style="color: #000066; font-weight: bold;">.</span>flexspy<span style="color: #000066; font-weight: bold;">.</span>FlexSpy<span style="color: #000066; font-weight: bold;">;</span><br />
<br />
&nbsp; &nbsp; <span style="color: #0033ff; font-weight: bold;">import</span> <span style="color: #004993;">flash.display</span><span style="color: #000066; font-weight: bold;">.</span><a href="http://www.google.com/search?q=interactiveobject%20inurl:http://livedocs.adobe.com/flex/201/langref/%20inurl:interactiveobject.html"><span style="color: #004993;">InteractiveObject</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=contextmenuevent%20inurl:http://livedocs.adobe.com/flex/201/langref/%20inurl:contextmenuevent.html"><span style="color: #004993;">ContextMenuEvent</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=event%20inurl:http://livedocs.adobe.com/flex/201/langref/%20inurl:event.html"><span style="color: #004993;">Event</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.ui</span><span style="color: #000066; font-weight: bold;">.</span><a href="http://www.google.com/search?q=contextmenu%20inurl:http://livedocs.adobe.com/flex/201/langref/%20inurl:contextmenu.html"><span style="color: #004993;">ContextMenu</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.ui</span><span style="color: #000066; font-weight: bold;">.</span><a href="http://www.google.com/search?q=contextmenuitem%20inurl:http://livedocs.adobe.com/flex/201/langref/%20inurl:contextmenuitem.html"><span style="color: #004993;">ContextMenuItem</span></a><span style="color: #000066; font-weight: bold;">;</span><br />
<br />
&nbsp; &nbsp; <span style="color: #0033ff; font-weight: bold;">import</span> flashx<span style="color: #000066; font-weight: bold;">.</span>textLayout<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">elements</span><span style="color: #000066; font-weight: bold;">.</span>GlobalSettings<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>FlexGlobals<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>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: #0033ff; font-weight: bold;">import</span> spark<span style="color: #000066; font-weight: bold;">.</span>core<span style="color: #000066; font-weight: bold;">.</span>SpriteVisualElement<span style="color: #000066; font-weight: bold;">;</span><br />
<br />
&nbsp; &nbsp; <span style="color: #000000;">&#91;</span>Mixin<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> MyToolBoxInitializer<br />
&nbsp; &nbsp; <span style="color: #000000;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0033ff; font-weight: bold;">private</span> static <span style="color: #6699cc; font-weight: bold;">var</span> initializer<span style="color: #000066; font-weight: bold;">:</span>MyToolBoxInitializer<span style="color: #000066; font-weight: bold;">;</span><br />
<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0033ff; font-weight: bold;">public</span> static <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; systemManager<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>APPLICATION_COMPLETE<span style="color: #000066; font-weight: bold;">,</span> applicationCompleteHandler<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> static <span style="color: #339966; font-weight: bold;">function</span> applicationCompleteHandler<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> systemManager<span style="color: #000066; font-weight: bold;">:</span><a href="http://www.google.com/search?q=interactiveobject%20inurl:http://livedocs.adobe.com/flex/201/langref/%20inurl:interactiveobject.html"><span style="color: #004993;">InteractiveObject</span></a> = event<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">target</span> <span style="color: #0033ff; font-weight: bold;">as</span> <a href="http://www.google.com/search?q=interactiveobject%20inurl:http://livedocs.adobe.com/flex/201/langref/%20inurl:interactiveobject.html"><span style="color: #004993;">InteractiveObject</span></a><span style="color: #000066; font-weight: bold;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; systemManager<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>APPLICATION_COMPLETE<span style="color: #000066; font-weight: bold;">,</span> applicationCompleteHandler<span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span><br />
<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; initializer = <span style="color: #0033ff; font-weight: bold;">new</span> MyToolBoxInitializer<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 />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0033ff; font-weight: bold;">public</span> <span style="color: #339966; font-weight: bold;">function</span> MyToolBoxInitializer<span style="color: #000000;">&#40;</span><span style="color: #004993;">target</span><span style="color: #000066; font-weight: bold;">:</span><a href="http://www.google.com/search?q=interactiveobject%20inurl:http://livedocs.adobe.com/flex/201/langref/%20inurl:interactiveobject.html"><span style="color: #004993;">InteractiveObject</span></a><span style="color: #000000;">&#41;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; createContextMenu<span style="color: #000000;">&#40;</span><span style="color: #004993;">target</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; createMonitor<span style="color: #000000;">&#40;</span><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> createContextMenu<span style="color: #000000;">&#40;</span><span style="color: #004993;">target</span><span style="color: #000066; font-weight: bold;">:</span><a href="http://www.google.com/search?q=interactiveobject%20inurl:http://livedocs.adobe.com/flex/201/langref/%20inurl:interactiveobject.html"><span style="color: #004993;">InteractiveObject</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> <span style="color: #004993;">contextMenu</span><span style="color: #000066; font-weight: bold;">:</span><a href="http://www.google.com/search?q=contextmenu%20inurl:http://livedocs.adobe.com/flex/201/langref/%20inurl:contextmenu.html"><span style="color: #004993;">ContextMenu</span></a> = <span style="color: #004993;">target</span><span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">contextMenu</span><span style="color: #000066; font-weight: bold;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #004993;">contextMenu</span><span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">customItems</span> = <span style="color: #000000;">&#91;</span> createContextMenuItem<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span> <span style="color: #000000;">&#93;</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> createMonitor<span style="color: #000000;">&#40;</span><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> sve<span style="color: #000066; font-weight: bold;">:</span>SpriteVisualElement = <span style="color: #0033ff; font-weight: bold;">new</span> SpriteVisualElement<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; sve<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">addChild</span><span style="color: #000000;">&#40;</span><span style="color: #0033ff; font-weight: bold;">new</span> Stats<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; FlexGlobals<span style="color: #000066; font-weight: bold;">.</span>topLevelApplication<span style="color: #000066; font-weight: bold;">.</span>addElement<span style="color: #000000;">&#40;</span>sve<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> createContextMenuItem<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=contextmenuitem%20inurl:http://livedocs.adobe.com/flex/201/langref/%20inurl:contextmenuitem.html"><span style="color: #004993;">ContextMenuItem</span></a><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> contextItem<span style="color: #000066; font-weight: bold;">:</span><a href="http://www.google.com/search?q=contextmenuitem%20inurl:http://livedocs.adobe.com/flex/201/langref/%20inurl:contextmenuitem.html"><span style="color: #004993;">ContextMenuItem</span></a> = <span style="color: #0033ff; font-weight: bold;">new</span> <a href="http://www.google.com/search?q=contextmenuitem%20inurl:http://livedocs.adobe.com/flex/201/langref/%20inurl:contextmenuitem.html"><span style="color: #004993;">ContextMenuItem</span></a><span style="color: #000000;">&#40;</span><span style="color: #990000;">&quot;Flex Spy&quot;</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; contextItem<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">addEventListener</span><span style="color: #000000;">&#40;</span><a href="http://www.google.com/search?q=contextmenuevent%20inurl:http://livedocs.adobe.com/flex/201/langref/%20inurl:contextmenuevent.html"><span style="color: #004993;">ContextMenuEvent</span></a><span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">MENU_ITEM_SELECT</span><span style="color: #000066; font-weight: bold;">,</span> handleContextMenuItemSelect<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;">return</span> contextItem<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> handleContextMenuItemSelect<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; FlexSpy<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">show</span><span style="color: #000000;">&#40;</span><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 />
&nbsp; &nbsp; <span style="color: #000000;">&#125;</span><br />
<span style="color: #000000;">&#125;</span></div></div>
<p>In the Initializer you could also intialize the fps and memory monitor provided by mrdoob by simply adding a new instance to the DisplayList.</p>
<p>These are the benefits I see on this approach:</p>
<ul>
<li>You won&#8217;t have to reapeat yourself in different projects initializing the same libraries always in the same way.</li>
<li>Your main file won&#8217;t be cluttered with infrastructure and glue code to configure your libraries.</li>
<li>You won&#8217;t need to use conditional compilation for this initializations. You can enable or disable all at once by removing the compiler option. Going an step further you could have diferent compiler profiles / environments on your ant tasks or maven builds or even use the -load-config compiler option to externalize your configurations to an xml file.</li>
</ul>
<p><a href="http://www.rialvalue.com/downloads/libraryInitializers.zip">You can downdload a zip with 2 sample projects</a>, one for the library and the other for the application using it.</p>
<p>Shortly I&#8217;ll blog about some of the things I have in my toolbox that could be helpful for you too.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.rialvalue.com/blog/2010/05/21/howto-create-your-developer-toolbox-with-mixins/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Global Exception or Error Handling in Flex</title>
		<link>http://www.rialvalue.com/blog/2010/05/13/global-exception-or-error-handling-in-flex/</link>
		<comments>http://www.rialvalue.com/blog/2010/05/13/global-exception-or-error-handling-in-flex/#comments</comments>
		<pubDate>Thu, 13 May 2010 09:08:52 +0000</pubDate>
		<dc:creator>Xavi Beumala</dc:creator>
				<category><![CDATA[General]]></category>
		<category><![CDATA[air]]></category>
		<category><![CDATA[components]]></category>
		<category><![CDATA[flex]]></category>
		<category><![CDATA[tips]]></category>
		<category><![CDATA[error handling]]></category>
		<category><![CDATA[mixin]]></category>

		<guid isPermaLink="false">http://www.rialvalue.com/blog/?p=207</guid>
		<description><![CDATA[In this post I explain how you can catch unhandled exceptions or errors globally in a declarative mxml-based way using the [Mixin] flex-specific metadata tag.
Starting on FP 10.1 and AIR 2.0 you can capture unhandled exceptions or errors globally. Although you can use these new APIs you should always take care of the exceptions where [...]]]></description>
			<content:encoded><![CDATA[<p>In this post I explain how you can catch unhandled exceptions or errors globally in a declarative mxml-based way using the [Mixin] flex-specific metadata tag.</p>
<p>Starting on FP 10.1 and AIR 2.0 you can capture unhandled exceptions or errors globally. Although you can use these new APIs you should <b>always</b> take care of the exceptions where they happen and use this technique only as a diagnosing or logging help or for async exceptions that you can&#8217;t really control in any other way. </p>
<p>You might also be interested in these 2 other topics:</p>
<ul>
<li><a href="http://www.rialvalue.com/blog/2009/08/25/logging-and-catching-exceptions-during-invalidation/">Logging and catching (async) exceptions during invalidation in Flex</a></li>
<li><a href="http://www.rialvalue.com/blog/2009/08/16/debugging-production-ready-air-applications/">Debugging and getting Stack-trace error dialogs with installed AIR applications</a></li>
</ul>
<p>The new API works 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: #004993;">loaderInfo</span><span style="color: #000066; font-weight: bold;">.</span>uncaughtErrorEvents<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">addEventListener</span><span style="color: #000000;">&#40;</span>UncaughtErrorEvent<span style="color: #000066; font-weight: bold;">.</span>UNCAUGHT_ERROR<span style="color: #000066; font-weight: bold;">,</span> onUncaughtError<span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span><br />
<br />
<span style="color: #0033ff; font-weight: bold;">private</span> <span style="color: #339966; font-weight: bold;">function</span> onUncaughtError<span style="color: #000000;">&#40;</span>e<span style="color: #000066; font-weight: bold;">:</span>UncaughtErrorEvent<span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">:</span><span style="color: #0033ff; font-weight: bold;">void</span><br />
<span style="color: #000000;">&#123;</span><br />
&nbsp; &nbsp; <span style="color: #009900; font-style: italic;">// Do something with your error.</span><br />
<span style="color: #000000;">&#125;</span></div></div>
<p><a href="http://blogs.adobe.com/cantrell/archives/2009/10/global_error_handling_in_air_20.html">Christian Cantrell explains some more details on the APIs</a>. You can find further information <a href="http://help.adobe.com/en_US/FlashPlatform/beta/reference/actionscript/3/flash/events/UncaughtErrorEvent.html">in the documentation</a> as well.</p>
<p>When working with Flex, and adding the UncaughtErrorEvent.UNCAUGHT_ERROR listener to the loaderInfo object make sure you do it after FlexEvent.APPLICATION_COMPLETE event has been triggered, otherwise you&#8217;ll get an &#8220;Error #1009: Cannot access a property or method of a null object reference&#8221;</p>
<p>To prevent all this required glue code and avoid unnecessary configuration code (that ends up cluttering the main application Class) I&#8217;ve created a GlobalExceptionHandler component that abstracts developers a little bit from these sort of problems. The implementation isn&#8217;t tighted to the APPLICATION_COMPLETE event, instead it uses the [Mixin] metadata tag. On top of that you can use it declaratively:</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;?xml</span> <span style="color: #000066;">version</span>=<span style="color: #ff0000;">&quot;1.0&quot;</span> <span style="color: #000066;">encoding</span>=<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;s:WindowedApplication</span> <span style="color: #000066;">xmlns:fx</span>=<span style="color: #ff0000;">&quot;http://ns.adobe.com/mxml/2009&quot;</span></span><br />
<span style="color: #009900;"> &nbsp; &nbsp;<span style="color: #000066;">xmlns:s</span>=<span style="color: #ff0000;">&quot;library://ns.adobe.com/flex/spark&quot;</span></span><br />
<span style="color: #009900;"> &nbsp; &nbsp;<span style="color: #000066;">xmlns:mx</span>=<span style="color: #ff0000;">&quot;library://ns.adobe.com/flex/mx&quot;</span></span><br />
<span style="color: #009900;"> &nbsp; &nbsp;<span style="color: #000066;">xmlns:logging</span>=<span style="color: #ff0000;">&quot;com.adobe.ac.logging.*&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;fx:Declarations<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;logging:GlobalExceptionHandler</span> <span style="color: #000066;">preventDefault</span>=<span style="color: #ff0000;">&quot;true&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;logging:LogHandlerAction</span><span style="color: #000000; font-weight: bold;">/&gt;</span></span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;local:TraceHandlerAction</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;/logging:GlobalExceptionHandler<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;/fx:Declarations<span style="color: #000000; font-weight: bold;">&gt;</span></span></span><br />
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/s:WindowedApplication<span style="color: #000000; font-weight: bold;">&gt;</span></span></span></div></div>
<p>You can <a href="http://www.rialvalue.com/downloads/globalExceptionHandler.zip">download the code along with a sample project here</a>. The code for GlobalExceptionHandler:</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>logging<br />
<span style="color: #000000;">&#123;</span><br />
&nbsp; &nbsp; <span style="color: #0033ff; font-weight: bold;">import</span> <span style="color: #004993;">flash.display</span><span style="color: #000066; font-weight: bold;">.</span><a href="http://www.google.com/search?q=loaderinfo%20inurl:http://livedocs.adobe.com/flex/201/langref/%20inurl:loaderinfo.html"><span style="color: #004993;">LoaderInfo</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>UncaughtErrorEvent<span style="color: #000066; font-weight: bold;">;</span><br />
&nbsp; &nbsp; <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>Mixin<span style="color: #000000;">&#93;</span><br />
&nbsp; &nbsp; <span style="color: #000000;">&#91;</span>DefaultProperty<span style="color: #000000;">&#40;</span><span style="color: #990000;">&quot;handlerActions&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> GlobalExceptionHandler<br />
&nbsp; &nbsp; <span style="color: #000000;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0033ff; font-weight: bold;">private</span> static <span style="color: #6699cc; font-weight: bold;">var</span> <span style="color: #004993;">loaderInfo</span><span style="color: #000066; font-weight: bold;">:</span><a href="http://www.google.com/search?q=loaderinfo%20inurl:http://livedocs.adobe.com/flex/201/langref/%20inurl:loaderinfo.html"><span style="color: #004993;">LoaderInfo</span></a><span style="color: #000066; font-weight: bold;">;</span><br />
<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000;">&#91;</span>ArrayElementType<span style="color: #000000;">&#40;</span><span style="color: #990000;">&quot;com.adobe.ac.logging.GlobalExceptionHandlerAction&quot;</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">&#93;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0033ff; font-weight: bold;">public</span> <span style="color: #6699cc; font-weight: bold;">var</span> handlerActions<span style="color: #000066; font-weight: bold;">:</span><a href="http://www.google.com/search?q=array%20inurl:http://livedocs.adobe.com/flex/201/langref/%20inurl:array.html"><span style="color: #004993;">Array</span></a><span style="color: #000066; font-weight: bold;">;</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> <span style="color: #004993;">preventDefault</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: #000066; font-weight: bold;">;</span><br />
<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0033ff; font-weight: bold;">public</span> static <span style="color: #339966; font-weight: bold;">function</span> <span style="color: #004993;">init</span><span style="color: #000000;">&#40;</span>sm<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: #004993;">loaderInfo</span> = sm<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">loaderInfo</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;">public</span> <span style="color: #339966; font-weight: bold;">function</span> GlobalExceptionHandler<span style="color: #000000;">&#40;</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;">loaderInfo</span><span style="color: #000066; font-weight: bold;">.</span>uncaughtErrorEvents<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">addEventListener</span><span style="color: #000000;">&#40;</span>UncaughtErrorEvent<span style="color: #000066; font-weight: bold;">.</span>UNCAUGHT_ERROR<span style="color: #000066; font-weight: bold;">,</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; uncaughtErrorHandler<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> uncaughtErrorHandler<span style="color: #000000;">&#40;</span>event<span style="color: #000066; font-weight: bold;">:</span>UncaughtErrorEvent<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;">for</span> <span style="color: #0033ff; font-weight: bold;">each</span> <span style="color: #000000;">&#40;</span><span style="color: #6699cc; font-weight: bold;">var</span> action<span style="color: #000066; font-weight: bold;">:</span>GlobalExceptionHandlerAction <span style="color: #0033ff; font-weight: bold;">in</span> handlerActions<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; action<span style="color: #000066; font-weight: bold;">.</span>handle<span style="color: #000000;">&#40;</span>event<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">error</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><span style="color: #004993;">preventDefault</span> == <span style="color: #0033ff; font-weight: bold;">true</span><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; event<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">preventDefault</span><span style="color: #000000;">&#40;</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 />
&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>
<p>The code for LogHandlerAction:</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>logging<br />
<span style="color: #000000;">&#123;</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 />
<br />
&nbsp; &nbsp; <span style="color: #0033ff; font-weight: bold;">public</span> <span style="color: #9900cc; font-weight: bold;">class</span> LogHandlerAction implements GlobalExceptionHandlerAction<br />
&nbsp; &nbsp; <span style="color: #000000;">&#123;</span><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;UncaughtException&quot;</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</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> handle<span style="color: #000000;">&#40;</span><span style="color: #004993;">error</span><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><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><span style="color: #004993;">error</span> <span style="color: #0033ff; font-weight: bold;">is</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; &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> errorObj<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: #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; &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}. {1}<span style="">\n</span> {2}&quot;</span><span style="color: #000066; font-weight: bold;">,</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; errorObj<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">errorID</span><span style="color: #000066; font-weight: bold;">,</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; errorObj<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">message</span><span style="color: #000066; font-weight: bold;">,</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; errorObj<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 />
&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/2010/05/13/global-exception-or-error-handling-in-flex/feed/</wfw:commentRss>
		<slash:comments>7</slash:comments>
		</item>
		<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>Disabling Bindings on certain Views to avoid unnecessary processing time</title>
		<link>http://www.rialvalue.com/blog/2010/05/05/disabling-bindings-on-certain-views-to-avoid-unnecessary-processing-time/</link>
		<comments>http://www.rialvalue.com/blog/2010/05/05/disabling-bindings-on-certain-views-to-avoid-unnecessary-processing-time/#comments</comments>
		<pubDate>Wed, 05 May 2010 14:35:55 +0000</pubDate>
		<dc:creator>Xavi Beumala</dc:creator>
				<category><![CDATA[General]]></category>
		<category><![CDATA[flex]]></category>
		<category><![CDATA[tips]]></category>
		<category><![CDATA[performance]]></category>

		<guid isPermaLink="false">http://www.rialvalue.com/blog/?p=169</guid>
		<description><![CDATA[Once a view has been created, Bindings will always be active no matter if the view is invisible or removed from Stage.
There might be cases when a View is constantly receiving Binding updates (i.e. connected to an LCDS server with big amount of data transfer or messages). Imagine the view that is processing all the [...]]]></description>
			<content:encoded><![CDATA[<p>Once a view has been created, Bindings will always be active no matter if the view is invisible or removed from Stage.<br />
There might be cases when a View is constantly receiving Binding updates (i.e. connected to an LCDS server with big amount of data transfer or messages). Imagine the view that is processing all the updates is off the screen. Although the most expensive part of the processing in terms of CPU is the UI and it&#8217;s not being processed because it&#8217;s invisible, We could still say it&#8217;s consuming resources unnecessarly.</p>
<p>If you want you can disable or enable selectively the Bindings in an mxml document using the BindingManager:</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">BindingManager<span style="color: #000066; font-weight: bold;">.</span>setEnabled<span style="color: #000000;">&#40;</span> document<span style="color: #000066; font-weight: bold;">,</span> <span style="color: #0033ff; font-weight: bold;">false</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span></div></div>
<p>You could enable or disable the bindings according to the visibility of the document.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.rialvalue.com/blog/2010/05/05/disabling-bindings-on-certain-views-to-avoid-unnecessary-processing-time/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Some thoughts on constructor and method parameters</title>
		<link>http://www.rialvalue.com/blog/2010/03/30/some-thoughts-on-method-parameters/</link>
		<comments>http://www.rialvalue.com/blog/2010/03/30/some-thoughts-on-method-parameters/#comments</comments>
		<pubDate>Tue, 30 Mar 2010 11:09:59 +0000</pubDate>
		<dc:creator>Xavi Beumala</dc:creator>
				<category><![CDATA[General]]></category>
		<category><![CDATA[flex]]></category>
		<category><![CDATA[tips]]></category>
		<category><![CDATA[as3]]></category>
		<category><![CDATA[best practices]]></category>
		<category><![CDATA[clean code]]></category>

		<guid isPermaLink="false">http://www.rialvalue.com/blog/?p=126</guid>
		<description><![CDATA[I consider a best practice to keep to the minimum the number of arguments a method accepts. As uncle Bob explains in his &#8220;Clean code&#8221; book we should always favour niladic (no arguments), monadic (1 argument) or dyadic (2 argument) methods and avoid whenever possible methods with more than 3 arguments, if not possible we [...]]]></description>
			<content:encoded><![CDATA[<p>I consider a best practice to keep to the minimum the number of arguments a method accepts. As uncle Bob explains in his &#8220;Clean code&#8221; book we should always favour niladic (no arguments), monadic (1 argument) or dyadic (2 argument) methods and avoid whenever possible methods with more than 3 arguments, if not possible we should be able to clearly justify them.</p>
<p><b>The higher number of arguments a method accepts the harder it&#8217;ll be to read, understand and test.</b></p>
<p>When a method needs too much arguments, it is normally a sign of:</p>
<ol>
<li>Poor encapsulation
<li>The method is doing more than one thing, breaking the Single Responsibility principle. The arguments define what the method will do, they define and change the method execution path. (i.e. flag methods)</li>
<li>Method signatures are harder to read and it&#8217;s easier to introduce errors by swapping the order of parameters (specially if they are of the same type). (link to FB issue to highlight parameters. i.e. assertEquals();)</li>
<li>Method parameters are all part of the same concept and could be encapsulated in an object with its own type.</li>
<li>Arguments belong to different levels of abstraction and are harder to understand.</li>
</ol>
<p><span id="more-126"></span><br />
<br/><br />
To reduce the number of arguments in class methods you can consider different techniques depending on what the exact problem is in each case:</p>
<ol>
<li>Create specialised objects that wrap several parameters. i.e. x, y could be a Point instance.</li>
<li>Transform method arguments into class properties so that they don&#8217;t need to be passed between methods.</li>
<li>Create different methods or strategies to fork the behaviour instead of using flag parameters</li>
<li>Use factory methods and builders.</li>
</ol>
<p><br/><br />
All points above can even get worse when overusing optional parameters, which lot of people use to alleviate the lack of method and constructor overloading in ActionScript3 instead of using Builders, Factories of creating different named methods.</p>
<p><br/><br />
If we focus on constructors I think they should only accept:</p>
<ol>
<li>Required parameters for the object to be properly initialised.</li>
<li>Optional invariant parameters. Parameters that can&#8217;t be changed during the life of the object and that thus need to be specified during born.</li>
</ol>
<p>Let&#8217;s consider the typical Person object with a name, surname, age and a unique invariant Id. We define a constructor with 1 required argument and 3 optional ones:</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: #9900cc; font-weight: bold;">class</span> Person <span style="color: #000000;">&#123;</span><br />
&nbsp; &nbsp; <span style="color: #0033ff; font-weight: bold;">private</span> <span style="color: #6699cc; font-weight: bold;">var</span> _id <span style="color: #000066; font-weight: bold;">:</span> <a href="http://www.google.com/search?q=int%20inurl:http://livedocs.adobe.com/flex/201/langref/%20inurl:int.html"><span style="color: #004993;">int</span></a><span style="color: #000066; font-weight: bold;">;</span><br />
<br />
&nbsp; &nbsp; <span style="color: #0033ff; font-weight: bold;">public</span> <span style="color: #6699cc; font-weight: bold;">var</span> <span style="color: #004993;">name</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: #000066; font-weight: bold;">;</span><br />
&nbsp; &nbsp; <span style="color: #0033ff; font-weight: bold;">public</span> <span style="color: #6699cc; font-weight: bold;">var</span> surname <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><br />
&nbsp; &nbsp; <span style="color: #0033ff; font-weight: bold;">public</span> <span style="color: #6699cc; font-weight: bold;">var</span> street <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 />
&nbsp; &nbsp; <span style="color: #0033ff; font-weight: bold;">public</span> <span style="color: #339966; font-weight: bold;">function</span> Person<span style="color: #000000;">&#40;</span> id <span style="color: #000066; font-weight: bold;">:</span> <a href="http://www.google.com/search?q=int%20inurl:http://livedocs.adobe.com/flex/201/langref/%20inurl:int.html"><span style="color: #004993;">int</span></a><span style="color: #000066; font-weight: bold;">,</span> <span style="color: #004993;">name</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;&quot;</span><span style="color: #000066; font-weight: bold;">,</span> surname<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;&quot;</span><span style="color: #000066; font-weight: bold;">,</span> streetString=<span style="color: #990000;">&quot;&quot;</span><span style="color: #000000;">&#41;</span> <span style="color: #000000;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0033ff; font-weight: bold;">this</span><span style="color: #000066; font-weight: bold;">.</span>_id = id<span style="color: #000066; font-weight: bold;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0033ff; font-weight: bold;">this</span><span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">name</span> = <span style="color: #004993;">name</span><span style="color: #000066; font-weight: bold;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0033ff; font-weight: bold;">this</span><span style="color: #000066; font-weight: bold;">.</span>surname = surname<span style="color: #000066; font-weight: bold;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0033ff; font-weight: bold;">this</span><span style="color: #000066; font-weight: bold;">.</span>street = street<span style="color: #000066; font-weight: bold;">;</span><br />
&nbsp; &nbsp; <span style="color: #000000;">&#125;</span><br />
<br />
&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> id<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=int%20inurl:http://livedocs.adobe.com/flex/201/langref/%20inurl:int.html"><span style="color: #004993;">int</span></a> <span style="color: #000000;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0033ff; font-weight: bold;">return</span> _id<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>You could create different instances 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> p1 <span style="color: #000066; font-weight: bold;">:</span> Person = <span style="color: #0033ff; font-weight: bold;">new</span> Person<span style="color: #000000;">&#40;</span> <span style="color: #000000; font-weight:bold;">1</span><span style="color: #000066; font-weight: bold;">,</span> <span style="color: #990000;">&quot;Xavi&quot;</span><span style="color: #000066; font-weight: bold;">,</span> <span style="color: #990000;">&quot;Beumala&quot;</span><span style="color: #000066; font-weight: bold;">,</span> <span style="color: #990000;">&quot;address1&quot;</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span><br />
<span style="color: #6699cc; font-weight: bold;">var</span> p2 <span style="color: #000066; font-weight: bold;">:</span> Person = <span style="color: #0033ff; font-weight: bold;">new</span> Person<span style="color: #000000;">&#40;</span> <span style="color: #000000; font-weight:bold;">2</span><span style="color: #000066; font-weight: bold;">,</span> <span style="color: #990000;">&quot;John&quot;</span><span style="color: #000066; font-weight: bold;">,</span> <span style="color: #0033ff; font-weight: bold;">null</span><span style="color: #000066; font-weight: bold;">,</span> <span style="color: #990000;">&quot;address2&quot;</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span><br />
<span style="color: #6699cc; font-weight: bold;">var</span> p3 <span style="color: #000066; font-weight: bold;">:</span> Person = <span style="color: #0033ff; font-weight: bold;">new</span> Person<span style="color: #000000;">&#40;</span> <span style="color: #000000; font-weight:bold;">3</span><span style="color: #000066; font-weight: bold;">,</span> <span style="color: #990000;">&quot;Andy&quot;</span><span style="color: #000066; font-weight: bold;">,</span> <span style="color: #990000;">&quot;address3&quot;</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span><br />
<span style="color: #6699cc; font-weight: bold;">var</span> p4 <span style="color: #000066; font-weight: bold;">:</span> Person = <span style="color: #0033ff; font-weight: bold;">new</span> Person<span style="color: #000000;">&#40;</span> 4<span style="color: #000066; font-weight: bold;">,</span> <span style="color: #0033ff; font-weight: bold;">null</span><span style="color: #000066; font-weight: bold;">,</span> <span style="color: #990000;">&quot;addres4&quot;</span><span style="color: #000066; font-weight: bold;">,</span> <span style="color: #990000;">&quot;Martin&quot;</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span></div></div>
<p>The code above will compile fine, the compiler won&#8217;t complain at all since all declarations are right, but there&#8217;re several data integrity errors here, errors that are normally very hard to find and isolate.  i.e. p3 is setting the address as the surname. p4 is swapping the surname and the address.</p>
<p>In this case, the Person type and the data might be self explanatory, but there are a bunch of other cases that are not. Having cluttered constructors with lots of optional parameters is quite common when dealing with Custom Events.</p>
<p>What would be interesting is to be able to pass the optional parameters in a named way, removing the order constraint while making the solution more readable, developer friendly and robust to changes:</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> p1 <span style="color: #000066; font-weight: bold;">:</span> Person = <span style="color: #0033ff; font-weight: bold;">new</span> PersonBuilder<span style="color: #000000;">&#40;</span> 1 <span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">name</span><span style="color: #000000;">&#40;</span> <span style="color: #990000;">'Xavi'</span> <span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">.</span>surname<span style="color: #000000;">&#40;</span> <span style="color: #990000;">'Beumala'</span> <span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">.</span>build<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span><br />
<span style="color: #6699cc; font-weight: bold;">var</span> p2 <span style="color: #000066; font-weight: bold;">:</span> Person = <span style="color: #0033ff; font-weight: bold;">new</span> PersonBuilder<span style="color: #000000;">&#40;</span> 2 <span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">name</span><span style="color: #000000;">&#40;</span> <span style="color: #990000;">'John'</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">.</span>address<span style="color: #000000;">&#40;</span><span style="color: #990000;">'address2'</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">.</span>build<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span><br />
<span style="color: #6699cc; font-weight: bold;">var</span> p3 <span style="color: #000066; font-weight: bold;">:</span> Person = <span style="color: #0033ff; font-weight: bold;">new</span> PersonBuilder<span style="color: #000000;">&#40;</span> 3 <span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">name</span><span style="color: #000000;">&#40;</span> <span style="color: #990000;">'Andy'</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">.</span>address<span style="color: #000000;">&#40;</span><span style="color: #990000;">'address3'</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">.</span>build<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span><br />
<span style="color: #6699cc; font-weight: bold;">var</span> p4 <span style="color: #000066; font-weight: bold;">:</span> Person = <span style="color: #0033ff; font-weight: bold;">new</span> PersonBuilder<span style="color: #000000;">&#40;</span> <span style="color: #000000; font-weight:bold;">4</span> <span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">.</span>address<span style="color: #000000;">&#40;</span><span style="color: #990000;">'address4'</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">.</span>surname<span style="color: #000000;">&#40;</span><span style="color: #990000;">'Martin'</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">.</span>build<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span></div></div>
<p>This solution is a kind of <a href="http://en.wikipedia.org/wiki/Builder_pattern">Buider pattern</a> implemented in a <a href="http://en.wikipedia.org/wiki/Fluent_interface">fluent way</a>, a train wreck. It&#8217;s also somehow mimicking <a href="http://en.wikipedia.org/wiki/Named_parameters">named parameters</a> in other languages. The nice things I really like about this syntax is:</p>
<ol>
<li>It&#8217;s a compact expression. It can be written in just one line.</li>
<li>The order of the optional parameters is not important anymore.</li>
<li>It&#8217;s easy to read and prevents parameter swapping. In some cases it can also be read as a natural language phrase.</li>
<li>In case of invariant optional parameters the builder can hide the implementation in the build method.</li>
<li>It doesn&#8217;t break <a href="http://en.wikipedia.org/wiki/Law_of_Demeter">Demeter&#8217;s law</a>. Although implemented as a train wreck, each method is applied on the same object.</li>
</ol>
<p><br/><br />
As mentioned above a common scenario where you could apply this technique is when dealing with custom events. Imagine you want to implement CRUD operations in terms of Persons. You could have:</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">PersonEvent<span style="color: #000066; font-weight: bold;">.</span>createPersonEvent<span style="color: #000000;">&#40;</span> <span style="color: #000066; font-weight: bold;">-</span>1 <span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">name</span><span style="color: #000000;">&#40;</span> <span style="color: #990000;">'Xavi'</span> <span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">.</span>surname<span style="color: #000000;">&#40;</span> <span style="color: #990000;">'Beumala'</span> <span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">bubbles</span><span style="color: #000000;">&#40;</span> <span style="color: #0033ff; font-weight: bold;">true</span> <span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">.</span>build<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span><br />
PersonEvent<span style="color: #000066; font-weight: bold;">.</span>removePersonEvent<span style="color: #000000;">&#40;</span> 2 <span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">cancelable</span><span style="color: #000000;">&#40;</span> <span style="color: #0033ff; font-weight: bold;">true</span> <span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">.</span>build<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span><br />
PersonEvent<span style="color: #000066; font-weight: bold;">.</span>updatePersonEvent<span style="color: #000000;">&#40;</span> <span style="color: #000000; font-weight:bold;">2</span> <span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">.</span>surname<span style="color: #000000;">&#40;</span> <span style="color: #990000;">'Smith'</span> <span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">.</span>build<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span><br />
PersonEvent<span style="color: #000066; font-weight: bold;">.</span>getPersonEvent<span style="color: #000000;">&#40;</span> 100 <span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">.</span>build<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span><br />
PersonEvent<span style="color: #000066; font-weight: bold;">.</span>getPeopleListEvent<span style="color: #000000;">&#40;</span> <span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">.</span>pageOffset<span style="color: #000000;">&#40;</span> 10 <span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">.</span>numResults<span style="color: #000000;">&#40;</span> 50 <span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">.</span>build<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span><br />
PersonEvent<span style="color: #000066; font-weight: bold;">.</span>getPeopleListEvent<span style="color: #000000;">&#40;</span> <span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">.</span>pageOffset<span style="color: #000000;">&#40;</span> 10 <span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">.</span>numResults<span style="color: #000000;">&#40;</span> 50 <span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">name</span><span style="color: #000000;">&#40;</span><span style="color: #990000;">'Xavi*'</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">.</span>build<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span></div></div>
<p><br/><br />
This implementation would allow you to reuse the same PersonEvent for the different operations without cluttering the constructor with all the different permutations of optional and required parameters in a scalable way. Another option in this case would be using static factory methods (but this won&#8217;t solve the optional parameters mess).</p>
]]></content:encoded>
			<wfw:commentRss>http://www.rialvalue.com/blog/2010/03/30/some-thoughts-on-method-parameters/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
		<item>
		<title>Using BlazeDS  from a Flash or AS3-only project</title>
		<link>http://www.rialvalue.com/blog/2010/03/27/using-blazeds-from-a-flash-or-as3-only-project/</link>
		<comments>http://www.rialvalue.com/blog/2010/03/27/using-blazeds-from-a-flash-or-as3-only-project/#comments</comments>
		<pubDate>Sat, 27 Mar 2010 11:54:28 +0000</pubDate>
		<dc:creator>Xavi Beumala</dc:creator>
				<category><![CDATA[blazeds]]></category>
		<category><![CDATA[flex]]></category>
		<category><![CDATA[lcds]]></category>
		<category><![CDATA[tips]]></category>
		<category><![CDATA[flash]]></category>
		<category><![CDATA[remoting]]></category>
		<category><![CDATA[rpc]]></category>

		<guid isPermaLink="false">http://www.rialvalue.com/blog/?p=116</guid>
		<description><![CDATA[Some weeks ago I had to develop a light version of an existing Flex application. The Flex application consumed lot of Java logic through services exposed by BlazeDS&#8217;s RemoteObjects. 
The goal was to be able to consume, from the new application, the exact same Java Services that the Flex application was consuming through RemoteObjects without [...]]]></description>
			<content:encoded><![CDATA[<p>Some weeks ago I had to develop a light version of an existing Flex application. The Flex application consumed lot of Java logic through services exposed by BlazeDS&#8217;s RemoteObjects. </p>
<p>The goal was to be able to consume, from the new application, the exact same Java Services that the Flex application was consuming through RemoteObjects without modifying the Java code or the server gateway at all.</p>
<p>This scenario could be a very common scenario in the near future when porting, adapting or extending existing applications to different devices targetting Flash Player 10.1. </p>
<p>BlazeDS uses some kind of handshake between the client and the server as well as control messages that were not obvious to replicate in a custom implementation using a plain NetConnection object. Also I wanted to make use of the several more complicated features that Flex rpc implementation brings.</p>
<p>Basically the problem became to  <strong>&#8220;How could I use the entire component set from rpc.swc distributed with Flex SDK in a Flash or AS3-only project?&#8221;</strong></p>
<p>This excercise is also applicable to WebService, HttpService, Consumer or Producer (messaging) classes.<br />
<span id="more-116"></span></p>
<h3>Step 1.</h3>
<p> Add rpc.swc from {FLEX_HOME}/framework/libs to your project or .fla classpath </p>
<h3>Step 2</h3>
<p> Compile some simple code using RemoteObjects:</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">const ENDPOINT <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;http://your.domain/messagebroker/amf&quot;</span><span style="color: #000066; font-weight: bold;">;</span><br />
const DESTINATION <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;workflowService&quot;</span><span style="color: #000066; font-weight: bold;">;</span><br />
<br />
remoteObject = <span style="color: #0033ff; font-weight: bold;">new</span> RemoteObject<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span><br />
remoteObject<span style="color: #000066; font-weight: bold;">.</span>destination = DESTINATION<span style="color: #000066; font-weight: bold;">;</span><br />
remoteObject<span style="color: #000066; font-weight: bold;">.</span>endpoint = ENDPOINT<span style="color: #000066; font-weight: bold;">;</span><br />
remoteObject<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">addEventListener</span><span style="color: #000000;">&#40;</span> ResultEvent<span style="color: #000066; font-weight: bold;">.</span>RESULT<span style="color: #000066; font-weight: bold;">,</span> resultHandler <span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span><br />
remoteObject<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">addEventListener</span><span style="color: #000000;">&#40;</span> FaultEvent<span style="color: #000066; font-weight: bold;">.</span>FAULT<span style="color: #000066; font-weight: bold;">,</span> faultHandler <span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span><br />
remoteObject<span style="color: #000066; font-weight: bold;">.</span>findAll<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span></div></div>
<p>Compiling this code throws several different errors due to unsatisfied or missing dependencies:</p>
<p><quote>mx.logging.ILogger<br />
mx.rpc.IResponder<br />
</quote></p>
<p>These 2 classes are in framework.swc Copying the swc from the FlexSDK into your classpath will fix the issues.</p>
<h3>Step 3</h3>
<p> After that you&#8217;ll get errors due to missing resource bundles like:<br />
&#8220;Unable to resolve resource bundle &#8216;collections&#8217; for locale &#8216;en_US&#8217;&#8221;</p>
<p>Copying to the classpath the required resource bundles from {FLEX_SDK}/frameworks/locale/ will fix the problem. You&#8217;ll only need to copy rpc_rb.swc and framework_rb.swc</p>
<p>You will receive this error only if compiling the project using the Flex compiler. You won&#8217;t get this error if you compile your application in Flash.</p>
<h3>Step 4</h3>
<p> When the application finally compiles you&#8217;ll always get FaultEvents with not too much information. </p>
<p><quote>faultCode: &#8220;Client.Error.MessageSend&#8221;<br />
faultDetail: &#8220;Channel.Connect.Failed error null url: &#8216;null&#8217;&#8221;<br />
</quote></p>
<p>Using Charles I realized that the request was not even sent, something was  going wrong.</p>
<h3>Step 5</h3>
<p>  All RPC classes use the Flex logging API so enabling it in the Flash project could be helpful. To enable it we only need to add:</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">Log<span style="color: #000066; font-weight: bold;">.</span>addTarget<span style="color: #000000;">&#40;</span> <span style="color: #0033ff; font-weight: bold;">new</span> TraceTarget<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></div></div>
<h3>Step 6</h3>
<p> After a couple of hours of debugging I discovered that RPC library to properly work needs to be initialized in the following way:</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> <span style="color: #004993;">flash.display</span><span style="color: #000066; font-weight: bold;">.</span><a href="http://www.google.com/search?q=loaderinfo%20inurl:http://livedocs.adobe.com/flex/201/langref/%20inurl:loaderinfo.html"><span style="color: #004993;">LoaderInfo</span></a><span style="color: #000066; font-weight: bold;">;</span><br />
<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>mx_internal<span style="color: #000066; font-weight: bold;">;</span><br />
<span style="color: #0033ff; font-weight: bold;">import</span> mx<span style="color: #000066; font-weight: bold;">.</span>messaging<span style="color: #000066; font-weight: bold;">.</span>config<span style="color: #000066; font-weight: bold;">.</span>LoaderConfig<span style="color: #000066; font-weight: bold;">;</span><br />
<br />
use <span style="color: #004993;">namespace</span> mx_internal<span style="color: #000066; font-weight: bold;">;</span><br />
<br />
LoaderConfig<span style="color: #000066; font-weight: bold;">.</span>mx_internal<span style="color: #000066; font-weight: bold;">::</span>_url = <span style="color: #004993;">loaderInfo</span><span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">url</span><span style="color: #000066; font-weight: bold;">;</span><br />
LoaderConfig<span style="color: #000066; font-weight: bold;">.</span>mx_internal<span style="color: #000066; font-weight: bold;">::</span>_parameters = <span style="color: #004993;">loaderInfo</span><span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">parameters</span><span style="color: #000066; font-weight: bold;">;</span></div></div>
<p>Where loaderInfo is the loaderInfo object of the root Sprite of your application.</p>
<p>After adding the initialization code you will see the request going through in Charles.</p>
<h3>Step 7</h3>
<p> There&#8217;s still one last problem to solve:</p>
<p><quote>&#8220;TypeError: Error #1034: Type Coercion failed: cannot convert Object@20612a79 to mx.messaging.messages.ErrorMessage.&#8221;<br />
</quote></p>
<p>The error means that somewhere an ErrorMessage object was expected but instead an object of type Object is received. We need to register several types. This will happen with several different types of ojects. To solve it:</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: #004993;">registerClassAlias</span><span style="color: #000000;">&#40;</span><span style="color: #990000;">&quot;flex.messaging.messages.ErrorMessage&quot;</span><span style="color: #000066; font-weight: bold;">,</span> ErrorMessage<span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span><br />
<span style="color: #004993;">registerClassAlias</span><span style="color: #000000;">&#40;</span><span style="color: #990000;">&quot;flex.messaging.messages.CommandMessage&quot;</span><span style="color: #000066; font-weight: bold;">,</span> CommandMessage<span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span><br />
<span style="color: #004993;">registerClassAlias</span><span style="color: #000000;">&#40;</span><span style="color: #990000;">&quot;flex.messaging.messages.RemotingMessage&quot;</span><span style="color: #000066; font-weight: bold;">,</span> RemotingMessage<span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span><br />
<span style="color: #004993;">registerClassAlias</span><span style="color: #000000;">&#40;</span><span style="color: #990000;">&quot;flex.messaging.messages.AcknowledgeMessage &quot;</span><span style="color: #000066; font-weight: bold;">,</span> AcknowledgeMessage<span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span><br />
<span style="color: #004993;">registerClassAlias</span><span style="color: #000000;">&#40;</span><span style="color: #990000;">&quot;DSC&quot;</span><span style="color: #000066; font-weight: bold;">,</span> CommandMessageExt<span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span><br />
<span style="color: #004993;">registerClassAlias</span><span style="color: #000000;">&#40;</span><span style="color: #990000;">&quot;DSK&quot;</span><span style="color: #000066; font-weight: bold;">,</span> AcknowledgeMessageExt<span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span><br />
<span style="color: #004993;">registerClassAlias</span><span style="color: #000000;">&#40;</span><span style="color: #990000;">&quot;flex.messaging.config.ConfigMap&quot;</span><span style="color: #000066; font-weight: bold;">,</span> ConfigMap<span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span><br />
<span style="color: #004993;">registerClassAlias</span><span style="color: #000000;">&#40;</span><span style="color: #990000;">&quot;flex.messaging.io.ArrayCollection&quot;</span><span style="color: #000066; font-weight: bold;">,</span> ArrayCollection<span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span><br />
<span style="color: #004993;">registerClassAlias</span><span style="color: #000000;">&#40;</span><span style="color: #990000;">&quot;flex.messaging.io.ObjectProxy&quot;</span><span style="color: #000066; font-weight: bold;">,</span> ObjectProxy<span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span></div></div>
<p>After properly registering these classes everything should work as expected (the list of required registrations might not be complete, if you find a TypeCoercion error consider registering the object).</p>
<p>The entire code you need:</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: #0033ff; font-weight: bold;">import</span> <span style="color: #004993;">flash.display</span><span style="color: #000066; font-weight: bold;">.</span><a href="http://www.google.com/search?q=sprite%20inurl:http://livedocs.adobe.com/flex/201/langref/%20inurl:sprite.html"><span style="color: #004993;">Sprite</span></a><span style="color: #000066; font-weight: bold;">;</span><br />
<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=event%20inurl:http://livedocs.adobe.com/flex/201/langref/%20inurl:event.html"><span style="color: #004993;">Event</span></a><span style="color: #000066; font-weight: bold;">;</span><br />
<span style="color: #0033ff; font-weight: bold;">import</span> <span style="color: #004993;">flash.net</span><span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">registerClassAlias</span><span style="color: #000066; font-weight: bold;">;</span><br />
<br />
<span style="color: #0033ff; font-weight: bold;">import</span> mx<span style="color: #000066; font-weight: bold;">.</span>collections<span style="color: #000066; font-weight: bold;">.</span>ArrayCollection<span style="color: #000066; font-weight: bold;">;</span><br />
<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>mx_internal<span style="color: #000066; font-weight: bold;">;</span><br />
<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 />
<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>targets<span style="color: #000066; font-weight: bold;">.</span>TraceTarget<span style="color: #000066; font-weight: bold;">;</span><br />
<span style="color: #0033ff; font-weight: bold;">import</span> mx<span style="color: #000066; font-weight: bold;">.</span>messaging<span style="color: #000066; font-weight: bold;">.</span>config<span style="color: #000066; font-weight: bold;">.</span>ConfigMap<span style="color: #000066; font-weight: bold;">;</span><br />
<span style="color: #0033ff; font-weight: bold;">import</span> mx<span style="color: #000066; font-weight: bold;">.</span>messaging<span style="color: #000066; font-weight: bold;">.</span>config<span style="color: #000066; font-weight: bold;">.</span>LoaderConfig<span style="color: #000066; font-weight: bold;">;</span><br />
<span style="color: #0033ff; font-weight: bold;">import</span> mx<span style="color: #000066; font-weight: bold;">.</span>messaging<span style="color: #000066; font-weight: bold;">.</span>messages<span style="color: #000066; font-weight: bold;">.</span>AcknowledgeMessage<span style="color: #000066; font-weight: bold;">;</span><br />
<span style="color: #0033ff; font-weight: bold;">import</span> mx<span style="color: #000066; font-weight: bold;">.</span>messaging<span style="color: #000066; font-weight: bold;">.</span>messages<span style="color: #000066; font-weight: bold;">.</span>AcknowledgeMessageExt<span style="color: #000066; font-weight: bold;">;</span><br />
<span style="color: #0033ff; font-weight: bold;">import</span> mx<span style="color: #000066; font-weight: bold;">.</span>messaging<span style="color: #000066; font-weight: bold;">.</span>messages<span style="color: #000066; font-weight: bold;">.</span>CommandMessage<span style="color: #000066; font-weight: bold;">;</span><br />
<span style="color: #0033ff; font-weight: bold;">import</span> mx<span style="color: #000066; font-weight: bold;">.</span>messaging<span style="color: #000066; font-weight: bold;">.</span>messages<span style="color: #000066; font-weight: bold;">.</span>CommandMessageExt<span style="color: #000066; font-weight: bold;">;</span><br />
<span style="color: #0033ff; font-weight: bold;">import</span> mx<span style="color: #000066; font-weight: bold;">.</span>messaging<span style="color: #000066; font-weight: bold;">.</span>messages<span style="color: #000066; font-weight: bold;">.</span>ErrorMessage<span style="color: #000066; font-weight: bold;">;</span><br />
<span style="color: #0033ff; font-weight: bold;">import</span> mx<span style="color: #000066; font-weight: bold;">.</span>messaging<span style="color: #000066; font-weight: bold;">.</span>messages<span style="color: #000066; font-weight: bold;">.</span>RemotingMessage<span style="color: #000066; font-weight: bold;">;</span><br />
<span style="color: #0033ff; font-weight: bold;">import</span> mx<span style="color: #000066; font-weight: bold;">.</span>rpc<span style="color: #000066; font-weight: bold;">.</span>events<span style="color: #000066; font-weight: bold;">.</span>FaultEvent<span style="color: #000066; font-weight: bold;">;</span><br />
<span style="color: #0033ff; font-weight: bold;">import</span> mx<span style="color: #000066; font-weight: bold;">.</span>rpc<span style="color: #000066; font-weight: bold;">.</span>events<span style="color: #000066; font-weight: bold;">.</span>ResultEvent<span style="color: #000066; font-weight: bold;">;</span><br />
<span style="color: #0033ff; font-weight: bold;">import</span> mx<span style="color: #000066; font-weight: bold;">.</span>rpc<span style="color: #000066; font-weight: bold;">.</span>remoting<span style="color: #000066; font-weight: bold;">.</span>RemoteObject<span style="color: #000066; font-weight: bold;">;</span><br />
<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>ObjectProxy<span style="color: #000066; font-weight: bold;">;</span><br />
<br />
use <span style="color: #004993;">namespace</span> mx_internal<span style="color: #000066; font-weight: bold;">;</span><br />
<br />
const ENDPOINT <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;http://your.domain/messagebroker/amf&quot;</span><span style="color: #000066; font-weight: bold;">;</span><br />
const DESTINATION <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;workflowService&quot;</span><span style="color: #000066; font-weight: bold;">;</span><br />
<br />
<span style="color: #6699cc; font-weight: bold;">var</span> remoteObject <span style="color: #000066; font-weight: bold;">:</span> RemoteObject<span style="color: #000066; font-weight: bold;">;</span><br />
<br />
<span style="color: #339966; font-weight: bold;">function</span> registerObjects<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span> <span style="color: #000066; font-weight: bold;">:</span> <span style="color: #0033ff; font-weight: bold;">void</span><br />
<span style="color: #000000;">&#123;</span><br />
&nbsp; &nbsp; <span style="color: #004993;">registerClassAlias</span><span style="color: #000000;">&#40;</span> <span style="color: #990000;">&quot;flex.messaging.messages.ErrorMessage&quot;</span><span style="color: #000066; font-weight: bold;">,</span> ErrorMessage <span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span><br />
&nbsp; &nbsp; <span style="color: #004993;">registerClassAlias</span><span style="color: #000000;">&#40;</span> <span style="color: #990000;">&quot;flex.messaging.messages.CommandMessage&quot;</span><span style="color: #000066; font-weight: bold;">,</span> CommandMessage <span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span><br />
&nbsp; &nbsp; <span style="color: #004993;">registerClassAlias</span><span style="color: #000000;">&#40;</span> <span style="color: #990000;">&quot;flex.messaging.messages.RemotingMessage&quot;</span><span style="color: #000066; font-weight: bold;">,</span> RemotingMessage <span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span><br />
&nbsp; &nbsp; <span style="color: #004993;">registerClassAlias</span><span style="color: #000000;">&#40;</span> <span style="color: #990000;">&quot;flex.messaging.messages.AcknowledgeMessage &quot;</span><span style="color: #000066; font-weight: bold;">,</span> AcknowledgeMessage <span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span><br />
&nbsp; &nbsp; <span style="color: #004993;">registerClassAlias</span><span style="color: #000000;">&#40;</span> <span style="color: #990000;">&quot;DSC&quot;</span><span style="color: #000066; font-weight: bold;">,</span> CommandMessageExt <span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span><br />
&nbsp; &nbsp; <span style="color: #004993;">registerClassAlias</span><span style="color: #000000;">&#40;</span> <span style="color: #990000;">&quot;DSK&quot;</span><span style="color: #000066; font-weight: bold;">,</span> AcknowledgeMessageExt <span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span><br />
&nbsp; &nbsp; <span style="color: #004993;">registerClassAlias</span><span style="color: #000000;">&#40;</span> <span style="color: #990000;">&quot;flex.messaging.config.ConfigMap&quot;</span><span style="color: #000066; font-weight: bold;">,</span> ConfigMap <span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span><br />
&nbsp; &nbsp; <span style="color: #004993;">registerClassAlias</span><span style="color: #000000;">&#40;</span> <span style="color: #990000;">&quot;flex.messaging.io.ArrayCollection&quot;</span><span style="color: #000066; font-weight: bold;">,</span> ArrayCollection <span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span><br />
&nbsp; &nbsp; <span style="color: #004993;">registerClassAlias</span><span style="color: #000000;">&#40;</span> <span style="color: #990000;">&quot;flex.messaging.io.ObjectProxy&quot;</span><span style="color: #000066; font-weight: bold;">,</span> ObjectProxy <span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span><br />
<span style="color: #000000;">&#125;</span><br />
<br />
<br />
<span style="color: #339966; font-weight: bold;">function</span> initializeRPC<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span> <span style="color: #000066; font-weight: bold;">:</span> <span style="color: #0033ff; font-weight: bold;">void</span><br />
<span style="color: #000000;">&#123;</span><br />
&nbsp; &nbsp; LoaderConfig<span style="color: #000066; font-weight: bold;">.</span>mx_internal<span style="color: #000066; font-weight: bold;">::</span>_url = <span style="color: #004993;">loaderInfo</span><span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">url</span><span style="color: #000066; font-weight: bold;">;</span><br />
&nbsp; &nbsp; LoaderConfig<span style="color: #000066; font-weight: bold;">.</span>mx_internal<span style="color: #000066; font-weight: bold;">::</span>_parameters = <span style="color: #004993;">loaderInfo</span><span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">parameters</span><span style="color: #000066; font-weight: bold;">;</span><br />
<span style="color: #000000;">&#125;</span><br />
<br />
<br />
<span style="color: #339966; font-weight: bold;">function</span> initializeLogging<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span> <span style="color: #000066; font-weight: bold;">:</span> <span style="color: #0033ff; font-weight: bold;">void</span><br />
<span style="color: #000000;">&#123;</span><br />
&nbsp; &nbsp; Log<span style="color: #000066; font-weight: bold;">.</span>addTarget<span style="color: #000000;">&#40;</span> <span style="color: #0033ff; font-weight: bold;">new</span> TraceTarget<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 />
<span style="color: #000000;">&#125;</span><br />
<br />
<br />
<span style="color: #339966; font-weight: bold;">function</span> createRemoteObject<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span> <span style="color: #000066; font-weight: bold;">:</span> <span style="color: #0033ff; font-weight: bold;">void</span><br />
<span style="color: #000000;">&#123;</span><br />
&nbsp; &nbsp; remoteObject = <span style="color: #0033ff; font-weight: bold;">new</span> RemoteObject<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span><br />
&nbsp; &nbsp; remoteObject<span style="color: #000066; font-weight: bold;">.</span>destination = DESTINATION<span style="color: #000066; font-weight: bold;">;</span><br />
&nbsp; &nbsp; remoteObject<span style="color: #000066; font-weight: bold;">.</span>endpoint = ENDPOINT<span style="color: #000066; font-weight: bold;">;</span><br />
&nbsp; &nbsp; remoteObject<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">addEventListener</span><span style="color: #000000;">&#40;</span> ResultEvent<span style="color: #000066; font-weight: bold;">.</span>RESULT<span style="color: #000066; font-weight: bold;">,</span> resultHandler <span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span><br />
&nbsp; &nbsp; remoteObject<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">addEventListener</span><span style="color: #000000;">&#40;</span> FaultEvent<span style="color: #000066; font-weight: bold;">.</span>FAULT<span style="color: #000066; font-weight: bold;">,</span> faultHandler <span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span><br />
&nbsp; &nbsp; remoteObject<span style="color: #000066; font-weight: bold;">.</span>findAll<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span><br />
<span style="color: #000000;">&#125;</span><br />
<br />
<br />
<span style="color: #339966; font-weight: bold;">function</span> resultHandler<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 />
<span style="color: #000000;">&#123;</span><br />
&nbsp; &nbsp; <span style="color: #004993;">trace</span><span style="color: #000000;">&#40;</span> <span style="color: #990000;">&quot;invocation successful&quot;</span> <span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span><br />
<span style="color: #000000;">&#125;</span><br />
<br />
<br />
<span style="color: #339966; font-weight: bold;">function</span> faultHandler<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 />
<span style="color: #000000;">&#123;</span><br />
&nbsp; &nbsp; <span style="color: #004993;">trace</span><span style="color: #000000;">&#40;</span> <span style="color: #990000;">&quot;invocation failed&quot;</span> <span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span><br />
<span style="color: #000000;">&#125;</span><br />
<br />
registerObjects<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span><br />
initializeLogging<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><br />
initializeRPC<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span><br />
createRemoteObject<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span></div></div>
<h2>Pros and cons of the solution </h2>
<ul>
<li>~100Kb footprint</li>
<li>You can focus on adding value and not building the infrastructure.</li>
<li>Faster time to market</li>
<li>Solid market solution</li>
</ul>
<h2>Improvement points</h2>
<p>Using the above solution you&#8217;ll have to work with ArrayCollection instead of Arrays which in certain situations might not be necessary, might have a performance impact as well as increase the number of class dependencies and file size.</p>
<p>One possible way to get rid of ArrayCollection and all its dependencies (i.e. ListCollectionView, Cursor, SystemManager, etc.) would be to create your own map. Instead of using:</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: #004993;">registerClassAlias</span><span style="color: #000000;">&#40;</span> <span style="color: #990000;">&quot;flex.messaging.io.ArrayCollection&quot;</span><span style="color: #000066; font-weight: bold;">,</span> ArrayCollection <span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span></div></div>
<p>You could use:</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: #004993;">registerClassAlias</span><span style="color: #000000;">&#40;</span> <span style="color: #990000;">&quot;flex.messaging.io.ArrayCollection&quot;</span><span style="color: #000066; font-weight: bold;">,</span> YourClass <span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span></div></div>
<p>Where your class would implement IExternalizable. This class could be completely light and would mean a considerable improvement in terms of dependencies and lighter implementation.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.rialvalue.com/blog/2010/03/27/using-blazeds-from-a-flash-or-as3-only-project/feed/</wfw:commentRss>
		<slash:comments>17</slash:comments>
		</item>
	</channel>
</rss>

