<?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>Farata Systems &#187; Victor Rasputnis</title>
	<atom:link href="http://flexblog.faratasystems.com/author/victor/feed" rel="self" type="application/rss+xml" />
	<link>http://flexblog.faratasystems.com</link>
	<description>A blog about our experience with Adobe Flex</description>
	<lastBuildDate>Tue, 31 Aug 2010 01:46:01 +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>Using Flex 4 Skin Inheritance To Make PictureButton Component</title>
		<link>http://flexblog.faratasystems.com/2010/02/17/using-flex-4-skin-inheritance-to-make-picturebutton-component</link>
		<comments>http://flexblog.faratasystems.com/2010/02/17/using-flex-4-skin-inheritance-to-make-picturebutton-component#comments</comments>
		<pubDate>Wed, 17 Feb 2010 19:27:14 +0000</pubDate>
		<dc:creator>Victor Rasputnis</dc:creator>
				<category><![CDATA[Flex]]></category>
		<category><![CDATA[Flex 2]]></category>

		<guid isPermaLink="false">http://flexblog.faratasystems.com/?p=627</guid>
		<description><![CDATA[Coming across several blogs that hint that custom Spark skins should not be created via OOP inheritance I felt challenged.  After all, Spark skins are using inheritance already, so why should I be stripped of something I am so used to? In this post , I will create a PictureButton component that injects image [...]]]></description>
			<content:encoded><![CDATA[<p>Coming across several <a href="http://www.flexjunk.com/2009/08/03/flex-4-skinning-ignores-developer-needs/">blogs</a> that hint that custom Spark skins should not be created via OOP inheritance I felt challenged.  After all, Spark skins are using inheritance already, so why should I be stripped of something I am so used to? In this post , I will create a PictureButton component that injects image into the Spark Button:</p>
<div class="quickcodenoclick"><code> &lt;PictureButton label=&quot;My PictureButton&quot;&nbsp;&nbsp;pictureGroupName=&quot;statistic&quot; skinClass=&quot;PictureButtonSkin&quot; /&gt;<br />
</code></div>
<p>This is how the button looks <img src="http://flexblog.faratasystems.com/images/627/PictureButton.png" alt="PictureButton" />and you can run view-source enabled <a href="http://flexblog.faratasystems.com/images/627/PictureButtonDemo.html">demo application</a> if you, like me, do not have patience for the wordy blogs. PictureButton component features <code>pictureGroupName</code> property, which represents the common &#8220;group name&#8221; of three images for &#8220;up&#8221;, &#8220;over&#8221; and &#8220;down&#8221; states. Mangled with the &#8220;_up&#8221;, &#8220;_over&#8221; and &#8220;_down&#8221; suffixes it should yield the real image URLs (e.g. <em>assets/statistic_up.png, assets/statistic_down/png</em> etc.) :<em><br />
</em><br />
Clearly, creating <code>public class PictureButton extends spark.skins.sparkButton</code> is a must, if anything &#8211;  just to carry arround the <code>pictureGroupName</code>. Then we have three choices for the <code>PictureButtonSkin</code>:<br />
a) create a brand new skin (this had been <a href="http://www.andymcintosh.com/?p=179">done before</a>)<br />
b) massage the clone of <code>spark.skins.spark.ButtonSkin</code><br />
c) build a descendant (in OOP terms)  of the Spark skin.<em></em></p>
<p><em>This post is focusing on the last two approaches, particularly highlighting the OOP way.<br />
</em><br />
<strong>Making Picture Button Skin By Cloning And Massaging Spark Button Skin</strong><em><br />
</em><br />
Massaging the original skin we redirect the <code>HostComponent</code> to point to our forthcoming <code>PictureButton</code>. Then, in the last,  8-th layer of original skin, we wrap the <code>labelDisplay</code> skin part with the <code>VGroup</code> and inject a <code>bitmapImage</code>. The &#8220;up&#8221;, &#8220;over&#8221; and &#8220;down&#8221; variants of the <code>bitmapImage.source</code> are bound to the bitmaps carried within the &#8220;hostComponent&#8221; :</p>

<div class="wp_codebox_msgheader"><span class="left"><a href="javascript:;" onclick="javascript:showCodeTxt('p627code7'); return false;">Flat PictureButton Skin (no inheritance)</a> </span><div class="codebox_clear"></div></div><div class="wp_codebox"><table width="100%" ><tr id="p6277"><td class="code" id="p627code7"><pre class="mxml" style="font-family:monospace;"><span style="color: #000000;">&lt;?xml version=<span style="color: #990000;">&quot;1.0&quot;</span> encoding=<span style="color: #990000;">&quot;utf-8&quot;</span>?<span style="color: #0033ff;">&gt;</span></span>
<span style="color: #000000;"><span style="color: #0033ff;">&lt;s:SparkSkin</span> xmlns:fx=<span style="color: #990000;">&quot;http://ns.adobe.com/mxml/2009&quot;</span> xmlns:s=<span style="color: #990000;">&quot;library://ns.adobe.com/flex/spark&quot;</span> </span>
<span style="color: #000000;">             xmlns:fb=<span style="color: #990000;">&quot;http://ns.adobe.com/flashbuilder/2009&quot;</span> minWidth=<span style="color: #990000;">&quot;21&quot;</span> minHeight=<span style="color: #990000;">&quot;21&quot;</span> alpha.disabled=<span style="color: #990000;">&quot;0.5&quot;</span></span>
<span style="color: #000000;">	 <span style="color: #0033ff;">&gt;</span></span>
	<span style="color: #000000;"><span style="color: #0033ff;">&lt;fx:Metadata</span><span style="color: #0033ff;">&gt;</span></span>
		<span style="color: #000000;">&lt;!<span style="color: #66cc66;">&#91;</span>CDATA<span style="color: #66cc66;">&#91;</span></span>
<span style="color: #000000;">		<span style="color: #66cc66;">&#91;</span>HostComponent<span style="color: #66cc66;">&#40;</span><span style="color: #990000;">&quot;PictureButton&quot;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#93;</span></span>
<span style="color: #000000;">		<span style="color: #66cc66;">&#93;</span><span style="color: #66cc66;">&#93;</span><span style="color: #0033ff;">&gt;</span></span>
       <span style="color: #000000;"><span style="color: #808080; font-style: italic;">&lt;!-- The rest of the original spark.skins.spark.ButtonSkin - till layer 8  is omitted for brevity --&gt;</span></span>
	.  .  .  .  .
	<span style="color: #000000;"><span style="color: #808080; font-style: italic;">&lt;!-- layer 8: text --&gt;</span></span>
	<span style="color: #000000;"><span style="color: #808080; font-style: italic;">&lt;!-- @copy spark.components.supportClasses.ButtonBase#labelDisplay --&gt;</span></span>
	<span style="color: #000000;"><span style="color: #808080; font-style: italic;">&lt;!-- WE COMMENTED OUT ORIGINAL labelDisplay</span>
<span style="color: #000000;">         &lt;s:Label id=&quot;labelDisplay&quot;</span>
<span style="color: #000000;">			 textAlign=&quot;center&quot; verticalAlign=&quot;middle&quot;</span>
<span style="color: #000000;">			 maxDisplayedLines=&quot;1&quot;</span>
<span style="color: #000000;">			 horizontalCenter=&quot;0&quot; verticalCenter=&quot;1&quot;</span>
<span style="color: #000000;">			 left=&quot;10&quot; right=&quot;10&quot; top=&quot;2&quot; bottom=&quot;2&quot;&gt;</span></span>
	<span style="color: #000000;"><span style="color: #0033ff;">&lt;/s:Label</span><span style="color: #0033ff;">&gt;</span></span> 
         --&gt;
	<span style="color: #000000;"><span style="color: #0033ff;">&lt;s:VGroup</span>  horizontalAlign=<span style="color: #990000;">&quot;center&quot;</span>  verticalAlign=<span style="color: #990000;">&quot;middle&quot;</span> left=<span style="color: #990000;">&quot;3&quot;</span> right=<span style="color: #990000;">&quot;3&quot;</span></span>
<span style="color: #000000;">			   paddingTop=<span style="color: #990000;">&quot;3&quot;</span> paddingBottom=<span style="color: #990000;">&quot;3&quot;</span> </span>
<span style="color: #000000;">			   paddingLeft=<span style="color: #990000;">&quot;3&quot;</span> paddingRight=<span style="color: #990000;">&quot;3&quot;</span> </span>
<span style="color: #000000;">				   <span style="color: #0033ff;">&gt;</span></span>			
		<span style="color: #000000;"><span style="color: #0033ff;">&lt;s:BitmapImage</span>  id=<span style="color: #990000;">&quot;bitmapImage&quot;</span> </span>
<span style="color: #000000;">			  source.up=<span style="color: #990000;">&quot;{hostComponent.bitmapImageUp}&quot;</span></span>
<span style="color: #000000;">			  source.over=<span style="color: #990000;">&quot;{hostComponent.bitmapImageOver}&quot;</span></span>
<span style="color: #000000;">			  source.down=<span style="color: #990000;">&quot;{hostComponent.bitmapImageDown}&quot;</span></span>
<span style="color: #000000;">		<span style="color: #0033ff;">/&gt;</span></span>
&nbsp;
		<span style="color: #000000;"><span style="color: #0033ff;">&lt;s:Label</span> id=<span style="color: #990000;">&quot;labelDisplay&quot;</span> left=<span style="color: #990000;">&quot;10&quot;</span> right=<span style="color: #990000;">&quot;10&quot;</span> top=<span style="color: #990000;">&quot;2&quot;</span> bottom=<span style="color: #990000;">&quot;2&quot;</span></span>
<span style="color: #000000;">			  textAlign=<span style="color: #990000;">&quot;center&quot;</span> verticalAlign=<span style="color: #990000;">&quot;middle&quot;</span> </span>
<span style="color: #000000;">			  maxDisplayedLines=<span style="color: #990000;">&quot;1&quot;</span> </span>
<span style="color: #000000;">		<span style="color: #0033ff;">/&gt;</span></span>
	<span style="color: #000000;"><span style="color: #0033ff;">&lt;/s:VGroup</span><span style="color: #0033ff;">&gt;</span></span>		
<span style="color: #000000;"><span style="color: #0033ff;">&lt;/s:SparkSkin</span><span style="color: #0033ff;">&gt;</span></span></pre></td></tr></table></div>

<p>Now, let&#8217;s supplement this skin with the matching <code>PictureButton</code> code.<br />
<em><br />
</em><br />
<strong>PictureButton Component</strong><br />
To make the very PictureButton we extend the Spark button and instantly create three SWFLoaders to facilitate load of three images:</p>

<div class="wp_codebox_msgheader"><span class="left"><a href="javascript:;" onclick="javascript:showCodeTxt('p627code8'); return false;">PictureButton Component: Image loaders</a> </span><div class="codebox_clear"></div></div><div class="wp_codebox"><table width="100%" ><tr id="p6278"><td class="code" id="p627code8"><pre class="actionscript" style="font-family:monospace;"><span style="color: #0066CC;">public</span> <span style="color: #000000; font-weight: bold;">class</span> PictureButton <span style="color: #0066CC;">extends</span> <span style="color: #0066CC;">Button</span>	<span style="color: #66cc66;">&#123;</span>
      <span style="color: #0066CC;">private</span> <span style="color: #000000; font-weight: bold;">var</span> loaderUp:SWFLoader;
      <span style="color: #0066CC;">private</span> <span style="color: #000000; font-weight: bold;">var</span> loaderDown:SWFLoader;
      <span style="color: #0066CC;">private</span> <span style="color: #000000; font-weight: bold;">var</span> loaderOver:SWFLoader;
&nbsp;
       <span style="color: #0066CC;">public</span> <span style="color: #000000; font-weight: bold;">function</span> PictureButton<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>
	<span style="color: #66cc66;">&#123;</span>
	        <span style="color: #0066CC;">super</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;
		loaderUp = <span style="color: #000000; font-weight: bold;">new</span> SWFLoader;
		loaderDown = <span style="color: #000000; font-weight: bold;">new</span> SWFLoader<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;
		loaderOver = <span style="color: #000000; font-weight: bold;">new</span> SWFLoader<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;
		loaderUp.<span style="color: #006600;">addEventListener</span><span style="color: #66cc66;">&#40;</span>Event.<span style="color: #006600;">COMPLETE</span>, <span style="color: #0066CC;">onLoadComplete</span><span style="color: #66cc66;">&#41;</span>;
		loaderDown.<span style="color: #006600;">addEventListener</span><span style="color: #66cc66;">&#40;</span>Event.<span style="color: #006600;">COMPLETE</span>, <span style="color: #0066CC;">onLoadComplete</span><span style="color: #66cc66;">&#41;</span>;
		loaderOver.<span style="color: #006600;">addEventListener</span><span style="color: #66cc66;">&#40;</span>Event.<span style="color: #006600;">COMPLETE</span>, <span style="color: #0066CC;">onLoadComplete</span><span style="color: #66cc66;">&#41;</span>;
	<span style="color: #66cc66;">&#125;</span>
...</pre></td></tr></table></div>

<p>Changing of the <code>pictureGroupName</code> will result in loading of the pictures, according to the setter below:</p>

<div class="wp_codebox_msgheader"><span class="left"><a href="javascript:;" onclick="javascript:showCodeTxt('p627code9'); return false;">PictureButton Component: pictureGroupName accessors</a> </span><div class="codebox_clear"></div></div><div class="wp_codebox"><table width="100%" ><tr id="p6279"><td class="code" id="p627code9"><pre class="actionscript" style="font-family:monospace;">		<span style="color: #0066CC;">private</span> <span style="color: #000000; font-weight: bold;">var</span> _pictureGroupName:<span style="color: #0066CC;">String</span>;
&nbsp;
		<span style="color: #66cc66;">&#91;</span>Bindable<span style="color: #66cc66;">&#93;</span>
		<span style="color: #0066CC;">public</span> <span style="color: #000000; font-weight: bold;">function</span> <span style="color: #0066CC;">set</span> pictureGroupName <span style="color: #66cc66;">&#40;</span>value:<span style="color: #0066CC;">String</span><span style="color: #66cc66;">&#41;</span>:<span style="color: #0066CC;">void</span> <span style="color: #66cc66;">&#123;</span>
			<span style="color: #b1b100;">if</span> <span style="color: #66cc66;">&#40;</span>_pictureGroupName <span style="color: #66cc66;">!</span>== value<span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#123;</span>
				_pictureGroupName = value;
				loadPictures<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;
			<span style="color: #66cc66;">&#125;</span>
		<span style="color: #66cc66;">&#125;</span>
&nbsp;
		<span style="color: #0066CC;">public</span> <span style="color: #000000; font-weight: bold;">function</span> <span style="color: #0066CC;">get</span> pictureGroupName<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>:<span style="color: #0066CC;">String</span> <span style="color: #66cc66;">&#123;</span>
			<span style="color: #b1b100;">return</span> _pictureGroupName;
		<span style="color: #66cc66;">&#125;</span>
&nbsp;
		<span style="color: #0066CC;">private</span> <span style="color: #000000; font-weight: bold;">function</span> loadPictures<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>:<span style="color: #0066CC;">void</span> <span style="color: #66cc66;">&#123;</span>
			<span style="color: #b1b100;">if</span> <span style="color: #66cc66;">&#40;</span>loaderUp<span style="color: #66cc66;">&#41;</span> loaderUp.<span style="color: #0066CC;">load</span><span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">&quot;assets/&quot;</span> + pictureGroupName + <span style="color: #ff0000;">&quot;.png&quot;</span><span style="color: #66cc66;">&#41;</span>
			<span style="color: #b1b100;">if</span> <span style="color: #66cc66;">&#40;</span>loaderDown<span style="color: #66cc66;">&#41;</span> loaderDown.<span style="color: #0066CC;">load</span><span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">&quot;assets/&quot;</span> + pictureGroupName + <span style="color: #ff0000;">&quot;_down.png&quot;</span><span style="color: #66cc66;">&#41;</span>;
			<span style="color: #b1b100;">if</span> <span style="color: #66cc66;">&#40;</span>loaderOver<span style="color: #66cc66;">&#41;</span> loaderOver.<span style="color: #0066CC;">load</span><span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">&quot;assets/&quot;</span> + pictureGroupName + <span style="color: #ff0000;">&quot;_over.png&quot;</span><span style="color: #66cc66;">&#41;</span>;
		<span style="color: #66cc66;">&#125;</span></pre></td></tr></table></div>

<p>Finally, as images get loaded we populate corresponding bindable bitmapImage properties that our custom skin so much depends on. Note, that being public these properties can be set from outside; you can avoid using <code>pictureGroupName</code> whatsoever and, in particular, you may load all your images from module classes or CSS styles etc.</p>

<div class="wp_codebox_msgheader"><span class="left"><a href="javascript:;" onclick="javascript:showCodeTxt('p627code10'); return false;">PictureButton:Communicating to the Skin</a> </span><div class="codebox_clear"></div></div><div class="wp_codebox"><table width="100%" ><tr id="p62710"><td class="code" id="p627code10"><pre class="actionscript" style="font-family:monospace;">		<span style="color: #66cc66;">&#91;</span>Bindable<span style="color: #66cc66;">&#93;</span> <span style="color: #0066CC;">public</span> <span style="color: #000000; font-weight: bold;">var</span> bitmapImageUp:<span style="color: #0066CC;">Object</span>;
		<span style="color: #66cc66;">&#91;</span>Bindable<span style="color: #66cc66;">&#93;</span> <span style="color: #0066CC;">public</span> <span style="color: #000000; font-weight: bold;">var</span> bitmapImageDown:<span style="color: #0066CC;">Object</span>;
		<span style="color: #66cc66;">&#91;</span>Bindable<span style="color: #66cc66;">&#93;</span> <span style="color: #0066CC;">public</span> <span style="color: #000000; font-weight: bold;">var</span> bitmapImageOver:<span style="color: #0066CC;">Object</span>;
&nbsp;
		<span style="color: #0066CC;">private</span> <span style="color: #000000; font-weight: bold;">function</span> <span style="color: #0066CC;">onLoadComplete</span><span style="color: #66cc66;">&#40;</span>event:Event<span style="color: #66cc66;">&#41;</span>:<span style="color: #0066CC;">void</span> <span style="color: #66cc66;">&#123;</span>
			<span style="color: #b1b100;">if</span> <span style="color: #66cc66;">&#40;</span>event.<span style="color: #0066CC;">target</span> == loaderUp<span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#123;</span>
				bitmapImageUp = event.<span style="color: #0066CC;">target</span>.<span style="color: #006600;">content</span>;
			<span style="color: #66cc66;">&#125;</span> <span style="color: #b1b100;">else</span> <span style="color: #b1b100;">if</span> <span style="color: #66cc66;">&#40;</span>event.<span style="color: #0066CC;">target</span> == loaderDown<span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#123;</span>
				bitmapImageDown = event.<span style="color: #0066CC;">target</span>.<span style="color: #006600;">content</span>;
			<span style="color: #66cc66;">&#125;</span> <span style="color: #b1b100;">else</span> <span style="color: #b1b100;">if</span> <span style="color: #66cc66;">&#40;</span>event.<span style="color: #0066CC;">target</span> == loaderOver<span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#123;</span>
				bitmapImageOver = event.<span style="color: #0066CC;">target</span>.<span style="color: #006600;">content</span>;
			<span style="color: #66cc66;">&#125;</span>
		<span style="color: #66cc66;">&#125;</span>
&nbsp;
<span style="color: #66cc66;">&#125;</span></pre></td></tr></table></div>

<p>OK. Both skin and control are done,  but there is an afterthought: WHAT IF THE BASE SKIN CHANGES?<br />
Obviously, we will be out of sync. Hence the need for OOP approach.<br />
<em><br />
</em></p>
<p><strong>Making PictureButtonSkin WITH INHERITANCE</strong><br />
<em><br />
</em><br />
All we did in the cloned Skin was replacing original <em>labelDisplay</em> with the <em>VGroup</em> containing both <em>labelDisplay</em> AND <em>bitmapImage</em>.<br />
We did it with the declarative MXML, however the same can be done in ActionScript:</p>

<div class="wp_codebox_msgheader"><span class="left"><a href="javascript:;" onclick="javascript:showCodeTxt('p627code11'); return false;">PictureButtonSkin Inherited from ButtonSkin: UI components</a> </span><div class="codebox_clear"></div></div><div class="wp_codebox"><table width="100%" ><tr id="p62711"><td class="code" id="p627code11"><pre class="actionscript" style="font-family:monospace;">package
<span style="color: #66cc66;">&#123;</span>
        <span style="color: #0066CC;">import</span> ...
	<span style="color: #0066CC;">public</span> <span style="color: #000000; font-weight: bold;">class</span> PictureButtonSkin <span style="color: #0066CC;">extends</span> ButtonSkin      <span style="color: #66cc66;">&#123;</span>
&nbsp;
                protected override <span style="color: #000000; font-weight: bold;">function</span> childrenCreated<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>:<span style="color: #0066CC;">void</span> <span style="color: #66cc66;">&#123;</span>
		       <span style="color: #0066CC;">super</span>.<span style="color: #006600;">removeElement</span><span style="color: #66cc66;">&#40;</span>labelDisplay<span style="color: #66cc66;">&#41;</span>;
		       addElement<span style="color: #66cc66;">&#40;</span>createVGroup<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span>;
	               <span style="color: #0066CC;">super</span>.<span style="color: #006600;">childrenCreated</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;
	        <span style="color: #66cc66;">&#125;</span>
	        <span style="color: #66cc66;">&#91;</span>Bindable<span style="color: #66cc66;">&#93;</span>
		<span style="color: #0066CC;">public</span> <span style="color: #000000; font-weight: bold;">var</span> bitmapImage : spark.<span style="color: #006600;">primitives</span>.<span style="color: #006600;">BitmapImage</span>;
&nbsp;
		<span style="color: #0066CC;">private</span> <span style="color: #000000; font-weight: bold;">function</span> createVGroup<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>:VGroup
		<span style="color: #66cc66;">&#123;</span>
			<span style="color: #000000; font-weight: bold;">var</span> temp : spark.<span style="color: #006600;">components</span>.<span style="color: #006600;">VGroup</span> = <span style="color: #000000; font-weight: bold;">new</span> spark.<span style="color: #006600;">components</span>.<span style="color: #006600;">VGroup</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;
			temp.<span style="color: #006600;">horizontalAlign</span> = <span style="color: #ff0000;">&quot;center&quot;</span>;
			temp.<span style="color: #006600;">verticalAlign</span> = <span style="color: #ff0000;">&quot;middle&quot;</span>;
			temp.<span style="color: #0066CC;">left</span> = <span style="color: #cc66cc;">3</span>;
			temp.<span style="color: #0066CC;">right</span> = <span style="color: #cc66cc;">3</span>;
			temp.<span style="color: #006600;">paddingTop</span> = <span style="color: #cc66cc;">3</span>;
			temp.<span style="color: #006600;">paddingBottom</span> = <span style="color: #cc66cc;">3</span>;
			temp.<span style="color: #006600;">paddingLeft</span> = <span style="color: #cc66cc;">3</span>;
			temp.<span style="color: #006600;">paddingRight</span> = <span style="color: #cc66cc;">3</span>;
			temp.<span style="color: #006600;">mxmlContent</span> = <span style="color: #66cc66;">&#91;</span>createBitmapImage<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>, createLabel<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#93;</span>;
			<span style="color: #b1b100;">return</span> temp;
		<span style="color: #66cc66;">&#125;</span>
&nbsp;
		<span style="color: #0066CC;">private</span> <span style="color: #000000; font-weight: bold;">function</span> createBitmapImage<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span> : spark.<span style="color: #006600;">primitives</span>.<span style="color: #006600;">BitmapImage</span>
		<span style="color: #66cc66;">&#123;</span>
			bitmapImage = <span style="color: #000000; font-weight: bold;">new</span> BitmapImage<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;
			<span style="color: #b1b100;">return</span> bitmapImage;
		<span style="color: #66cc66;">&#125;</span>
&nbsp;
		<span style="color: #0066CC;">private</span> <span style="color: #000000; font-weight: bold;">function</span> createLabel<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span> : spark.<span style="color: #006600;">components</span>.<span style="color: #006600;">Label</span>
		<span style="color: #66cc66;">&#123;</span>
			labelDisplay  = <span style="color: #000000; font-weight: bold;">new</span> Label<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;
			labelDisplay.<span style="color: #0066CC;">left</span> = <span style="color: #cc66cc;">10</span>;
			labelDisplay.<span style="color: #0066CC;">right</span> = <span style="color: #cc66cc;">10</span>;
			labelDisplay.<span style="color: #006600;">top</span> = <span style="color: #cc66cc;">2</span>;
			labelDisplay.<span style="color: #006600;">bottom</span> = <span style="color: #cc66cc;">2</span>;
			labelDisplay.<span style="color: #006600;">maxDisplayedLines</span> = <span style="color: #cc66cc;">1</span>;
			labelDisplay.<span style="color: #0066CC;">setStyle</span><span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">&quot;textAlign&quot;</span>, <span style="color: #ff0000;">&quot;center&quot;</span><span style="color: #66cc66;">&#41;</span>;
			labelDisplay.<span style="color: #0066CC;">setStyle</span><span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">&quot;verticalAlign&quot;</span>, <span style="color: #ff0000;">&quot;middle&quot;</span><span style="color: #66cc66;">&#41;</span>;
			labelDisplay.<span style="color: #006600;">id</span> = <span style="color: #ff0000;">&quot;labelDisplay&quot;</span>;
			<span style="color: #b1b100;">return</span> labelDisplay;
		<span style="color: #66cc66;">&#125;</span>
<span style="color: #66cc66;">&#125;</span></pre></td></tr></table></div>

<p>Now, notice that we did not populate the <code>source</code> of the <code>bitmapImage</code>. The reason is that by diving into ActionScript we lost &#8220;luxury&#8221; of state-related code generation for &#8220;source.up&#8221;,  &#8220;source.over&#8221; and &#8220;source.down&#8221;. To complement this we have to listen to &#8220;stateChanging&#8221; event and adjust the source ourselves:<em><br />
</em></p>

<div class="wp_codebox_msgheader"><span class="left"><a href="javascript:;" onclick="javascript:showCodeTxt('p627code12'); return false;">PictureButton skin inherited from ButtonSkin: state management</a> </span><div class="codebox_clear"></div></div><div class="wp_codebox"><table width="100%" ><tr id="p62712"><td class="code" id="p627code12"><pre class="actionscript" style="font-family:monospace;"> 	<span style="color: #0066CC;">public</span> <span style="color: #000000; font-weight: bold;">class</span> PictureButtonSkin <span style="color: #0066CC;">extends</span> ButtonSkin
	<span style="color: #66cc66;">&#123;</span>
		<span style="color: #0066CC;">public</span> <span style="color: #000000; font-weight: bold;">function</span> PictureButtonSkin<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#123;</span>
			<span style="color: #0066CC;">super</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;
			addEventListener<span style="color: #66cc66;">&#40;</span>StateChangeEvent.<span style="color: #006600;">CURRENT_STATE_CHANGING</span>, onStateChanging<span style="color: #66cc66;">&#41;</span>;
		<span style="color: #66cc66;">&#125;</span>
                .  .  .  .
		<span style="color: #0066CC;">private</span> <span style="color: #000000; font-weight: bold;">function</span> onStateChanging<span style="color: #66cc66;">&#40;</span>event:StateChangeEvent<span style="color: #66cc66;">&#41;</span>:<span style="color: #0066CC;">void</span> <span style="color: #66cc66;">&#123;</span>
			<span style="color: #b1b100;">switch</span> <span style="color: #66cc66;">&#40;</span>event.<span style="color: #006600;">newState</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#123;</span>
				<span style="color: #b1b100;">case</span> <span style="color: #ff0000;">&quot;down&quot;</span>:
					bitmapImage.<span style="color: #006600;">source</span> = hostComponent<span style="color: #66cc66;">&#91;</span><span style="color: #ff0000;">&quot;bitmapImageDown&quot;</span><span style="color: #66cc66;">&#93;</span>;
					<span style="color: #b1b100;">break</span>;
				<span style="color: #b1b100;">case</span> <span style="color: #ff0000;">&quot;over&quot;</span>:
					bitmapImage.<span style="color: #006600;">source</span> = hostComponent<span style="color: #66cc66;">&#91;</span><span style="color: #ff0000;">&quot;bitmapImageOver&quot;</span><span style="color: #66cc66;">&#93;</span>;
					<span style="color: #b1b100;">break</span>;
				<span style="color: #b1b100;">case</span> <span style="color: #ff0000;">&quot;default&quot;</span>:
					bitmapImage.<span style="color: #006600;">source</span> = hostComponent<span style="color: #66cc66;">&#91;</span><span style="color: #ff0000;">&quot;bitmapImageUp&quot;</span><span style="color: #66cc66;">&#93;</span>;
			<span style="color: #66cc66;">&#125;</span>
		<span style="color: #66cc66;">&#125;</span>
<span style="color: #66cc66;">&#125;</span></pre></td></tr></table></div>

<p>And that is pretty much it.<br />
<em><br />
</em><br />
<strong>Conclusions</strong></p>
<p>Programmatic extension of skins is not that hard. As a developer, I prefer the OOP way to copy/paste.<br />
I am well aware that it breaks the Designer/Developer separation of concerns as it is currently (I stress, currently) envisioned by Adobe.<br />
I am well aware that using non-vector graphics in the first place, instead of Rect and Line primitives, has it&#8217;s own drawbacks.<br />
Yet, being realistic, most often than not I will not have a designer to draw for me.<br />
Neither do I get paid for drawing: I am a coder.</p>
<p>Why I like OOP? Less code.</p>
<p><a href="http://flexblog.faratasystems.com/images/627/PictureButtonDemo.html">Demo Application</a><br />
<a href="http://flexblog.faratasystems.com/images/627/srcview/index.html">SourceView</a></p>
<p>I&#8217;d like to use this opportunity and invite Flex developers living in Europe to attend our <a href="http://www.eventbrite.com/event/527934065">Advanced Flex Master Class in Brussels, Belgium on March 1 and 2, 2010</a>.</p>
<p>Victor Rasputnis</p>
]]></content:encoded>
			<wfw:commentRss>http://flexblog.faratasystems.com/2010/02/17/using-flex-4-skin-inheritance-to-make-picturebutton-component/feed</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Avoiding pitfalls of Flex RSL with Self Initialized Libraries</title>
		<link>http://flexblog.faratasystems.com/2010/01/27/taming-flex-rsl</link>
		<comments>http://flexblog.faratasystems.com/2010/01/27/taming-flex-rsl#comments</comments>
		<pubDate>Wed, 27 Jan 2010 23:55:31 +0000</pubDate>
		<dc:creator>Victor Rasputnis</dc:creator>
				<category><![CDATA[Flex]]></category>
		<category><![CDATA[Flex 4]]></category>
		<category><![CDATA[dynamic instantiation]]></category>
		<category><![CDATA[Flex4]]></category>
		<category><![CDATA[FlexModuleFactory]]></category>
		<category><![CDATA[monkey paching]]></category>
		<category><![CDATA[RSL]]></category>
		<category><![CDATA[self initialized library]]></category>

		<guid isPermaLink="false">http://flexblog.faratasystems.com/?p=585</guid>
		<description><![CDATA[Flex RSLs are notoriously naive in regards to dynamic object instantiation. Consider the following code snippet when the actual class descends Panel or it is a remoting DTO with the [RemoteClass] annotation:
var className:String = &#34;some.flex.class&#34;;
var clazz : Class = loaderInfo.applicationDomain.getDefinition(className) as Class;
var instance: Object = new clazz();

In either case, well being of the class is [...]]]></description>
			<content:encoded><![CDATA[<p>Flex RSLs are notoriously naive in regards to dynamic object instantiation. Consider the following code snippet when the actual class descends Panel or it is a remoting DTO with the <code>[RemoteClass]</code> annotation:</p>
<div class="quickcodenoclick"><code>var className:String = &quot;some.flex.class&quot;;<br />
var clazz : Class = loaderInfo.applicationDomain.getDefinition(className) as Class;<br />
var instance: Object = new clazz();<br />
</code></div>
<p>In either case, well being of the class is based on <strong>mixins</strong> &#8211; decorator classes generated by Flex compiler. Mixins carry obligatory <code>init(o:Object/*systemManager or moduleFactory*/)</code> method and get called to decorate startup class of the application (SystemManager) or the module (ModuleFactory). For instance, a class with <code>[RemoteClass(&quot;foo.Bar&quot;)]</code> annotation contributes  a similar looking fragment to the mixin class <code>_YourApplicationName_FlexInit</code>:</p>

<div class="wp_codebox_msgheader"><span class="left"><a href="javascript:;" onclick="javascript:showCodeTxt('p585code20'); return false;">View Code</a> </span><div class="codebox_clear"></div></div><div class="wp_codebox"><table width="100%" ><tr id="p58520"><td class="code" id="p585code20"><pre class="actionscript" style="font-family:monospace;">  <span style="color: #0066CC;">try</span> <span style="color: #66cc66;">&#123;</span>
      <span style="color: #b1b100;">if</span> <span style="color: #66cc66;">&#40;</span>flash.<span style="color: #006600;">net</span>.<span style="color: #006600;">getClassByAlias</span><span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">&quot;foo.Bar&quot;</span><span style="color: #66cc66;">&#41;</span> == <span style="color: #000000; font-weight: bold;">null</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#123;</span>
          flash.<span style="color: #006600;">net</span>.<span style="color: #006600;">registerClassAlias</span><span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">&quot;foo.Bar&quot;</span>, flex.<span style="color: #000000; font-weight: bold;">class</span>.<span style="color: #0066CC;">with</span>.<span style="color: #006600;">RemoteClassAnnotation</span><span style="color: #66cc66;">&#41;</span>;<span style="color: #66cc66;">&#125;</span>
  <span style="color: #66cc66;">&#125;</span> <span style="color: #0066CC;">catch</span> <span style="color: #66cc66;">&#40;</span><span style="color: #0066CC;">e</span>:<span style="color: #0066CC;">Error</span><span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#123;</span>
          flash.<span style="color: #006600;">net</span>.<span style="color: #006600;">registerClassAlias</span><span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">&quot;foo.Bar&quot;</span>, flex.<span style="color: #000000; font-weight: bold;">class</span>.<span style="color: #0066CC;">with</span>.<span style="color: #006600;">RemoteClassAnnotation</span><span style="color: #66cc66;">&#41;</span>; <span style="color: #66cc66;">&#125;</span></pre></td></tr></table></div>

<p>Similarly, a class that descends from a Panel depends on mixin <code>[_YourApplicationName]_Styles</code> to carry the following:</p>

<div class="wp_codebox_msgheader"><span class="left"><a href="javascript:;" onclick="javascript:showCodeTxt('p585code21'); return false;">View Code</a> </span><div class="codebox_clear"></div></div><div class="wp_codebox"><table width="100%" ><tr id="p58521"><td class="code" id="p585code21"><pre class="actionscript" style="font-family:monospace;">        .  .  .
        <span style="color: #808080; font-style: italic;">// spark.components.Panel</span>
        selector = <span style="color: #000000; font-weight: bold;">new</span> CSSSelector<span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">&quot;spark.components.Panel&quot;</span>, conditions, selector<span style="color: #66cc66;">&#41;</span>;
        mergedStyle = styleManager.<span style="color: #006600;">getMergedStyleDeclaration</span><span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">&quot;spark.components.Panel&quot;</span><span style="color: #66cc66;">&#41;</span>;
        style = <span style="color: #000000; font-weight: bold;">new</span> CSSStyleDeclaration<span style="color: #66cc66;">&#40;</span>selector, styleManager, mergedStyle == <span style="color: #000000; font-weight: bold;">null</span><span style="color: #66cc66;">&#41;</span>;
        . . .</pre></td></tr></table></div>

<p>Now, here is the problem. If you hide your class behind <code>getDefinition()</code> Flex compiler does not contribute to either _FlexInit or _Styles mixins. In other words, your RSL may contain 100 classes, all of them will be loaded, but they will be lacking proper initialization if you did not explicitly reference them in the application.<br />
<em><br />
</em><br />
<strong>Problem Illustration</strong></p>
<p>Let&#8217;s illustrate.  On the left is the application that on button click &#8230; fails to dynamically instantiate a custom panel from standard Flex RSL. On the right we show working application AFTER the solution has been applied (Patience, reader, patience!)<br />
<img class="aligncenter" src="http://flexblog.faratasystems.com/images/407/bad_app_good_app.png" alt="Sample application with problem before and after treatment" /><br />
Here is the application code:</p>

<div class="wp_codebox_msgheader"><span class="left"><a href="javascript:;" onclick="javascript:showCodeTxt('p585code22'); return false;">View Code</a> </span><div class="codebox_clear"></div></div><div class="wp_codebox"><table width="100%" ><tr id="p58522"><td class="code" id="p585code22"><pre class="mxml" style="font-family:monospace;">	<span style="color: #000000;">&lt;!<span style="color: #66cc66;">&#91;</span>CDATA<span style="color: #66cc66;">&#91;</span></span>
<span style="color: #000000;">			import mx.core.IVisualElement;</span>
<span style="color: #000000;">			private var visualElement:IVisualElement;</span>
<span style="color: #000000;">			//import spark.components.Panel;Panel; // That would be too simple :<span style="color: #66cc66;">&#41;</span></span>
<span style="color: #000000;">			private function createComponent<span style="color: #66cc66;">&#40;</span>componentName:String<span style="color: #66cc66;">&#41;</span> : void <span style="color: #66cc66;">&#123;</span></span>
<span style="color: #000000;">				var clazz : Class = loaderInfo.applicationDomain.getDefinition<span style="color: #66cc66;">&#40;</span>componentName<span style="color: #66cc66;">&#41;</span> as Class;</span>
<span style="color: #000000;">				visualElement = IVisualElement<span style="color: #66cc66;">&#40;</span>new clazz<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#41;</span>;</span>
<span style="color: #000000;">				addElement<span style="color: #66cc66;">&#40;</span>visualElement<span style="color: #66cc66;">&#41;</span>;</span>
<span style="color: #000000;">			<span style="color: #66cc66;">&#125;</span></span>
<span style="color: #000000;">	<span style="color: #66cc66;">&#93;</span><span style="color: #66cc66;">&#93;</span><span style="color: #0033ff;">&gt;</span></span></pre></td></tr></table></div>

<p><em><br />
</em>The very custom panel is hosted by a separate Flex Library Project &#8211; ComponentLibrary:</p>

<div class="wp_codebox_msgheader"><span class="left"><a href="javascript:;" onclick="javascript:showCodeTxt('p585code23'); return false;">View Code</a> </span><div class="codebox_clear"></div></div><div class="wp_codebox"><table width="100%" ><tr id="p58523"><td class="code" id="p585code23"><pre class="mxml" style="font-family:monospace;">		public static var count:int;
       [Bindable] private var instanceNumber:int;</pre></td></tr></table></div>

<p>Make sure the link type of the ComponentLibrary is set to &#8220;RSL&#8221;. Run the application, click on the Button &#8211; you won&#8217;t see any panels. Better yet, Debug (instead of Run) and you will notice console trace statements of the panels actually being created. However, custom panel is not shown, because _Styles mixin lacks section for ancestor &#8211; Spark Panel.<br />
<em><br />
</em><br />
<strong>Solution</strong></p>
<p>So what is the solution? Obviously, the Adobe RSL SWF has to be replaced by something else. By default, ComponentLibrary.swf get extracted from ComponentLibrary.swc on every build of the application. But, if we turn off the &#8220;AutoExtract&#8221; checkbox, we are free to replace it with the SWF of our own making.  Which one? A sub-application SWF.  Instead of a headless, single framed RSL SWF, we will use double framed application SWF adding a descendant of the mx.core.SimpleApplication as a head class. Within such head class we can statically reference all library classes. As a result, compiler will generate required mixins within the &#8220;library&#8221; SWF. That is why in Farata we coined the term   <strong>self-initialized library</strong>, meaning that classes in our library do not need external initialization by the Flex compiler:<br />
<em><br />
</em></p>

<div class="wp_codebox_msgheader"><span class="left"><a href="javascript:;" onclick="javascript:showCodeTxt('p585code24'); return false;">View Code</a> </span><div class="codebox_clear"></div></div><div class="wp_codebox"><table width="100%" ><tr id="p58524"><td class="code" id="p585code24"><pre class="actionscript" style="font-family:monospace;">package <span style="color: #66cc66;">&#123;</span>
  <span style="color: #0066CC;">import</span> mx.<span style="color: #006600;">core</span>.<span style="color: #006600;">SimpleApplication</span>;
  <span style="color: #0066CC;">public</span> <span style="color: #000000; font-weight: bold;">class</span> LibraryHead <span style="color: #0066CC;">extends</span> SimpleApplication <span style="color: #66cc66;">&#123;</span>
&nbsp;
        <span style="color: #808080; font-style: italic;">// List all library classes here, so Flex compiler will take care of them</span>
        <span style="color: #0066CC;">import</span>  com.<span style="color: #006600;">farata</span>.<span style="color: #006600;">samples</span>.<span style="color: #006600;">CustomPanel</span>;com.<span style="color: #006600;">farata</span>.<span style="color: #006600;">samples</span>.<span style="color: #006600;">CustomPanel</span>; 
&nbsp;
	<span style="color: #0066CC;">public</span> <span style="color: #000000; font-weight: bold;">function</span> LibraryHead<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#123;</span>
		<span style="color: #808080; font-style: italic;">// Custom library initialization code may go here</span>
		<span style="color: #0066CC;">trace</span><span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">&quot;Self-initialized library has been loaded&quot;</span><span style="color: #66cc66;">&#41;</span>;
	<span style="color: #66cc66;">&#125;</span>
<span style="color: #66cc66;">&#125;</span>
<span style="color: #66cc66;">&#125;</span></pre></td></tr></table></div>

<p>As a matter of fact, the last drop required to force Flex compiler into mixin generation is to use a MXML extension of the LibraryHead as the compilation <strong>target</strong>:</p>
<p>Importantly, we use Ant scripts to build self-initialized libraries, since out of the box Flex library project is not positioned to produce SWFs:</p>
<p>Wait! There is more. In Flex 3 making and using self-initialized library would be enough. In Flex 4, however, we have to replace single line of code that applies the mixins in the <code>mx.core.FlexModuleFactory</code>, ancestor of the SimpleApplication. In place of</p>
<div class="quickcodenoclick"><code><br />
c[&quot;init&quot;](this);<br />
</code></div>
<p>we should put more sophisticated code that instead of decorating the factory class of the loaded library decorates the factory class of the entire application, i.e.   SystemManager:</p>

<div class="wp_codebox_msgheader"><span class="left"><a href="javascript:;" onclick="javascript:showCodeTxt('p585code25'); return false;">View Code</a> </span><div class="codebox_clear"></div></div><div class="wp_codebox"><table width="100%" ><tr id="p58525"><td class="code" id="p585code25"><pre class="actionscript" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">var</span> mixinTarget:<span style="color: #0066CC;">Object</span>;
	 <span style="color: #b1b100;">if</span> <span style="color: #66cc66;">&#40;</span><span style="color: #0066CC;">this</span> is FlexApplicationBootstrap<span style="color: #66cc66;">&#41;</span> <span style="color: #808080; font-style: italic;">//aka self initialized library</span>
		mixinTarget = SystemManagerGlobals.<span style="color: #006600;">topLevelSystemManagers</span><span style="color: #66cc66;">&#91;</span>
                     SystemManagerGlobals.<span style="color: #006600;">topLevelSystemManagers</span>.<span style="color: #006600;">length</span>-<span style="color: #cc66cc;">1</span>
                <span style="color: #66cc66;">&#93;</span>;
	 <span style="color: #b1b100;">else</span>
                mixinTarget = <span style="color: #0066CC;">this</span>;
	 c<span style="color: #66cc66;">&#91;</span><span style="color: #ff0000;">&quot;init&quot;</span><span style="color: #66cc66;">&#93;</span><span style="color: #66cc66;">&#40;</span>mixinTarget<span style="color: #66cc66;">&#41;</span>;</pre></td></tr></table></div>

<p>Add this class to the application sources and &#8230; it won&#8217;t be considered by the SWF. For one thing, if you did not explicitly reference a variable of this class (or use -includes compiler switch) it will not make into SWF at all. Even if you did, however, remember that Flex SWF links the minimal number of classes to the first frame (FlexModuleFactory is NOT among them) and all the rest &#8211; to the second. In between (actually &#8211; under the control of the first frame&#8217;s code) Flex dynamically loads classes from RSLs, starting from signed RSLs and ending with your custom ones. By the time ComponentLibrary.swf get loaded, class definition of the <code>mx.core.FlexModuleFactory</code> will already be grabbed from &#8220;earlier&#8221; framework.swc. That&#8217;s a known challenge of Flex &#8220;monkey patching&#8221;. The simplest way to overcome it is to overlap application sources with one of the classes that Flex <strong>must</strong> put in the first frame. It can be custom preloader or <code>mx.core.SystemManager</code> itself, however, in this context we prefer <code>mx.core.RSLListLoader</code>. Simply, add <code>import mx.core.FlexModuleLoader;mx.core.FlexModuleLoader;</code> anywhere in the modified <code>mx.core.RSLListLoader</code> and add it to the source path of your main application along with the modified FlexModuleFactory. Again, we use it to our advantage that all dependancies of SystemManager, including RSLListLoader get linked to the first frame:</p>

<div class="wp_codebox_msgheader"><span class="left"><a href="javascript:;" onclick="javascript:showCodeTxt('p585code26'); return false;">View Code</a> </span><div class="codebox_clear"></div></div><div class="wp_codebox"><table width="100%" ><tr id="p58526"><td class="code" id="p585code26"><pre class="actionscript" style="font-family:monospace;">    <span style="color: #0066CC;">import</span> mx.<span style="color: #006600;">core</span>.<span style="color: #006600;">FlexModuleFactory</span>; mx.<span style="color: #006600;">core</span>.<span style="color: #006600;">FlexModuleFactory</span>; <span style="color: #808080; font-style: italic;">// WE ADDED THIS</span>
    <span style="color: #0066CC;">public</span> <span style="color: #000000; font-weight: bold;">function</span> RSLListLoader<span style="color: #66cc66;">&#40;</span>rslList:<span style="color: #0066CC;">Array</span><span style="color: #66cc66;">&#41;</span>
    <span style="color: #66cc66;">&#123;</span>
    	<span style="color: #0066CC;">super</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;
        <span style="color: #0066CC;">this</span>.<span style="color: #006600;">rslList</span> = rslList;
    <span style="color: #66cc66;">&#125;</span></pre></td></tr></table></div>

<p>Believe it or not, that&#8217;s it.</p>
<p>Here is the summary of the steps:<br />
1. Turn-off &#8220;autoextract&#8221; of the SWC<br />
2. Create self-initialized library SWF and place it into bin or bin-debug<br />
3. Add monkey-patched FlexModuleFactory and RSLListLoader into Flex sources<br />
4. Say good-bye to plain old Flex RSLs.</p>
<p>I&#8217;d like to use this opportunity and invite Flex developers living in Europe to attend our <a href="http://www.eventbrite.com/event/527934065">Advanced Flex Master Class in Brussels, Belgium on March 1 and 2, 2010</a>.</p>
<p>Victor Rasputnis</p>
]]></content:encoded>
			<wfw:commentRss>http://flexblog.faratasystems.com/2010/01/27/taming-flex-rsl/feed</wfw:commentRss>
		<slash:comments>6</slash:comments>
		</item>
		<item>
		<title>Using Custom Type Marshallers in BlazeDS</title>
		<link>http://flexblog.faratasystems.com/2010/01/09/custom-type-masrhaller-in-blazeds</link>
		<comments>http://flexblog.faratasystems.com/2010/01/09/custom-type-masrhaller-in-blazeds#comments</comments>
		<pubDate>Sat, 09 Jan 2010 13:28:49 +0000</pubDate>
		<dc:creator>Victor Rasputnis</dc:creator>
				<category><![CDATA[BlazeDS]]></category>
		<category><![CDATA[Data Management]]></category>
		<category><![CDATA[Data Services]]></category>
		<category><![CDATA[Flex]]></category>
		<category><![CDATA[NaN]]></category>
		<category><![CDATA[serialization]]></category>
		<category><![CDATA[type-marshaller]]></category>

		<guid isPermaLink="false">http://flexblog.faratasystems.com/?p=555</guid>
		<description><![CDATA[In my previous post I pointed to the BlazeDS classes that need to be replaced in order to prevent ActionScript Number.NaN from turning into Long or Integer zeroes on the MessageBroker side. The recommendation boiled down to re-jaring flex-messaging-core.jar or placing the modified classes somewhere earlier in the application server&#8217;s classpath. If neither option is [...]]]></description>
			<content:encoded><![CDATA[<p><a href="http://flexblog.faratasystems.com/2010/01/07/how-to-keep-numeric-null-value-from-turning-into-zeros-in-blazeds">In my previous post</a> I pointed to the BlazeDS classes that need to be replaced in order to prevent ActionScript Number.NaN from turning into Long or Integer zeroes on the MessageBroker side. The recommendation boiled down to re-jaring flex-messaging-core.jar or placing the modified classes somewhere earlier in the application server&#8217;s classpath. If neither option is allowed, you may configure your endpoint with the custom type marshaller, like the one below:</p>

<div class="wp_codebox_msgheader"><span class="left"><a href="javascript:;" onclick="javascript:showCodeTxt('p555code29'); return false;">View Code</a> </span><div class="codebox_clear"></div></div><div class="wp_codebox"><table width="100%" ><tr id="p55529"><td class="code" id="p555code29"><pre class="xml" style="font-family:monospace;">        <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;channel-definition</span> <span style="color: #000066;">id</span>=<span style="color: #ff0000;">&quot;my-amf&quot;</span> <span style="color: #000066;">class</span>=<span style="color: #ff0000;">&quot;mx.messaging.channels.AMFChannel&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>
            <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;endpoint</span> <span style="color: #000066;">url</span>=<span style="color: #ff0000;">&quot;http://{server.name}:{server.port}/{context.root}/messagebroker/amf&quot;</span> </span>
<span style="color: #009900;">            <span style="color: #000066;">class</span>=<span style="color: #ff0000;">&quot;flex.messaging.endpoints.AMFEndpoint&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>
            <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/endpoint<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
            <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;properties<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>	
	            <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;serialization<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
            		<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;type-marshaller<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>com.farata.messaging.io.CustomTypeMarshaller<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/type-marshaller<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
            	<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/serialization<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
            <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/properties<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>	
        <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/channel-definition<span style="color: #000000; font-weight: bold;">&gt;</span></span></span></pre></td></tr></table></div>

<p>In BlazeDS 4 you will base your type marshaller on flex.messaging.io.ASTranslator, in BlazeDS 3 they already have one level of extension called Java15TypeMarshaller, so build on top of that one:</p>

<div class="wp_codebox_msgheader"><span class="left"><a href="javascript:;" onclick="javascript:showCodeTxt('p555code30'); return false;">View Code</a> </span><div class="codebox_clear"></div></div><div class="wp_codebox"><table width="100%" ><tr id="p55530"><td class="code" id="p555code30"><pre class="java" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">package</span> <span style="color: #006699;">com.farata.messaging.io</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">com.farata.messaging.io.amf.translator.decoder.NumberDecoder</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">flex.messaging.io.amf.translator.decoder.DecoderFactory</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #666666; font-style: italic;">// For BlazeDS 4 you should extend flex.messaging.io.ASTranslator</span>
<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">class</span> CustomTypeMarshaller <span style="color: #000000; font-weight: bold;">extends</span>
		flex.<span style="color: #006633;">messaging</span>.<span style="color: #006633;">io</span>.<span style="color: #006633;">Java15TypeMarshaller</span> <span style="color: #009900;">&#123;</span>
&nbsp;
    <span style="color: #000000; font-weight: bold;">private</span> <span style="color: #000000; font-weight: bold;">static</span> <span style="color: #000000; font-weight: bold;">final</span> NumberDecoder numberDecoder <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> NumberDecoder<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
    <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #003399;">Object</span> convert<span style="color: #009900;">&#40;</span><span style="color: #003399;">Object</span> source, <span style="color: #000000; font-weight: bold;">Class</span> desiredClass<span style="color: #009900;">&#41;</span>
    <span style="color: #009900;">&#123;</span>
    	<span style="color: #000000; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span> DecoderFactory.<span style="color: #006633;">isNumber</span><span style="color: #009900;">&#40;</span>desiredClass<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
    		<span style="color: #000000; font-weight: bold;">return</span> numberDecoder.<span style="color: #006633;">decodeObject</span><span style="color: #009900;">&#40;</span>source, desiredClass<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    	<span style="color: #009900;">&#125;</span><span style="color: #000000; font-weight: bold;">else</span><span style="color: #009900;">&#123;</span>
    		<span style="color: #000000; font-weight: bold;">return</span> <span style="color: #000000; font-weight: bold;">super</span>.<span style="color: #006633;">convert</span><span style="color: #009900;">&#40;</span>source, desiredClass<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    	<span style="color: #009900;">&#125;</span>
    <span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span></pre></td></tr></table></div>

<p>This route does not require neither server-level deployment nor modification of the flex-messaging-core.jar.<br />
Please note that in my example I repackaged NumberDecoder as <strong>com.farata</strong>.messaging.io.amf.translator.decoder.NumberDecoder</p>
<p>I&#8217;d like to use this opportunity and invite Flex developers living in Europe to attend our <a href="http://www.eventbrite.com/event/527934065">Advanced Flex Master Class in Brussels, Belgium on March 1 and 2, 2010</a>.</p>
<p>Victor Rasputnis</p>
]]></content:encoded>
			<wfw:commentRss>http://flexblog.faratasystems.com/2010/01/09/custom-type-masrhaller-in-blazeds/feed</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Prevent Flex numeric nulls from turning to zeros in BlazeDS</title>
		<link>http://flexblog.faratasystems.com/2010/01/07/how-to-keep-numeric-null-value-from-turning-into-zeros-in-blazeds</link>
		<comments>http://flexblog.faratasystems.com/2010/01/07/how-to-keep-numeric-null-value-from-turning-into-zeros-in-blazeds#comments</comments>
		<pubDate>Thu, 07 Jan 2010 18:24:26 +0000</pubDate>
		<dc:creator>Victor Rasputnis</dc:creator>
				<category><![CDATA[Flex]]></category>
		<category><![CDATA[BlazeDS]]></category>
		<category><![CDATA[marshalling]]></category>
		<category><![CDATA[serialization]]></category>

		<guid isPermaLink="false">http://flexblog.faratasystems.com/?p=515</guid>
		<description><![CDATA[This question we get on almost every new client project: &#8220;We’re struggling with handling of null values for numeric data types in Flex/Java projects. Every time there’s an update, we end up replacing the original nulls with zeros when the user didn’t actually change that value.  Have you guys come up with a silver bullet [...]]]></description>
			<content:encoded><![CDATA[<p>This question we get on almost every new client project: <em>&#8220;We’re struggling with handling of null values for numeric data types in Flex/Java projects. Every time there’s an update, we end up replacing the original nulls with zeros when the user didn’t actually change that value.  Have you guys come up with a silver bullet for handling numeric nulls?&#8221;</em><br />
<em><br />
</em> Consider a Java method with a Double parameter. You pass uninitialized ActionScript Number, that is, Number.NaN. What will BlazeDS deserialize (unmarshal)? Double.NaN. At this point your Java code may use something like <code>(value==Double.NaN)?null:value</code>, capitalizing on the fact that information about special value of NaN had been delivered from your client code to your server code. Now, let&#8217;s assume you change the signature of the Java method to accept Long instead of Double. You pass NaN and you get &#8230; 0! The same happens with marshaling ActionScript object that carries Number.NaN properties: they turn into 0, if, god forbid, their Java counterparties are declared as Long or Integer.<br />
<em><br />
</em> The reason is that while Java has <code>Double.NaN</code> it does not support either <code>Long.NaN</code> or <code>Integer.NaN</code>. Looking at the following snippet of code you can see how differently <code>Double</code> and <code>Long</code> variables get treated by Java:<br />
<em><br />
</em></p>

<div class="wp_codebox_msgheader"><span class="left"><a href="javascript:;" onclick="javascript:showCodeTxt('p515code33'); return false;">View Code</a> </span><div class="codebox_clear"></div></div><div class="wp_codebox"><table width="100%" ><tr id="p51533"><td class="code" id="p515code33"><pre class="java" style="font-family:monospace;">		 <span style="color: #003399;">Double</span> dbl <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> <span style="color: #003399;">Double</span><span style="color: #009900;">&#40;</span><span style="color: #003399;">Double</span>.<span style="color: #006633;">NaN</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #666666; font-style: italic;">// We emulate incoming numeric null</span>
		 <span style="color: #003399;">System</span>.<span style="color: #006633;">out</span>.<span style="color: #006633;">println</span><span style="color: #009900;">&#40;</span>dbl<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #666666; font-style: italic;">//prints NaN, cause dbl &quot;knows&quot; it came from null</span>
		 <span style="color: #000066; font-weight: bold;">long</span> l <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> <span style="color: #003399;">Long</span><span style="color: #009900;">&#40;</span>dbl.<span style="color: #006633;">longValue</span><span style="color: #009900;">&#40;</span><span style="color: #000000; font-weight: bold;">new</span> <span style="color: #003399;">Double</span><span style="color: #009900;">&#40;</span><span style="color: #003399;">Double</span>.<span style="color: #006633;">NaN</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		 <span style="color: #003399;">System</span>.<span style="color: #006633;">out</span>.<span style="color: #006633;">println</span><span style="color: #009900;">&#40;</span>l<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #666666; font-style: italic;">// Oops, prints 0!</span></pre></td></tr></table></div>

<p>Unfortunately,  native BlazeDS <em>flex.messaging.io.amf.translator.NumberDecoder</em> falls into this trap. So, what is to be done? Luckily, BlazeDS is an open source product and this class  has to be slightly modified.</p>
<p>Figure 1 illustrates the changes required to protect <em>null</em>-ability of your <code>Long, Integer, etc</code> values, except Double (we explain what to do with Double-s a bit later):</p>
<p><img class="aligncenter" src="http://flexblog.faratasystems.com/images/407/NumberDecoder.png" alt="Modified NumberDecoder class  under Deltawalker" /></p>
<p>Figure 1.  Modified NumberDecoder. Farata modification is on the left, canonical BlazeDS class is on the right.<br />
<em><br />
</em> Now, after you make the changes and compile the class against the rest of the flex-messaging-*** jars you can re-jar your own flex-messaging-core.jar.<br />
Better yer, place this class in the common server folder so that it positively affects classpath of all applications on the server.<br />
From now on, Number.NaN will come as Long null, or Integer null &#8211; whatever you decide on the Java side.</p>
<p>It this sounds like to big of a deal to you, keep using Double values and convert Double.NaN to null yourself, when appropriate.<br />
<em><br />
</em><br />
Finally, if you would also like to see Double.NaN automatically converted to null, you will have to substitute one more BlazeDS class &#8211;  <em>flex.messaging.io.amf.translator.NativeDecoder</em>. Explanation:  it&#8217;s just so happens that BlazeDS marshalling ignores the NumberDecoder when the source (Number, aka Double) and target (Double) types are the same. Here we come and force BlazeDS to use NumberDecoder with numbers no matter what:</p>

<div class="wp_codebox_msgheader"><span class="left"><a href="javascript:;" onclick="javascript:showCodeTxt('p515code34'); return false;">View Code</a> </span><div class="codebox_clear"></div></div><div class="wp_codebox"><table width="100%" ><tr id="p51534"><td class="code" id="p515code34"><pre class="java" style="font-family:monospace;">    <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">class</span> NativeDecoder <span style="color: #000000; font-weight: bold;">extends</span> ActionScriptDecoder
<span style="color: #009900;">&#123;</span>
    <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #003399;">Object</span> decodeObject<span style="color: #009900;">&#40;</span><span style="color: #003399;">Object</span> shell, <span style="color: #003399;">Object</span> encodedObject, <span style="color: #000000; font-weight: bold;">Class</span> desiredClass<span style="color: #009900;">&#41;</span>
    <span style="color: #009900;">&#123;</span>
    	 <span style="color: #000000; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span> DecoderFactory.<span style="color: #006633;">isNumber</span><span style="color: #009900;">&#40;</span>desiredClass<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
    		 NumberDecoder numberDecoder <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> NumberDecoder<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
         	 <span style="color: #000000; font-weight: bold;">return</span> numberDecoder.<span style="color: #006633;">decodeObject</span><span style="color: #009900;">&#40;</span>encodedObject, desiredClass<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    	 <span style="color: #009900;">&#125;</span> <span style="color: #000000; font-weight: bold;">else</span>
    		 <span style="color: #000000; font-weight: bold;">return</span> encodedObject<span style="color: #339933;">;</span>      <span style="color: #666666; font-style: italic;">// the sole original BlazeDS line</span>
    <span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span></pre></td></tr></table></div>

<p>Source code:<br />
<a href="http://flexblog.faratasystems.com/images/407/NumberDecoder.java">NumberDecoder.java modified by Farata</a><br />
<a href="http://flexblog.faratasystems.com/images/407/NativeDecoder.java">NativeDecoder.java modified by Farata</a></p>
<p>I&#8217;d like to use this opportunity and invite Flex developers living in Europe to attend our <a href="http://www.eventbrite.com/event/527934065">Advanced Flex Master Class in Brussels, Belgium on March 1 and 2, 2010</a>.</p>
<p>Victor Rasputnis</p>
]]></content:encoded>
			<wfw:commentRss>http://flexblog.faratasystems.com/2010/01/07/how-to-keep-numeric-null-value-from-turning-into-zeros-in-blazeds/feed</wfw:commentRss>
		<slash:comments>7</slash:comments>
		</item>
		<item>
		<title>Data Synchronization with BlazeDS: Handling AUTOINCREMENT</title>
		<link>http://flexblog.faratasystems.com/2009/04/13/data-synchronization-with-blazeds-handling-autoincrement</link>
		<comments>http://flexblog.faratasystems.com/2009/04/13/data-synchronization-with-blazeds-handling-autoincrement#comments</comments>
		<pubDate>Tue, 14 Apr 2009 01:27:22 +0000</pubDate>
		<dc:creator>Victor Rasputnis</dc:creator>
				<category><![CDATA[BlazeDS]]></category>
		<category><![CDATA[Data Management]]></category>
		<category><![CDATA[Data Services]]></category>
		<category><![CDATA[Flex]]></category>
		<category><![CDATA[Java]]></category>
		<category><![CDATA[autoincrement]]></category>
		<category><![CDATA[data collection]]></category>
		<category><![CDATA[identity]]></category>
		<category><![CDATA[synchronization]]></category>

		<guid isPermaLink="false">http://flexblog.faratasystems.com/?p=414</guid>
		<description><![CDATA[Upcoming release of the ClearDataBuilder supports AUTOINCREMENTed property in the DataCollection items populated from databases based on autogenerated values like  MSSqlServer/ Sybase identity, or Oracle&#8217;s sequence, and so forth. All you need to do is add identity parameter to the CDB annotation 
&#160;&#160;&#160;&#160;/**
&#160;&#160;&#160;&#160;* @daoflex:sql
&#160;&#160;&#160;&#160;*&#160;&#160;sql=select * from employee
&#160;&#160;&#160;&#160;*&#160;&#160;transferType=EmployeeDTO[]
&#160;&#160;&#160;&#160;*&#160;&#160;keyColumns=id
&#160;&#160;&#160;&#160;*&#160;&#160;identity=id
&#160;&#160;&#160;&#160;*&#160;&#160;updateTable=employee
&#160;&#160;&#160;&#160;*/
&#160;
&#160;&#160;&#160;&#160;public abstract List getEmployees();
and allow server changes to [...]]]></description>
			<content:encoded><![CDATA[<p>Upcoming release of the <a>ClearDataBuilder</a> supports AUTOINCREMENTed property in the DataCollection items populated from databases based on autogenerated values like  MSSqlServer/ Sybase <i>identity</i>, or Oracle&#8217;s <i>sequence</i>, and so forth. All you need to do is add <code>identity</code> parameter to the CDB annotation </p>
<div class="quickcodenoclick"><code>&nbsp;&nbsp;&nbsp;&nbsp;/**<br />
&nbsp;&nbsp;&nbsp;&nbsp;* @daoflex:sql<br />
&nbsp;&nbsp;&nbsp;&nbsp;*&nbsp;&nbsp;sql=select * from employee<br />
&nbsp;&nbsp;&nbsp;&nbsp;*&nbsp;&nbsp;transferType=EmployeeDTO[]<br />
&nbsp;&nbsp;&nbsp;&nbsp;*&nbsp;&nbsp;keyColumns=id<br />
&nbsp;&nbsp;&nbsp;&nbsp;*&nbsp;&nbsp;identity=id<br />
&nbsp;&nbsp;&nbsp;&nbsp;*&nbsp;&nbsp;updateTable=employee<br />
&nbsp;&nbsp;&nbsp;&nbsp;*/<br />
&nbsp;<br />
&nbsp;&nbsp;&nbsp;&nbsp;public abstract List getEmployees();</code></div>
<p>and allow server changes to reflect back on the DataCollection:</p>
<div class="quickcodenoclick"><code>dataCollection.roundTripSync = true; </code></div>
<p><em><br />
</em><br />
<strong>Sample Use Case</strong><em><br />
</em><br />
Imagine a MSSqlServer table &#8220;employee&#8221;, with IDENTITY column named &#8220;id&#8221;. Here is the abstract Java class you would need to write:<br />
<a name="Listing 1"></a></p>

<div class="wp_codebox_msgheader"><span class="left"><a href="javascript:;" onclick="javascript:showCodeTxt('p414code38'); return false;">Listing 1. CDB-Annotated Java class</a> </span><div class="codebox_clear"></div></div><div class="wp_codebox"><table width="100%" ><tr id="p41438"><td class="code" id="p414code38"><pre class="java" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">package</span> <span style="color: #006699;">com.farata.test</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">java.util.List</span><span style="color: #339933;">;</span>
<span style="color: #008000; font-style: italic; font-weight: bold;">/**
 * @daoflex:webservice
 *   pool=jdbc/test
 */</span>
<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">abstract</span> <span style="color: #000000; font-weight: bold;">class</span> Employee
<span style="color: #009900;">&#123;</span>
		<span style="color: #008000; font-style: italic; font-weight: bold;">/**
		* @daoflex:sql
		*  sql=select * from employee
		*  transferType=EmployeeDTO[]
		*  keyColumns=id
		*  identity=id
		*  updateTable=employee
		*/</span>
&nbsp;
		<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">abstract</span> <span style="color: #003399;">List</span> getEmployees<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span></pre></td></tr></table></div>

<p>A Clean CDB build, as usual, will generate concrete implementation of the Assembler, already registered for Flex remoting, ActionScript DTO classes matching the Java counterparties and so forth.</p>
<p>Importantly, the specifics of the <code>identity</code> annotation will force CDB to enquire the value of the autogenerated <i>id</i> column along with the execution of the <code>executeUpdate()</code> and send the modified record back to the Flex client.<br />
<em><br />
</em><br />
<strong>Two-Way Syncronization: DataCollection &#8211; BlazeDS Assembler</strong><em><br />
</em><br />
You have to allow the echo of the server-side changes back to the client. You have two options.</p>
<li><code>dataCollection.roundTripSync=true;</code></i> &#8211; to allow Flex process the immediate result of &#8220;your own&#8221; <code>dataCollection.sync()</code> call </li>
<li><code>dataCollection.autoSyncEnabled=true;</code></i> &#8211; to allow Flex consume server-born asyncronous messages with changes inflicted by other clients. This option requires design-time <code>autoSyncEnabled=true</code> CDB annotation as well.
<p>
Here is the explanation. During the <code>sync()</code> operation changes originated in the DataCollection are remoted to method(s) of a server Assembler as Array of <code>com.farata.remoting.ChangeObject</code> elements. All of these methods are also <i>returning</i> the Array of changes, including, if any, changes originated by the server. The value of the <code>roundTripSync</code> determines whether these changes effect DataCollection when the synchronization is complete. Default value is <code>false</code><br />
<em><br />
</em><br />
<strong>Pluggable Identity Factory</strong><em><br />
</em><br />
No two databases are born equal. The default setting of the CDB is to handle identity compliant with MSSqlServer, i.e. to use <code>SELECT SCOPE_IDENTITY()</code> as the cleanest possible computation of the identity. If you are running Sybase, you would have to modify the default <code>daoflex.identity.factory</code> in the <i>daoflex-build/daoflex-build-custom.properties</i>:</p>

<div class="wp_codebox_msgheader"><span class="left"><a href="javascript:;" onclick="javascript:showCodeTxt('p414code39'); return false;">Listing 2. daoflex-build-custom.properties with Sybase identity factory</a> </span><div class="codebox_clear"></div></div><div class="wp_codebox"><table width="100%" ><tr id="p41439"><td class="code" id="p414code39"><pre class="java" style="font-family:monospace;">daoflex.<span style="color: #006633;">identity</span>.<span style="color: #006633;">factory</span><span style="color: #339933;">=</span>com.<span style="color: #006633;">farata</span>.<span style="color: #006633;">daoflex</span>.<span style="color: #006633;">SybaseIdentityFactory</span></pre></td></tr></table></div>

<p>It gets worse if you are an Oracle sequence guy.  Plugging a <code>foo.bar.OracleIdentityFactory</code> class that has to implement <code>com.farata.daoflex.IIdentityFactory</code> interface is not any different from the Sybase, but CDB does not know upfront which sequence to use. So roll up your sleeves and create something like following:</p>

<div class="wp_codebox_msgheader wp_codebox_hide"><span class="left"><a href="javascript:;" onclick="javascript:showCodeTxt('p414code40'); return false;">Listing 3. Custom Oracle identity factory</a> </span><div class="codebox_clear"></div></div><div class="wp_codebox"><table width="100%" ><tr id="p41440"><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
</pre></td><td class="code" id="p414code40"><pre class="java" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">package</span> <span style="color: #006699;">foo.bar</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">java.sql.Connection</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">java.sql.PreparedStatement</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">java.sql.ResultSet</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">java.util.Map</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">com.farata.daoflex.DAOException</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">com.farata.daoflex.IIdentityFactory</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">class</span> OracleIdentityFactory <span style="color: #000000; font-weight: bold;">implements</span> IIdentityFactory <span style="color: #009900;">&#123;</span>
	<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000066; font-weight: bold;">long</span> getIdentity<span style="color: #009900;">&#40;</span>Map<span style="color: #339933;">&lt;</span>String, Object<span style="color: #339933;">&gt;</span> properties<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
		<span style="color: #000066; font-weight: bold;">long</span> identity <span style="color: #339933;">=</span> <span style="color: #cc66cc;">0</span><span style="color: #339933;">;</span>
		<span style="color: #003399;">PreparedStatement</span> stmt <span style="color: #339933;">=</span> <span style="color: #000066; font-weight: bold;">null</span><span style="color: #339933;">;</span>
		<span style="color: #003399;">ResultSet</span> rs <span style="color: #339933;">=</span> <span style="color: #000066; font-weight: bold;">null</span><span style="color: #339933;">;</span>
		<span style="color: #000000; font-weight: bold;">try</span> <span style="color: #009900;">&#123;</span>
&nbsp;
			<span style="color: #003399;">Connection</span> conn <span style="color: #339933;">=</span> <span style="color: #009900;">&#40;</span><span style="color: #003399;">Connection</span><span style="color: #009900;">&#41;</span> properties.<span style="color: #006633;">get</span><span style="color: #009900;">&#40;</span>CONNECTION<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
			<span style="color: #003399;">String</span> table <span style="color: #339933;">=</span> <span style="color: #009900;">&#40;</span><span style="color: #003399;">String</span><span style="color: #009900;">&#41;</span> properties.<span style="color: #006633;">get</span><span style="color: #009900;">&#40;</span>TABLE<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
			<span style="color: #003399;">String</span> sequenceName<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;UNKNOWN_SEQUENCE&quot;</span><span style="color: #339933;">;</span>  
			<span style="color: #666666; font-style: italic;">// Your custom logic to determine the sequence give the table goes here		</span>
			<span style="color: #000000; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span>table<span style="color: #339933;">==</span>table<span style="color: #009900;">&#41;</span> 
			     sequenceName <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;MY_SEQUENCE&quot;</span><span style="color: #339933;">;</span>			
			stmt <span style="color: #339933;">=</span> conn.<span style="color: #006633;">prepareStatement</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;SELECT &quot;</span> <span style="color: #339933;">+</span> sequenceName <span style="color: #339933;">+</span> <span style="color: #0000ff;">&quot;.NEXTVAL AS identity FROM DUAL&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
			rs <span style="color: #339933;">=</span> stmt.<span style="color: #006633;">executeQuery</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
			<span style="color: #000000; font-weight: bold;">while</span><span style="color: #009900;">&#40;</span> rs.<span style="color: #006633;">next</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
				identity <span style="color: #339933;">=</span> rs.<span style="color: #006633;">getLong</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;identity&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
			<span style="color: #009900;">&#125;</span>
			<span style="color: #000000; font-weight: bold;">return</span> identity<span style="color: #339933;">;</span>
		<span style="color: #009900;">&#125;</span> <span style="color: #000000; font-weight: bold;">catch</span> <span style="color: #009900;">&#40;</span><span style="color: #003399;">Throwable</span> te<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
			te.<span style="color: #006633;">printStackTrace</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
			<span style="color: #000000; font-weight: bold;">throw</span> <span style="color: #000000; font-weight: bold;">new</span> DAOException<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;Failed creating identity&quot;</span>, te<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<span style="color: #009900;">&#125;</span>
		<span style="color: #000000; font-weight: bold;">finally</span> <span style="color: #009900;">&#123;</span>
			<span style="color: #000000; font-weight: bold;">try</span> <span style="color: #009900;">&#123;</span>rs.<span style="color: #006633;">close</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> rs <span style="color: #339933;">=</span> <span style="color: #000066; font-weight: bold;">null</span><span style="color: #339933;">;</span><span style="color: #009900;">&#125;</span> <span style="color: #000000; font-weight: bold;">catch</span> <span style="color: #009900;">&#40;</span><span style="color: #003399;">Exception</span> e<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span><span style="color: #009900;">&#125;</span>
			<span style="color: #000000; font-weight: bold;">try</span> <span style="color: #009900;">&#123;</span>stmt.<span style="color: #006633;">close</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> stmt <span style="color: #339933;">=</span> <span style="color: #000066; font-weight: bold;">null</span><span style="color: #339933;">;</span><span style="color: #009900;">&#125;</span> <span style="color: #000000; font-weight: bold;">catch</span> <span style="color: #009900;">&#40;</span><span style="color: #003399;">Exception</span> e<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span><span style="color: #009900;">&#125;</span>
		<span style="color: #009900;">&#125;</span>
	<span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span></pre></td></tr></table></div>

<p>Victor Rasputnis</p>
]]></content:encoded>
			<wfw:commentRss>http://flexblog.faratasystems.com/2009/04/13/data-synchronization-with-blazeds-handling-autoincrement/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Deep Data Synchronization with BlazeDS</title>
		<link>http://flexblog.faratasystems.com/2009/04/01/deep-synchronization-of-datacollections-with-the-java-server</link>
		<comments>http://flexblog.faratasystems.com/2009/04/01/deep-synchronization-of-datacollections-with-the-java-server#comments</comments>
		<pubDate>Thu, 02 Apr 2009 00:33:36 +0000</pubDate>
		<dc:creator>Victor Rasputnis</dc:creator>
				<category><![CDATA[Flex]]></category>
		<category><![CDATA[BlazeDS]]></category>
		<category><![CDATA[Clear Data Builder]]></category>
		<category><![CDATA[Data Services]]></category>
		<category><![CDATA[Data Syncronization]]></category>
		<category><![CDATA[Hierarchical collections]]></category>
		<category><![CDATA[Managed associations]]></category>

		<guid isPermaLink="false">http://flexblog.faratasystems.com/?p=407</guid>
		<description><![CDATA[Upcoming release of the ClearDataBuilder supports deep synchronization of hierarchical DataCollections with the Server, so that if an item of the collection contains child collections and so on, the entire tree of changes, if any, gets synchronized with the Java back end in one transaction:
orders.sync(true); // Deep sync of the DataCollection and all nested children



Sample [...]]]></description>
			<content:encoded><![CDATA[<p>Upcoming release of the <a>ClearDataBuilder</a> supports deep synchronization of hierarchical DataCollections with the Server, so that if an item of the collection contains child collections and so on, the entire tree of changes, if any, gets synchronized with the Java back end in one transaction:</p>
<div class="quickcodenoclick"><code>orders.sync(true); // Deep sync of the DataCollection and all nested children<br />
</code></div>
<p><em><br />
</em><br />
<strong>Sample Use Case</strong><em><br />
</em><br />
<a href="#Listing9">Listing 9</a> presents two SQL tables <em>Orders</em> and <em>OrderItems</em>. Sample application enables end user to navigate from order to order, editing the <em>master</em> information (order) as well as <em>details</em> (order items). All interactive changes are accumulated in Flex &#8211; until button &#8220;Commit&#8221; is clicked. That&#8217;s exactly when deep sync happens &#8211; in one transaction, i.e. all or nothing, &#8220;commit&#8221; of all changes or complete &#8220;rollback&#8221;:</p>
<p><img class="aligncenter" src="http://flexblog.faratasystems.com/images/125/orders_orderitems.jpg" alt="Snapshot of the Orders-OrderItems application" width="378" height="439" /><br />
Figure 1.  Order-OrderItems application snapshot<br />
<em><br />
</em><br />
<strong>Client Data Persistance</strong><em><br />
</em><br />
Two DataCollections &#8211; <code>OrderCollection</code>, <a href="#Listing2">Listing 2</a> and <code>OrderItemCollection</code>, <a href="#Listing3">Listing 3</a> &#8211; assist in persisting the data on the client; they remote to the methods of the Java class <code>OrderAssembler</code> generated by the ClearDataBuilder given <a href="#Listing8">SQL-annotated abstract class Order.java, Listing 8</a>. Each item of the OrderCollection carries <code>orderItems</code> referring to the child collection of line items of this order. At the application level<a href="#Listing1">, Listing 1 below,</a> we expose only the master collection <code>orders</code>, which holds the entire hierarchy:<br />
<a name="Listing 1"></a></p>

<div class="wp_codebox_msgheader"><span class="left"><a href="javascript:;" onclick="javascript:showCodeTxt('p407code54'); return false;">Listing 1. Demo application</a> </span><div class="codebox_clear"></div></div><div class="wp_codebox"><table width="100%" ><tr id="p40754"><td class="code" id="p407code54"><pre class="mxml" style="font-family:monospace;"><span style="color: #000000;">&lt;?xml version=<span style="color: #990000;">&quot;1.0&quot;</span> encoding=<span style="color: #990000;">&quot;UTF-8&quot;</span>?<span style="color: #0033ff;">&gt;</span></span>
<span style="color: #000000;"><span style="color: #808080; font-style: italic;">&lt;!--OrderEntryDemo.mxml --&gt;</span></span>
<span style="color: #000000;"><span style="color: #0033ff;">&lt;mx:Application</span>  </span>
<span style="color: #000000;">	xmlns:mx=<span style="color: #990000;">&quot;http://www.adobe.com/2006/mxml&quot;</span> </span>
<span style="color: #000000;">	xmlns=<span style="color: #990000;">&quot;*&quot;</span> xmlns:collections=<span style="color: #990000;">&quot;collections.*&quot;</span><span style="color: #0033ff;">&gt;</span></span>
	<span style="color: #000000;"><span style="color: #0033ff;">&lt;collections:OrderCollection</span> id=<span style="color: #990000;">&quot;orders&quot;</span><span style="color: #0033ff;">/&gt;</span></span>
	<span style="color: #000000;"><span style="color: #0033ff;">&lt;mx:ControlBar</span><span style="color: #0033ff;">&gt;</span></span>
		<span style="color: #000000;"><span style="color: #0033ff;">&lt;mx:Button</span> label=<span style="color: #990000;">&quot;Fill&quot;</span>  click=<span style="color: #990000;">&quot;selectedOrder=null;orders.fill()&quot;</span>  <span style="color: #0033ff;">/&gt;</span></span>
		<span style="color: #000000;"><span style="color: #0033ff;">&lt;mx:Button</span> label=<span style="color: #990000;">&quot;Commit&quot;</span>  click=<span style="color: #990000;">&quot;orders.sync(true)&quot;</span> </span>
<span style="color: #000000;">			enabled=<span style="color: #990000;">&quot;{orders.commitRequired}&quot;</span> <span style="color: #0033ff;">/&gt;</span></span>		
	<span style="color: #000000;"><span style="color: #0033ff;">&lt;/mx:ControlBar</span><span style="color: #0033ff;">&gt;</span></span>
	<span style="color: #000000;"><span style="color: #0033ff;">&lt;mx:VDividedBox</span>  <span style="color: #0033ff;">&gt;</span></span>
		<span style="color: #000000;">&lt;OrdersPanel id=<span style="color: #990000;">&quot;master&quot;</span> orders=<span style="color: #990000;">&quot;{orders}&quot;</span> </span>
<span style="color: #000000;">			orderSelectionChange=<span style="color: #990000;">&quot;selectedOrder = event.order&quot;</span></span>
<span style="color: #000000;">		<span style="color: #0033ff;">/&gt;</span></span>
		<span style="color: #000000;">&lt;OrderItemsPanel id=<span style="color: #990000;">&quot;detail&quot;</span> width=<span style="color: #990000;">&quot;100%&quot;</span>	</span>
<span style="color: #000000;">			selectedOrder=<span style="color: #990000;">&quot;{selectedOrder}&quot;</span></span>
<span style="color: #000000;">		<span style="color: #0033ff;">/&gt;</span></span>
	<span style="color: #000000;"><span style="color: #0033ff;">&lt;/mx:VDividedBox</span><span style="color: #0033ff;">&gt;</span></span>
	<span style="color: #339933;">&lt;mx:Script&gt;</span>
<span style="color: #339933;">		&lt;![CDATA[</span>
<span style="color: #339933;">			import com.farata.test.dto.OrderDTO;</span>
<span style="color: #339933;">			[Bindable] private var selectedOrder:OrderDTO;</span>
<span style="color: #339933;">		]]&gt;</span>
<span style="color: #339933;">	&lt;/mx:Script&gt;</span>
<span style="color: #000000;"><span style="color: #0033ff;">&lt;/mx:Application</span><span style="color: #0033ff;">&gt;</span></span></pre></td></tr></table></div>

<p><em><br />
</em><br />
<strong>Hierarchical DTO Items</strong><em><br />
</em><br />
Not that you would not have to write any code. For one, you would have to make sure that your DTOs implements <code>com.farata.collections.dto.IHierarchicalDTO</code> interface, i.e. &#8220;get&#8221; accessor of <code>childCollections</code>. One way to do it is via helper class <code>com.farata.collections.dto.HierarchicalDTOAdapter</code>. Please note <code>OrderDTO</code> in the snippet below extends the similarly named class prefixed with the &#8220;_&#8221; symbol. This is how, by default, CDB names a pair of generated ActionScript DTOs: the class with the &#8220;_&#8221; gets regenerated by CDB on every &#8220;Clean&#8221; of the project, while the extending class is preserving manual edits. Also, do  notice how child collection <code>orderItems</code> &#8211; for each item  &#8211; gets filled asynchronously, on <code>order_id</code> setter:</p>

<div class="wp_codebox_msgheader wp_codebox_hide"><span class="left"><a href="javascript:;" onclick="javascript:showCodeTxt('p407code55'); return false;">OrderDTO, a hierarchical collection item</a> </span><div class="codebox_clear"></div></div><div class="wp_codebox"><table width="100%" ><tr id="p40755"><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
</pre></td><td class="code" id="p407code55"><pre class="actionscript3" style="font-family:monospace;"><span style="color: #9900cc; font-weight: bold;">package</span> com.farata.<span style="color: #004993;">test</span>.dto<span style="color: #000000;">&#123;</span>
<span style="color: #0033ff; font-weight: bold;">import</span> collections.OrderItemCollection;
<span style="color: #0033ff; font-weight: bold;">import</span> com.farata.collections.dto.HierarchicalDTOAdapter;
<span style="color: #0033ff; font-weight: bold;">import</span> com.farata.collections.dto.IHierarchicalDTO;
&nbsp;
<span style="color: #000000;">&#91;</span>RemoteClass<span style="color: #000000;">&#40;</span>alias=<span style="color: #990000;">&quot;com.farata.test.dto.OrderDTO&quot;</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">&#93;</span>
<span style="color: #0033ff; font-weight: bold;">public</span> <span style="color: #9900cc; font-weight: bold;">class</span> OrderDTO extends _OrderDTO implements IHierarchicalDTO<span style="color: #000000;">&#123;</span>
<span style="color: #000000;">&#91;</span>Transient<span style="color: #000000;">&#93;</span> <span style="color: #000000;">&#91;</span><span style="color: #0033ff; font-weight: bold;">Bindable</span><span style="color: #000000;">&#93;</span> <span style="color: #0033ff; font-weight: bold;">public</span> <span style="color: #6699cc; font-weight: bold;">var</span> orderItems<span style="color: #000000; font-weight: bold;">:</span>OrderItemCollection;
<span style="color: #000000;">&#91;</span>Transient<span style="color: #000000;">&#93;</span> <span style="color: #0033ff; font-weight: bold;">public</span> <span style="color: #6699cc; font-weight: bold;">var</span> adapter<span style="color: #000000; font-weight: bold;">:</span>HierarchicalDTOAdapter;
&nbsp;
<span style="color: #0033ff; font-weight: bold;">public</span> <span style="color: #339966; font-weight: bold;">function</span> OrderDTO<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span> <span style="color: #000000;">&#123;</span>
    <span style="color: #0033ff; font-weight: bold;">super</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>;
    adapter = <span style="color: #0033ff; font-weight: bold;">new</span> HierarchicalDTOAdapter<span style="color: #000000;">&#40;</span><span style="color: #0033ff; font-weight: bold;">this</span><span style="color: #000000;">&#41;</span>;
    orderItems = <span style="color: #0033ff; font-weight: bold;">new</span> OrderItemCollection<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>;
    adapter.addCollection<span style="color: #000000;">&#40;</span>orderItems<span style="color: #000000;">&#41;</span>;
<span style="color: #000000;">&#125;</span>
&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> childCollections<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #000000; font-weight: bold;">:</span><span style="color: #004993;">Array</span> <span style="color: #000000;">&#123;</span>
    <span style="color: #0033ff; font-weight: bold;">return</span> adapter.childCollections;
<span style="color: #000000;">&#125;</span>
&nbsp;
<span style="color: #0033ff; font-weight: bold;">public</span> override <span style="color: #339966; font-weight: bold;">function</span> <span style="color: #0033ff; font-weight: bold;">set</span> order_id<span style="color: #000000;">&#40;</span>orderId<span style="color: #000000; font-weight: bold;">:</span><span style="color: #004993;">String</span><span style="color: #000000;">&#41;</span><span style="color: #000000; font-weight: bold;">:</span><span style="color: #0033ff; font-weight: bold;">void</span> <span style="color: #000000;">&#123;</span>
    <span style="color: #0033ff; font-weight: bold;">if</span> <span style="color: #000000;">&#40;</span>orderId <span style="color: #000000; font-weight: bold;">!</span>== <span style="color: #0033ff; font-weight: bold;">super</span>.order_id<span style="color: #000000;">&#41;</span> <span style="color: #000000;">&#123;</span>
         <span style="color: #0033ff; font-weight: bold;">super</span>.order_id = orderId;			
         orderItems.fill<span style="color: #000000;">&#40;</span>order_id<span style="color: #000000;">&#41;</span>;	
    <span style="color: #000000;">&#125;</span>			
<span style="color: #000000;">&#125;</span> 
<span style="color: #000000;">&#125;</span><span style="color: #009900;">//OrderDTO</span>
<span style="color: #000000;">&#125;</span></pre></td></tr></table></div>

<p>Browse <a href="#Listing1">Listings 1-8</a>: except &#8220;view&#8221;-Panel components there is no other code you would need to write. As long a you start with the <a href="Listing8">SQL-annotated abstract Java source</a> everything else gets code generated by the CDB.<br />
<em><br />
</em><br />
<strong>What if you use CDB with the existing DAO, i.e. IJavaDAO?</strong><em><br />
</em><br />
You are not confined to SQL-annotations to use the <code>fill()</code> and <code>sync()</code>, of course. CDB allows your DataCollections to remote to any Java class implementing <code>com.farata.daoflex.IJavaDAO</code> interface (see <a href="http://www.myflex.org/documentation/CDB3.pdf">CDB documentation</a> for more details):</p>

<div class="wp_codebox_msgheader"><span class="left"><a href="javascript:;" onclick="javascript:showCodeTxt('p407code56'); return false;">Interface com.farata.daoflex.IJavaDAO</a> </span><div class="codebox_clear"></div></div><div class="wp_codebox"><table width="100%" ><tr id="p40756"><td class="code" id="p407code56"><pre class="java" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">package</span> <span style="color: #006699;">com.farata.daoflex</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">java.util.List</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">flex.data.ChangeObject</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">interface</span> IJavaDAO <span style="color: #009900;">&#123;</span>
    <span style="color: #003399;">List</span> fill<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    List<span style="color: #339933;">&lt;</span>ChangeObject<span style="color: #339933;">&gt;</span> sync<span style="color: #009900;">&#40;</span>List<span style="color: #339933;">&lt;</span>ChangeObject<span style="color: #339933;">&gt;</span> items<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span></pre></td></tr></table></div>

<p>In addition to <code>IJavaDAO</code>, participation in the deep sync requires your Java class to implement <code>IBatchTransactionServiceSupport</code>. Methods of this interface allow to synchronize changes accumulated by the DataCollection in three independent steps: all deletes, all updates and all inserts:</p>

<div class="wp_codebox_msgheader"><span class="left"><a href="javascript:;" onclick="javascript:showCodeTxt('p407code57'); return false;">Interface com.farata.daoflex.IBatchTransactionServiceSupport</a> </span><div class="codebox_clear"></div></div><div class="wp_codebox"><table width="100%" ><tr id="p40757"><td class="code" id="p407code57"><pre class="java" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">package</span> <span style="color: #006699;">com.farata.daoflex</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">java.util.List</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">flex.data.ChangeObject</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">interface</span> IBatchServiceTransactionSupport  <span style="color: #009900;">&#123;</span>
    List<span style="color: #339933;">&lt;</span>ChangeObject<span style="color: #339933;">&gt;</span> deleteItems<span style="color: #009900;">&#40;</span>List<span style="color: #339933;">&lt;</span>ChangeObject<span style="color: #339933;">&gt;</span> items<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    List<span style="color: #339933;">&lt;</span>ChangeObject<span style="color: #339933;">&gt;</span> updateItems<span style="color: #009900;">&#40;</span>List<span style="color: #339933;">&lt;</span>ChangeObject<span style="color: #339933;">&gt;</span> items<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    List<span style="color: #339933;">&lt;</span>ChangeObject<span style="color: #339933;">&gt;</span> insertItems<span style="color: #009900;">&#40;</span>List<span style="color: #339933;">&lt;</span>ChangeObject<span style="color: #339933;">&gt;</span> items<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span></pre></td></tr></table></div>

<p><em><br />
</em><br />
<strong>BatchService</strong><em><br />
</em><br />
Splitting of monolythic <code>sync()</code> into three steps is required to support the referential integrity of data: children have to be deleted prior to parents and parents need to be inserted prior to children. And yet we can not addord three remoting calls instead of one (<code>sync()</code>), six calls altogether in our <em>Orders-OrderItems</em> scenario, because server-side transaction can not be spawned across several remoting calls.</p>
<p>That&#8217;s where <code>BatchService</code> class from <em>clear.swc</em> comes in play. It refers to sequence of several remote method calls-to-do as a &#8220;batch&#8221;, or, simply array of <code>BatchMember</code> elements: destination name, method name, array of arguments.  Instead of multiple remote calls it sends the &#8220;batch&#8221; as argument of one remote call &#8211; to  Java class <code>com.farata.remoting.BatchGateway</code> (daoflex-runtime.jar). In turn, BatchGateway&#8217;s method <code>execute(List&lt;BatchMember&gt;)</code> invokes the required remote calls sequentially, wrapping the entire sequence in the JTA begin/commit/rollback.</p>
<p><img class="aligncenter" src="http://flexblog.faratasystems.com/images/125/batchservice.jpg" alt="Snapshot of the Orders-OrderItems application" /></p>
<p>Here is a snippet illustrating the work of the <code>BatchService</code>:</p>

<div class="wp_codebox_msgheader"><span class="left"><a href="javascript:;" onclick="javascript:showCodeTxt('p407code58'); return false;">Snippet 'How to use BatchService'</a> </span><div class="codebox_clear"></div></div><div class="wp_codebox"><table width="100%" ><tr id="p40758"><td class="code" id="p407code58"><pre class="actionscript3" style="font-family:monospace;">  <span style="color: #6699cc; font-weight: bold;">var</span> bs<span style="color: #000000; font-weight: bold;">:</span> com.farata.remoting.BatchService;
  .  .  .
  bs = <span style="color: #0033ff; font-weight: bold;">new</span> BatchService<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>;
  bs.<span style="color: #004993;">addEventListener</span><span style="color: #000000;">&#40;</span>FaultEvent.FAULT, onFault<span style="color: #000000;">&#41;</span>;
  bs.registerCollection<span style="color: #000000;">&#40;</span>orders, <span style="color: #000000; font-weight:bold;">0</span><span style="color: #000000;">&#41;</span>; <span style="color: #009900;">//0 - default (top) priority, parent</span>
  bs.registerCollection<span style="color: #000000;">&#40;</span>orderItems,<span style="color: #000000; font-weight:bold;">1</span><span style="color: #000000;">&#41;</span>; <span style="color: #009900;">//1 - priority, child of &quot;0&quot;</span>
  .  .  .
  <span style="color: #6699cc; font-weight: bold;">var</span> batch<span style="color: #000000; font-weight: bold;">:</span><span style="color: #004993;">Array</span> = bs.batchRegisteredCollections<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>;
  bs.<span style="color: #004993;">send</span><span style="color: #000000;">&#40;</span>batch<span style="color: #000000;">&#41;</span>;</pre></td></tr></table></div>

<p>As you can see, <code>BatchService</code> batch is not confined to DataCollections: you can batch for synchronical server-side execution any sequence of remote calls. While <code>BatchService</code> has been around since 2006. the  <code>dataCollection.sync(true)</code> further reduces the amount of code required to transactionally update associated collections. Users of SQL-based branch of the CDB benefit from automatic generation of the required Java functions. Otherwise, your Java DAO has to implement <code>IBatchTransactionServiceSupport</code>.</p>
<p><a name="Listing2"></a></p>

<div class="wp_codebox_msgheader wp_codebox_hide"><span class="left"><a href="javascript:;" onclick="javascript:showCodeTxt('p407code59'); return false;">Listing 2. OrderCollection. Master collection, an extension of DataCollection</a> </span><div class="codebox_clear"></div></div><div class="wp_codebox"><table width="100%" ><tr id="p40759"><td class="code" id="p407code59"><pre class="actionscript3" style="font-family:monospace;"><span style="color: #9900cc; font-weight: bold;">package</span> collections <span style="color: #000000;">&#123;</span>
<span style="color: #0033ff; font-weight: bold;">import</span> com.farata.collections.DataCollection;
&nbsp;
<span style="color: #0033ff; font-weight: bold;">public</span> <span style="color: #9900cc; font-weight: bold;">class</span> OrderCollection extends DataCollection <span style="color: #000000;">&#123;</span>
    <span style="color: #0033ff; font-weight: bold;">public</span> <span style="color: #339966; font-weight: bold;">function</span> OrderCollection<span style="color: #000000;">&#40;</span><span style="color: #004993;">source</span><span style="color: #000000; font-weight: bold;">:</span><span style="color: #004993;">Array</span>=<span style="color: #0033ff; font-weight: bold;">null</span><span style="color: #000000;">&#41;</span> <span style="color: #000000;">&#123;</span>
        <span style="color: #0033ff; font-weight: bold;">super</span><span style="color: #000000;">&#40;</span><span style="color: #004993;">source</span><span style="color: #000000;">&#41;</span>;
        destination=<span style="color: #990000;">&quot;com.farata.test.Order&quot;</span>;
        <span style="color: #004993;">method</span>=<span style="color: #990000;">&quot;getOrders&quot;</span>;
    <span style="color: #000000;">&#125;</span>
<span style="color: #000000;">&#125;</span>
<span style="color: #000000;">&#125;</span></pre></td></tr></table></div>

<p><a name="Listing3"></a></p>

<div class="wp_codebox_msgheader wp_codebox_hide"><span class="left"><a href="javascript:;" onclick="javascript:showCodeTxt('p407code60'); return false;">Listing 3. OrderItemCollection. Detail collection, an extension of DataCollection</a> </span><div class="codebox_clear"></div></div><div class="wp_codebox"><table width="100%" ><tr id="p40760"><td class="code" id="p407code60"><pre class="actionscript3" style="font-family:monospace;"><span style="color: #9900cc; font-weight: bold;">package</span> collections <span style="color: #000000;">&#123;</span>
<span style="color: #0033ff; font-weight: bold;">import</span> com.farata.collections.DataCollection;
&nbsp;
<span style="color: #0033ff; font-weight: bold;">public</span> <span style="color: #9900cc; font-weight: bold;">class</span> OrderItemCollection extends DataCollection <span style="color: #000000;">&#123;</span>
&nbsp;
   <span style="color: #0033ff; font-weight: bold;">public</span> <span style="color: #339966; font-weight: bold;">function</span> OrderItemCollection<span style="color: #000000;">&#40;</span><span style="color: #004993;">source</span><span style="color: #000000; font-weight: bold;">:</span><span style="color: #004993;">Array</span>=<span style="color: #0033ff; font-weight: bold;">null</span><span style="color: #000000;">&#41;</span> <span style="color: #000000;">&#123;</span>
        <span style="color: #0033ff; font-weight: bold;">super</span><span style="color: #000000;">&#40;</span><span style="color: #004993;">source</span><span style="color: #000000;">&#41;</span>;
        destination=<span style="color: #990000;">&quot;com.farata.test.Order&quot;</span>;
        <span style="color: #004993;">method</span>=<span style="color: #990000;">&quot;getOrderItems&quot;</span>;
   <span style="color: #000000;">&#125;</span>
<span style="color: #000000;">&#125;</span>
<span style="color: #000000;">&#125;</span></pre></td></tr></table></div>

<p><a name="Listing4"></a></p>

<div class="wp_codebox_msgheader wp_codebox_hide"><span class="left"><a href="javascript:;" onclick="javascript:showCodeTxt('p407code61'); return false;">Listing 4. OrdersPanel. Master View</a> </span><div class="codebox_clear"></div></div><div class="wp_codebox"><table width="100%" ><tr id="p40761"><td class="code" id="p407code61"><pre class="mxml" style="font-family:monospace;"><span style="color: #000000;">&lt;?xml version=<span style="color: #990000;">&quot;1.0&quot;</span> encoding=<span style="color: #990000;">&quot;UTF-8&quot;</span>?<span style="color: #0033ff;">&gt;</span></span>
<span style="color: #000000;"><span style="color: #808080; font-style: italic;">&lt;!-- OrdersPanel.mxml --&gt;</span></span>
<span style="color: #000000;"><span style="color: #0033ff;">&lt;mx:Panel</span> title=<span style="color: #990000;">&quot;Orders&quot;</span> </span>
<span style="color: #000000;">	xmlns:mx=<span style="color: #990000;">&quot;http://www.adobe.com/2006/mxml&quot;</span> <span style="color: #0033ff;">&gt;</span></span>
&nbsp;
    <span style="color: #000000;"><span style="color: #0033ff;">&lt;mx:Metadata</span><span style="color: #0033ff;">&gt;</span></span> 
        [Event(name=&quot;orderSelectionChange&quot;, type=&quot;events.OrderEvent&quot;)] 
    <span style="color: #000000;"><span style="color: #0033ff;">&lt;/mx:Metadata</span><span style="color: #0033ff;">&gt;</span></span> 
&nbsp;
	<span style="color: #000000;"><span style="color: #0033ff;">&lt;mx:DataGrid</span> id=<span style="color: #990000;">&quot;dg&quot;</span> dataProvider=<span style="color: #990000;">&quot;{orders}&quot;</span> editable=<span style="color: #990000;">&quot;true&quot;</span>  change=<span style="color: #990000;">&quot;onChange()&quot;</span> height=<span style="color: #990000;">&quot;100%&quot;</span> <span style="color: #0033ff;">&gt;</span></span>
		<span style="color: #000000;"><span style="color: #0033ff;">&lt;mx:columns</span><span style="color: #0033ff;">&gt;</span></span>
			<span style="color: #000000;"><span style="color: #0033ff;">&lt;mx:DataGridColumn</span> dataField=<span style="color: #990000;">&quot;order_id&quot;</span> headerText=<span style="color: #990000;">&quot;Order Id&quot;</span> <span style="color: #0033ff;">/&gt;</span></span>
			<span style="color: #000000;"><span style="color: #0033ff;">&lt;mx:DataGridColumn</span> dataField=<span style="color: #990000;">&quot;customer_first_name&quot;</span> headerText=<span style="color: #990000;">&quot;First Name&quot;</span> <span style="color: #0033ff;">/&gt;</span></span>
			<span style="color: #000000;"><span style="color: #0033ff;">&lt;mx:DataGridColumn</span> dataField=<span style="color: #990000;">&quot;customer_last_name&quot;</span> headerText=<span style="color: #990000;">&quot;Last Name&quot;</span> <span style="color: #0033ff;">/&gt;</span></span>
			<span style="color: #000000;"><span style="color: #0033ff;">&lt;mx:DataGridColumn</span> dataField=<span style="color: #990000;">&quot;order_date&quot;</span> headerText=<span style="color: #990000;">&quot;Order Date&quot;</span>  itemEditor=<span style="color: #990000;">&quot;mx.controls.DateField&quot;</span> editorDataField=<span style="color: #990000;">&quot;selectedDate&quot;</span><span style="color: #0033ff;">/&gt;</span></span>
		<span style="color: #000000;"><span style="color: #0033ff;">&lt;/mx:columns</span><span style="color: #0033ff;">&gt;</span></span>
	<span style="color: #000000;"><span style="color: #0033ff;">&lt;/mx:DataGrid</span><span style="color: #0033ff;">&gt;</span></span>
	<span style="color: #000000;"><span style="color: #0033ff;">&lt;mx:ControlBar</span> width=<span style="color: #990000;">&quot;100%&quot;</span><span style="color: #0033ff;">&gt;</span></span>
		<span style="color: #000000;"><span style="color: #0033ff;">&lt;mx:Button</span> label=<span style="color: #990000;">&quot;Remove&quot;</span> click=<span style="color: #990000;">&quot;onRemove(dg.selectedIndex)&quot;</span> enabled=<span style="color: #990000;">&quot;{dg.selectedIndex != -1}&quot;</span><span style="color: #0033ff;">/&gt;</span></span>
		<span style="color: #000000;"><span style="color: #0033ff;">&lt;mx:Button</span> label=<span style="color: #990000;">&quot;Add&quot;</span> click=<span style="color: #990000;">&quot;onAdd(Math.max(0,dg.selectedIndex+1)); &quot;</span><span style="color: #0033ff;">/&gt;</span></span>
		<span style="color: #000000;"><span style="color: #0033ff;">&lt;mx:Label</span> text=<span style="color: #990000;">&quot;Deleted: {orders.deletedCount}&quot;</span><span style="color: #0033ff;">/&gt;</span></span>
		<span style="color: #000000;"><span style="color: #0033ff;">&lt;mx:Label</span> text=<span style="color: #990000;">&quot;Modified: {orders.modifiedCount}&quot;</span><span style="color: #0033ff;">/&gt;</span></span>
	<span style="color: #000000;"><span style="color: #0033ff;">&lt;/mx:ControlBar</span><span style="color: #0033ff;">&gt;</span></span>
	<span style="color: #339933;">&lt;mx:Script&gt;</span>
<span style="color: #339933;">	&lt;![CDATA[</span>
<span style="color: #339933;">	import events.OrderEvent;</span>
<span style="color: #339933;">	import com.farata.test.dto.OrderDTO;</span>
<span style="color: #339933;">	import com.farata.collections.DataCollection;</span>
&nbsp;
<span style="color: #339933;">	[Bindable] 	public var orders:DataCollection;</span>
&nbsp;
<span style="color: #339933;">	private function onAdd(position:int):void	{</span>
<span style="color: #339933;">		var item:OrderDTO = new OrderDTO();</span>
<span style="color: #339933;">		item.order_id = &quot;###&quot; + String(orders.length + 1);	</span>
<span style="color: #339933;">		item.order_date = new Date();</span>
&nbsp;
<span style="color: #339933;">		orders.addItemAt(item, position);</span>
<span style="color: #339933;">		dg.selectedIndex = position;</span>
<span style="color: #339933;">		onChange();</span>
<span style="color: #339933;">	}	</span>
<span style="color: #339933;">	private function onRemove(position:int):void {</span>
<span style="color: #339933;">		orders.removeItemAt(position);</span>
<span style="color: #339933;">	}</span>
&nbsp;
<span style="color: #339933;">	private function onChange():void {</span>
<span style="color: #339933;">		var event:OrderEvent = new OrderEvent(OrderEvent.ORDER_SELECTION_CHANGE);</span>
<span style="color: #339933;">		event.order = dg.selectedItem as OrderDTO;</span>
<span style="color: #339933;">		dispatchEvent(event);</span>
<span style="color: #339933;">	}	</span>
&nbsp;
<span style="color: #339933;">	]]&gt;</span>
<span style="color: #339933;">	&lt;/mx:Script&gt;</span>
<span style="color: #000000;"><span style="color: #0033ff;">&lt;/mx:Panel</span><span style="color: #0033ff;">&gt;</span></span></pre></td></tr></table></div>


<div class="wp_codebox_msgheader wp_codebox_hide"><span class="left"><a href="javascript:;" onclick="javascript:showCodeTxt('p407code62'); return false;">Listing 5. OrderItemsPanel. Detail View</a> </span><div class="codebox_clear"></div></div><div class="wp_codebox"><table width="100%" ><tr id="p40762"><td class="code" id="p407code62"><pre class="mxml" style="font-family:monospace;"><span style="color: #000000;">&lt;?xml version=<span style="color: #990000;">&quot;1.0&quot;</span> encoding=<span style="color: #990000;">&quot;utf-8&quot;</span>?<span style="color: #0033ff;">&gt;</span></span>
<span style="color: #000000;"><span style="color: #808080; font-style: italic;">&lt;!-- OrderItemsPanel.mxml --&gt;</span></span>
<span style="color: #000000;"><span style="color: #0033ff;">&lt;mx:Panel</span> title=<span style="color: #990000;">&quot;OrderItems&quot;</span> xmlns:mx=<span style="color: #990000;">&quot;http://www.adobe.com/2006/mxml&quot;</span> <span style="color: #0033ff;">&gt;</span></span>
	<span style="color: #000000;"><span style="color: #0033ff;">&lt;mx:DataGrid</span> id=<span style="color: #990000;">&quot;dg&quot;</span> dataProvider=<span style="color: #990000;">&quot;{orderItems}&quot;</span> editable=<span style="color: #990000;">&quot;true&quot;</span> height=<span style="color: #990000;">&quot;100%&quot;</span><span style="color: #0033ff;">&gt;</span></span>
		<span style="color: #000000;"><span style="color: #0033ff;">&lt;mx:columns</span><span style="color: #0033ff;">&gt;</span></span>
			<span style="color: #000000;"><span style="color: #0033ff;">&lt;mx:DataGridColumn</span> dataField=<span style="color: #990000;">&quot;order_id&quot;</span> headerText=<span style="color: #990000;">&quot;Order Id&quot;</span> <span style="color: #0033ff;">/&gt;</span></span>
			<span style="color: #000000;"><span style="color: #0033ff;">&lt;mx:DataGridColumn</span> dataField=<span style="color: #990000;">&quot;item_id&quot;</span> headerText=<span style="color: #990000;">&quot;Item Id&quot;</span> <span style="color: #0033ff;">/&gt;</span></span>
			<span style="color: #000000;"><span style="color: #0033ff;">&lt;mx:DataGridColumn</span> dataField=<span style="color: #990000;">&quot;product_name&quot;</span> headerText=<span style="color: #990000;">&quot;Product&quot;</span> <span style="color: #0033ff;">/&gt;</span></span>
			<span style="color: #000000;"><span style="color: #0033ff;">&lt;mx:DataGridColumn</span> dataField=<span style="color: #990000;">&quot;quantity&quot;</span> headerText=<span style="color: #990000;">&quot;Quantity&quot;</span> <span style="color: #0033ff;">/&gt;</span></span>
		<span style="color: #000000;"><span style="color: #0033ff;">&lt;/mx:columns</span><span style="color: #0033ff;">&gt;</span></span>
	<span style="color: #000000;"><span style="color: #0033ff;">&lt;/mx:DataGrid</span><span style="color: #0033ff;">&gt;</span></span>
	<span style="color: #000000;"><span style="color: #0033ff;">&lt;mx:ControlBar</span> width=<span style="color: #990000;">&quot;100%&quot;</span><span style="color: #0033ff;">&gt;</span></span>
		<span style="color: #000000;"><span style="color: #0033ff;">&lt;mx:Button</span> label=<span style="color: #990000;">&quot;Remove&quot;</span> click=<span style="color: #990000;">&quot;onRemove(dg.selectedIndex);&quot;</span> enabled=<span style="color: #990000;">&quot;{dg.selectedIndex != -1}&quot;</span><span style="color: #0033ff;">/&gt;</span></span>
		<span style="color: #000000;"><span style="color: #0033ff;">&lt;mx:Button</span> label=<span style="color: #990000;">&quot;Add&quot;</span> click=<span style="color: #990000;">&quot;onAdd(Math.max(0,dg.selectedIndex + 1)); &quot;</span> enabled=<span style="color: #990000;">&quot;{selectedOrder!=null}&quot;</span><span style="color: #0033ff;">/&gt;</span></span>
		<span style="color: #000000;"><span style="color: #0033ff;">&lt;mx:Label</span> text=<span style="color: #990000;">&quot;Deleted: {orderItems.deletedCount}&quot;</span><span style="color: #0033ff;">/&gt;</span></span>
		<span style="color: #000000;"><span style="color: #0033ff;">&lt;mx:Label</span> text=<span style="color: #990000;">&quot;Modified: {orderItems.modifiedCount}&quot;</span><span style="color: #0033ff;">/&gt;</span></span>
	<span style="color: #000000;"><span style="color: #0033ff;">&lt;/mx:ControlBar</span><span style="color: #0033ff;">&gt;</span></span>
	<span style="color: #339933;">&lt;mx:Script&gt;</span>
<span style="color: #339933;">		&lt;![CDATA[</span>
<span style="color: #339933;">		import com.farata.test.dto.OrderItemDTO;</span>
<span style="color: #339933;">		import com.farata.test.dto.OrderDTO;</span>
<span style="color: #339933;">		import com.farata.collections.DataCollection;</span>
&nbsp;
<span style="color: #339933;">	    [Bindable]private var orderItems:DataCollection ;</span>
&nbsp;
<span style="color: #339933;">		private var _selectedOrder:OrderDTO;</span>
<span style="color: #339933;">		[Bindable]</span>
<span style="color: #339933;">		public function set selectedOrder(order:OrderDTO):void {</span>
<span style="color: #339933;">			_selectedOrder = order;</span>
<span style="color: #339933;">			if (order != null) {</span>
<span style="color: #339933;">				orderItems = order.orderItems;</span>
<span style="color: #339933;">			} else </span>
<span style="color: #339933;">			 	orderItems = null; </span>
<span style="color: #339933;">		}</span>
<span style="color: #339933;">		public function get selectedOrder():OrderDTO {</span>
<span style="color: #339933;">			return _selectedOrder;</span>
<span style="color: #339933;">		}</span>
&nbsp;
<span style="color: #339933;">		private function onAdd(position:int):void	{</span>
<span style="color: #339933;">			var item:OrderItemDTO = new OrderItemDTO();</span>
<span style="color: #339933;">			item.order_id = selectedOrder.order_id;			</span>
<span style="color: #339933;">			if (item.quantity ==0) item.quantity = 1;</span>
&nbsp;
<span style="color: #339933;">			orderItems.addItemAt(item, position);</span>
<span style="color: #339933;">			dg.selectedIndex = position;</span>
<span style="color: #339933;">		}</span>
<span style="color: #339933;">		private function onRemove(position:int):void {</span>
<span style="color: #339933;">			orderItems.removeItemAt(position);</span>
<span style="color: #339933;">		}</span>
<span style="color: #339933;">	]]&gt;</span>
<span style="color: #339933;">	&lt;/mx:Script&gt;</span>	
<span style="color: #000000;"><span style="color: #0033ff;">&lt;/mx:Panel</span><span style="color: #0033ff;">&gt;</span></span></pre></td></tr></table></div>

<p><a name="Listing6"></a></p>

<div class="wp_codebox_msgheader wp_codebox_hide"><span class="left"><a href="javascript:;" onclick="javascript:showCodeTxt('p407code63'); return false;">Listing 6. OrderEvent</a> </span><div class="codebox_clear"></div></div><div class="wp_codebox"><table width="100%" ><tr id="p40763"><td class="code" id="p407code63"><pre class="actionscript3" style="font-family:monospace;"><span style="color: #9900cc; font-weight: bold;">package</span> events<span style="color: #000000;">&#123;</span>
<span style="color: #0033ff; font-weight: bold;">import</span> com.farata.<span style="color: #004993;">test</span>.dto.OrderDTO;
<span style="color: #0033ff; font-weight: bold;">import</span> <span style="color: #004993;">flash.events</span>.<span style="color: #004993;">Event</span>;
<span style="color: #0033ff; font-weight: bold;">public</span> <span style="color: #9900cc; font-weight: bold;">class</span> OrderEvent extends <span style="color: #004993;">Event</span> <span style="color: #000000;">&#123;</span>
    <span style="color: #0033ff; font-weight: bold;">public</span> static const ORDER_SELECTION_CHANGE<span style="color: #000000; font-weight: bold;">:</span><span style="color: #004993;">String</span> =<span style="color: #990000;">&quot;orderSelectionChange&quot;</span>;
&nbsp;
    <span style="color: #0033ff; font-weight: bold;">public</span> <span style="color: #6699cc; font-weight: bold;">var</span> order<span style="color: #000000; font-weight: bold;">:</span>OrderDTO;
    <span style="color: #0033ff; font-weight: bold;">public</span> <span style="color: #339966; font-weight: bold;">function</span> OrderEvent<span style="color: #000000;">&#40;</span><span style="color: #004993;">type</span><span style="color: #000000; font-weight: bold;">:</span><span style="color: #004993;">String</span>, <span style="color: #004993;">bubbles</span><span style="color: #000000; font-weight: bold;">:</span><span style="color: #004993;">Boolean</span>=<span style="color: #0033ff; font-weight: bold;">false</span>, <span style="color: #004993;">cancelable</span><span style="color: #000000; font-weight: bold;">:</span><span style="color: #004993;">Boolean</span>=<span style="color: #0033ff; font-weight: bold;">false</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">&#123;</span>
        <span style="color: #0033ff; font-weight: bold;">super</span><span style="color: #000000;">&#40;</span><span style="color: #004993;">type</span>, <span style="color: #004993;">bubbles</span>, <span style="color: #004993;">cancelable</span><span style="color: #000000;">&#41;</span>;
    <span style="color: #000000;">&#125;</span>
<span style="color: #000000;">&#125;</span>
<span style="color: #000000;">&#125;</span></pre></td></tr></table></div>

<p><a name="Listing7"></a></p>

<div class="wp_codebox_msgheader wp_codebox_hide"><span class="left"><a href="javascript:;" onclick="javascript:showCodeTxt('p407code64'); return false;">Listing 7. OrderDTO, the IHierarchicalDTO</a> </span><div class="codebox_clear"></div></div><div class="wp_codebox"><table width="100%" ><tr id="p40764"><td class="code" id="p407code64"><pre class="actionscript3" style="font-family:monospace;"><span style="color: #3f5fbf;">/* Generated only when absent by ClearDataBuilder according to UserActionScriptDTO.xsl */</span>
<span style="color: #9900cc; font-weight: bold;">package</span> com.farata.<span style="color: #004993;">test</span>.dto<span style="color: #000000;">&#123;</span>
<span style="color: #0033ff; font-weight: bold;">import</span> collections.OrderItemCollection;
<span style="color: #0033ff; font-weight: bold;">import</span> com.farata.collections.dto.HierarchicalDTOAdapter;
<span style="color: #0033ff; font-weight: bold;">import</span> com.farata.collections.dto.IHierarchicalDTO;
&nbsp;
<span style="color: #000000;">&#91;</span>RemoteClass<span style="color: #000000;">&#40;</span>alias=<span style="color: #990000;">&quot;com.farata.test.dto.OrderDTO&quot;</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">&#93;</span>
<span style="color: #0033ff; font-weight: bold;">public</span> <span style="color: #9900cc; font-weight: bold;">class</span> OrderDTO extends _OrderDTO implements IHierarchicalDTO<span style="color: #000000;">&#123;</span>
<span style="color: #009900;">//--------------------------------------------//</span>
<span style="color: #009900;">// Your custom code goes here                       //</span>
<span style="color: #009900;">//--------------------------------------------//</span>
&nbsp;
<span style="color: #000000;">&#91;</span>Transient<span style="color: #000000;">&#93;</span> <span style="color: #000000;">&#91;</span><span style="color: #0033ff; font-weight: bold;">Bindable</span><span style="color: #000000;">&#93;</span> <span style="color: #0033ff; font-weight: bold;">public</span> <span style="color: #6699cc; font-weight: bold;">var</span> orderItems<span style="color: #000000; font-weight: bold;">:</span>OrderItemCollection;
<span style="color: #000000;">&#91;</span>Transient<span style="color: #000000;">&#93;</span> <span style="color: #0033ff; font-weight: bold;">public</span> <span style="color: #6699cc; font-weight: bold;">var</span> adapter<span style="color: #000000; font-weight: bold;">:</span>HierarchicalDTOAdapter;
&nbsp;
<span style="color: #0033ff; font-weight: bold;">public</span> <span style="color: #339966; font-weight: bold;">function</span> OrderDTO<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span> <span style="color: #000000;">&#123;</span>
    <span style="color: #0033ff; font-weight: bold;">super</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>;
    adapter = <span style="color: #0033ff; font-weight: bold;">new</span> HierarchicalDTOAdapter<span style="color: #000000;">&#40;</span><span style="color: #0033ff; font-weight: bold;">this</span><span style="color: #000000;">&#41;</span>;
    orderItems = <span style="color: #0033ff; font-weight: bold;">new</span> OrderItemCollection<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>;
    adapter.addCollection<span style="color: #000000;">&#40;</span>orderItems<span style="color: #000000;">&#41;</span>;
<span style="color: #000000;">&#125;</span>
&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> childCollections<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #000000; font-weight: bold;">:</span><span style="color: #004993;">Array</span> <span style="color: #000000;">&#123;</span>
    <span style="color: #0033ff; font-weight: bold;">return</span> adapter.childCollections;
<span style="color: #000000;">&#125;</span>
&nbsp;
<span style="color: #0033ff; font-weight: bold;">public</span> override <span style="color: #339966; font-weight: bold;">function</span> <span style="color: #0033ff; font-weight: bold;">set</span> order_id<span style="color: #000000;">&#40;</span>orderId<span style="color: #000000; font-weight: bold;">:</span><span style="color: #004993;">String</span><span style="color: #000000;">&#41;</span><span style="color: #000000; font-weight: bold;">:</span><span style="color: #0033ff; font-weight: bold;">void</span> <span style="color: #000000;">&#123;</span>
    <span style="color: #0033ff; font-weight: bold;">if</span> <span style="color: #000000;">&#40;</span>orderId <span style="color: #000000; font-weight: bold;">!</span>== <span style="color: #0033ff; font-weight: bold;">super</span>.order_id<span style="color: #000000;">&#41;</span> <span style="color: #000000;">&#123;</span>
        <span style="color: #0033ff; font-weight: bold;">super</span>.order_id = orderId;
        orderItems.fill<span style="color: #000000;">&#40;</span>order_id<span style="color: #000000;">&#41;</span>;
    <span style="color: #000000;">&#125;</span>
<span style="color: #000000;">&#125;</span>
<span style="color: #000000;">&#125;</span><span style="color: #009900;">//OrderDTO</span>
<span style="color: #000000;">&#125;</span></pre></td></tr></table></div>

<p><a name="Listing8"></a></p>

<div class="wp_codebox_msgheader wp_codebox_hide"><span class="left"><a href="javascript:;" onclick="javascript:showCodeTxt('p407code65'); return false;">Listing 8. Order.java - Doclet-annotated for CDB code generation</a> </span><div class="codebox_clear"></div></div><div class="wp_codebox"><table width="100%" ><tr id="p40765"><td class="code" id="p407code65"><pre class="java" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">package</span> <span style="color: #006699;">com.farata.test</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">java.util.List</span><span style="color: #339933;">;</span>
<span style="color: #008000; font-style: italic; font-weight: bold;">/**
* @daoflex:webservice
* pool=jdbc/test
*/</span>
<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">abstract</span> <span style="color: #000000; font-weight: bold;">class</span> Order
<span style="color: #009900;">&#123;</span>
<span style="color: #008000; font-style: italic; font-weight: bold;">/**
* @daoflex:sql
* sql=:: select order_id, customer_first_name,
* customer_last_name, order_date from simple_order
* ::
* transferType=OrderDTO[]
* keyColumns=order_id
* updateTable=simple_order
* autoSyncEnabled=true
*/</span>
<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">abstract</span> <span style="color: #003399;">List</span> getOrders<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #008000; font-style: italic; font-weight: bold;">/**
* @daoflex:sql
* sql=select * from simple_order_item WHERE ORDER_ID=:orderId
* transferType=OrderItemDTO[]
* updateTable=simple_order_item
* keyColumns=order_id,item_id,product_name
* autoSyncEnabled=true
*/</span>
<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">abstract</span> <span style="color: #003399;">List</span> getOrderItems<span style="color: #009900;">&#40;</span><span style="color: #003399;">String</span> orderId<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span></pre></td></tr></table></div>

<p><a name="Listing 9"></a></p>

<div class="wp_codebox_msgheader wp_codebox_hide"><span class="left"><a href="javascript:;" onclick="javascript:showCodeTxt('p407code66'); return false;">Listing 9. Database tables: order and order_item</a> </span><div class="codebox_clear"></div></div><div class="wp_codebox"><table width="100%" ><tr id="p40766"><td class="code" id="p407code66"><pre class="mysql" style="font-family:monospace;"><span style="color: #990099; font-weight: bold;">CREATE</span> <span style="color: #990099; font-weight: bold;">TABLE</span> <span style="color: #008000;">`simple<span style="color: #008080; font-weight: bold;">_</span>order`</span> <span style="color: #FF00FF;">&#40;</span>
<span style="color: #008000;">`order<span style="color: #008080; font-weight: bold;">_</span>id`</span> <span style="color: #000099;">char</span><span style="color: #FF00FF;">&#40;</span><span style="color: #008080;">32</span><span style="color: #FF00FF;">&#41;</span> <span style="color: #CC0099; font-weight: bold;">NOT</span> <span style="color: #9900FF; font-weight: bold;">NULL</span> <span style="color: #990099; font-weight: bold;">default</span> <span style="color: #008000;">''</span><span style="color: #000033;">,</span>
<span style="color: #008000;">`customer<span style="color: #008080; font-weight: bold;">_</span>first<span style="color: #008080; font-weight: bold;">_</span>name`</span> <span style="color: #999900; font-weight: bold;">varchar</span><span style="color: #FF00FF;">&#40;</span><span style="color: #008080;">32</span><span style="color: #FF00FF;">&#41;</span> <span style="color: #CC0099; font-weight: bold;">NOT</span> <span style="color: #9900FF; font-weight: bold;">NULL</span> <span style="color: #990099; font-weight: bold;">default</span> <span style="color: #008000;">''</span><span style="color: #000033;">,</span>
<span style="color: #008000;">`customer<span style="color: #008080; font-weight: bold;">_</span>last<span style="color: #008080; font-weight: bold;">_</span>name`</span> <span style="color: #999900; font-weight: bold;">varchar</span><span style="color: #FF00FF;">&#40;</span><span style="color: #008080;">32</span><span style="color: #FF00FF;">&#41;</span> <span style="color: #CC0099; font-weight: bold;">NOT</span> <span style="color: #9900FF; font-weight: bold;">NULL</span> <span style="color: #990099; font-weight: bold;">default</span> <span style="color: #008000;">''</span><span style="color: #000033;">,</span>
<span style="color: #008000;">`order<span style="color: #008080; font-weight: bold;">_</span>date`</span> <span style="color: #999900; font-weight: bold;">datetime</span> <span style="color: #CC0099; font-weight: bold;">NOT</span> <span style="color: #9900FF; font-weight: bold;">NULL</span> <span style="color: #990099; font-weight: bold;">default</span> <span style="color: #008000;">'0000-00-00 00:00:00'</span><span style="color: #000033;">,</span>
<span style="color: #990099; font-weight: bold;">PRIMARY KEY</span> <span style="color: #FF00FF;">&#40;</span><span style="color: #008000;">`order<span style="color: #008080; font-weight: bold;">_</span>id`</span><span style="color: #FF00FF;">&#41;</span>
<span style="color: #FF00FF;">&#41;</span> <span style="color: #990099; font-weight: bold;">ENGINE</span><span style="color: #CC0099;">=</span><span style="color: #990099; font-weight: bold;">InnoDB</span> <span style="color: #990099; font-weight: bold;">DEFAULT</span> <span style="color: #FF9900; font-weight: bold;">CHARSET</span><span style="color: #CC0099;">=</span>latin1$$
&nbsp;
<span style="color: #990099; font-weight: bold;">INSERT</span> <span style="color: #990099; font-weight: bold;">INTO</span> <span style="color: #008000;">`simple<span style="color: #008080; font-weight: bold;">_</span>order`</span> <span style="color: #FF00FF;">&#40;</span><span style="color: #008000;">`order<span style="color: #008080; font-weight: bold;">_</span>id`</span><span style="color: #000033;">,</span><span style="color: #008000;">`customer<span style="color: #008080; font-weight: bold;">_</span>first<span style="color: #008080; font-weight: bold;">_</span>name`</span><span style="color: #000033;">,</span><span style="color: #008000;">`customer<span style="color: #008080; font-weight: bold;">_</span>last<span style="color: #008080; font-weight: bold;">_</span>name`</span><span style="color: #000033;">,</span><span style="color: #008000;">`order<span style="color: #008080; font-weight: bold;">_</span>date`</span><span style="color: #FF00FF;">&#41;</span> <span style="color: #990099; font-weight: bold;">VALUES</span>
<span style="color: #FF00FF;">&#40;</span><span style="color: #008000;">'###1'</span><span style="color: #000033;">,</span><span style="color: #008000;">'Victor'</span><span style="color: #000033;">,</span><span style="color: #008000;">'Rasputnis'</span><span style="color: #000033;">,</span><span style="color: #008000;">'2006-02-04 00:00:00'</span><span style="color: #FF00FF;">&#41;</span><span style="color: #000033;">,</span>
<span style="color: #FF00FF;">&#40;</span><span style="color: #008000;">'###2'</span><span style="color: #000033;">,</span><span style="color: #008000;">'Yakov'</span><span style="color: #000033;">,</span><span style="color: #008000;">'Fain'</span><span style="color: #000033;">,</span><span style="color: #008000;">'2006-09-25 00:00:00'</span><span style="color: #FF00FF;">&#41;</span><span style="color: #000033;">,</span>
<span style="color: #FF00FF;">&#40;</span><span style="color: #008000;">'###3'</span><span style="color: #000033;">,</span><span style="color: #008000;">'Anatole'</span><span style="color: #000033;">,</span><span style="color: #008000;">'Tartakovsky'</span><span style="color: #000033;">,</span><span style="color: #008000;">'2006-07-01 00:00:00'</span><span style="color: #FF00FF;">&#41;</span>$$
&nbsp;
<span style="color: #990099; font-weight: bold;">CREATE</span> <span style="color: #990099; font-weight: bold;">TABLE</span> <span style="color: #008000;">`simple<span style="color: #008080; font-weight: bold;">_</span>order<span style="color: #008080; font-weight: bold;">_</span>item`</span> <span style="color: #FF00FF;">&#40;</span>
<span style="color: #008000;">`order<span style="color: #008080; font-weight: bold;">_</span>id`</span> <span style="color: #000099;">char</span><span style="color: #FF00FF;">&#40;</span><span style="color: #008080;">32</span><span style="color: #FF00FF;">&#41;</span> <span style="color: #CC0099; font-weight: bold;">NOT</span> <span style="color: #9900FF; font-weight: bold;">NULL</span> <span style="color: #990099; font-weight: bold;">default</span> <span style="color: #008000;">''</span><span style="color: #000033;">,</span>
<span style="color: #008000;">`item<span style="color: #008080; font-weight: bold;">_</span>id`</span> <span style="color: #000099;">char</span><span style="color: #FF00FF;">&#40;</span><span style="color: #008080;">32</span><span style="color: #FF00FF;">&#41;</span> <span style="color: #CC0099; font-weight: bold;">NOT</span> <span style="color: #9900FF; font-weight: bold;">NULL</span> <span style="color: #990099; font-weight: bold;">default</span> <span style="color: #008000;">''</span><span style="color: #000033;">,</span>
<span style="color: #008000;">`product<span style="color: #008080; font-weight: bold;">_</span>name`</span> <span style="color: #999900; font-weight: bold;">varchar</span><span style="color: #FF00FF;">&#40;</span><span style="color: #008080;">32</span><span style="color: #FF00FF;">&#41;</span> <span style="color: #CC0099; font-weight: bold;">NOT</span> <span style="color: #9900FF; font-weight: bold;">NULL</span> <span style="color: #990099; font-weight: bold;">default</span> <span style="color: #008000;">''</span><span style="color: #000033;">,</span>
<span style="color: #008000;">`quantity`</span> <span style="color: #999900; font-weight: bold;">int</span><span style="color: #FF00FF;">&#40;</span><span style="color: #008080;">11</span><span style="color: #FF00FF;">&#41;</span> <span style="color: #CC0099; font-weight: bold;">NOT</span> <span style="color: #9900FF; font-weight: bold;">NULL</span> <span style="color: #990099; font-weight: bold;">default</span> <span style="color: #008000;">'1'</span><span style="color: #000033;">,</span>
<span style="color: #990099; font-weight: bold;">PRIMARY KEY</span> <span style="color: #FF00FF;">&#40;</span><span style="color: #008000;">`order<span style="color: #008080; font-weight: bold;">_</span>id`</span><span style="color: #000033;">,</span><span style="color: #008000;">`item<span style="color: #008080; font-weight: bold;">_</span>id`</span><span style="color: #000033;">,</span><span style="color: #008000;">`product<span style="color: #008080; font-weight: bold;">_</span>name`</span><span style="color: #FF00FF;">&#41;</span>
<span style="color: #FF00FF;">&#41;</span> <span style="color: #990099; font-weight: bold;">ENGINE</span><span style="color: #CC0099;">=</span><span style="color: #990099; font-weight: bold;">InnoDB</span> <span style="color: #990099; font-weight: bold;">DEFAULT</span> <span style="color: #FF9900; font-weight: bold;">CHARSET</span><span style="color: #CC0099;">=</span>latin1$$
&nbsp;
<span style="color: #990099; font-weight: bold;">INSERT</span> <span style="color: #990099; font-weight: bold;">INTO</span> <span style="color: #008000;">`simple<span style="color: #008080; font-weight: bold;">_</span>order<span style="color: #008080; font-weight: bold;">_</span>item`</span> <span style="color: #FF00FF;">&#40;</span><span style="color: #008000;">`order<span style="color: #008080; font-weight: bold;">_</span>id`</span><span style="color: #000033;">,</span><span style="color: #008000;">`item<span style="color: #008080; font-weight: bold;">_</span>id`</span><span style="color: #000033;">,</span><span style="color: #008000;">`product<span style="color: #008080; font-weight: bold;">_</span>name`</span><span style="color: #000033;">,</span><span style="color: #008000;">`quantity`</span><span style="color: #FF00FF;">&#41;</span> <span style="color: #990099; font-weight: bold;">VALUES</span>
<span style="color: #FF00FF;">&#40;</span><span style="color: #008000;">'###1'</span><span style="color: #000033;">,</span><span style="color: #008000;">'1'</span><span style="color: #000033;">,</span><span style="color: #008000;">'Laptop'</span><span style="color: #000033;">,</span><span style="color: #008080;">1</span><span style="color: #FF00FF;">&#41;</span><span style="color: #000033;">,</span>
<span style="color: #FF00FF;">&#40;</span><span style="color: #008000;">'###1'</span><span style="color: #000033;">,</span><span style="color: #008000;">'2'</span><span style="color: #000033;">,</span><span style="color: #008000;">'Battery'</span><span style="color: #000033;">,</span><span style="color: #008080;">1</span><span style="color: #FF00FF;">&#41;</span><span style="color: #000033;">,</span>
<span style="color: #FF00FF;">&#40;</span><span style="color: #008000;">'###1'</span><span style="color: #000033;">,</span><span style="color: #008000;">'3'</span><span style="color: #000033;">,</span><span style="color: #008000;">'Laptop Backpack'</span><span style="color: #000033;">,</span><span style="color: #008080;">1</span><span style="color: #FF00FF;">&#41;</span><span style="color: #000033;">,</span>
<span style="color: #FF00FF;">&#40;</span><span style="color: #008000;">'###3'</span><span style="color: #000033;">,</span><span style="color: #008000;">'1'</span><span style="color: #000033;">,</span><span style="color: #008000;">'Apple'</span><span style="color: #000033;">,</span><span style="color: #008080;">1</span><span style="color: #FF00FF;">&#41;</span><span style="color: #000033;">,</span>
<span style="color: #FF00FF;">&#40;</span><span style="color: #008000;">'###3'</span><span style="color: #000033;">,</span><span style="color: #008000;">'2'</span><span style="color: #000033;">,</span><span style="color: #008000;">'Orange'</span><span style="color: #000033;">,</span><span style="color: #008080;">1</span><span style="color: #FF00FF;">&#41;</span></pre></td></tr></table></div>

<p>Victor Rasputnis</p>
]]></content:encoded>
			<wfw:commentRss>http://flexblog.faratasystems.com/2009/04/01/deep-synchronization-of-datacollections-with-the-java-server/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>How to use Clear Data Builder with AIR applications</title>
		<link>http://flexblog.faratasystems.com/2009/03/21/how-to-use-clear-data-builder-with-air-applications</link>
		<comments>http://flexblog.faratasystems.com/2009/03/21/how-to-use-clear-data-builder-with-air-applications#comments</comments>
		<pubDate>Sat, 21 Mar 2009 14:11:43 +0000</pubDate>
		<dc:creator>Victor Rasputnis</dc:creator>
				<category><![CDATA[Flex]]></category>
		<category><![CDATA[AIR]]></category>
		<category><![CDATA[Clear Data Builder]]></category>
		<category><![CDATA[Clear Toolkit]]></category>
		<category><![CDATA[DataCollection]]></category>

		<guid isPermaLink="false">http://flexblog.faratasystems.com/?p=402</guid>
		<description><![CDATA[I&#8217;ve added a new How To entry to the Wiki section of  our open source Clear Toolkit framework. It explains the steps required to turn a CRUD Flex application generated by Clear Data Builder into an AIR application.
The Wiki page of Clear Toolkit is http://cleartoolkit.wiki.sourceforge.net/
The lates build, documentation and the source code of all Clear [...]]]></description>
			<content:encoded><![CDATA[<p>I&#8217;ve added a new How To entry to the <a href="http://cleartoolkit.wiki.sourceforge.net/" target="_blank">Wiki</a> section of  our open source Clear Toolkit framework. It explains the steps required to turn a <a title="ClearDataBuilder and DataCollection with Air" href="http://cleartoolkit.wiki.sourceforge.net/Using+CDB+with+Air" target="_blank">CRUD Flex application generated by Clear Data Builder into an AIR application</a>.</p>
<p>The Wiki page of Clear Toolkit is <a href="http://cleartoolkit.wiki.sourceforge.net/">http://cleartoolkit.wiki.sourceforge.net/</a></p>
<p>The lates build, documentation and the source code of all Clear Toolkit components you can find at <a href="https://sourceforge.net/projects/cleartoolkit/">https://sourceforge.net/projects/cleartoolkit/</a></p>
<p>Victor</p>
]]></content:encoded>
			<wfw:commentRss>http://flexblog.faratasystems.com/2009/03/21/how-to-use-clear-data-builder-with-air-applications/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>The next public Certified Flex training is announced</title>
		<link>http://flexblog.faratasystems.com/2008/10/24/the-next-public-certified-training-is-announced</link>
		<comments>http://flexblog.faratasystems.com/2008/10/24/the-next-public-certified-training-is-announced#comments</comments>
		<pubDate>Fri, 24 Oct 2008 12:52:37 +0000</pubDate>
		<dc:creator>Victor Rasputnis</dc:creator>
				<category><![CDATA[Adobe Flex training]]></category>
		<category><![CDATA[Flex]]></category>
		<category><![CDATA[Flex Builder]]></category>

		<guid isPermaLink="false">http://flexblog.faratasystems.com/?p=369</guid>
		<description><![CDATA[In 2008, our company ran lots of various Flex training classes for our private clients (mostly Wall Street), and several public classes and seminars.   We are closing 2008 with a week of public Adobe Certified Flex 3 training that will take place in Jersey City, NJ on the week of December 8, 2008.
Details and registration [...]]]></description>
			<content:encoded><![CDATA[<p>In 2008, our company ran lots of various Flex training classes for our private clients (mostly Wall Street), and several public classes and seminars.   We are closing 2008 with a week of public Adobe Certified Flex 3 training that will take place in Jersey City, NJ on the week of December 8, 2008.</p>
<p>Details and registration at <a href="http://www.eventbrite.com/event/202308109">http://www.eventbrite.com/event/202308109</a>.</p>
<p>Have you used your training budget of 2008 yet?</p>
<p>Victor</p>
]]></content:encoded>
			<wfw:commentRss>http://flexblog.faratasystems.com/2008/10/24/the-next-public-certified-training-is-announced/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Miracle of Data Transfer Objects</title>
		<link>http://flexblog.faratasystems.com/2008/02/17/miracle-of-data-transfer-objects</link>
		<comments>http://flexblog.faratasystems.com/2008/02/17/miracle-of-data-transfer-objects#comments</comments>
		<pubDate>Sun, 17 Feb 2008 18:26:54 +0000</pubDate>
		<dc:creator>Victor Rasputnis</dc:creator>
				<category><![CDATA[ActionScript]]></category>
		<category><![CDATA[Adobe Flex training]]></category>
		<category><![CDATA[Data Management]]></category>
		<category><![CDATA[Flex]]></category>
		<category><![CDATA[Flex Consulting]]></category>

		<guid isPermaLink="false">http://flexblog.faratasystems.com/?p=300</guid>
		<description><![CDATA[If you had only one hour in Paris, what would you do?
I, for one, would walk around Notre-Dame, and the point I am going to make is about Flex:
If I could pass just one Flex advice that would be: Use Data Transfer Objects.
Use Data Transfer Objects and NOT the dynamic Objects, and NOT the XML [...]]]></description>
			<content:encoded><![CDATA[<p>If you had only one hour in Paris, what would you do?</p>
<p>I, for one, would walk around Notre-Dame, and the point I am going to make is about Flex:</p>
<p><strong>If I could pass just one Flex advice that would be: Use Data Transfer Objects.</strong></p>
<p>Use Data Transfer Objects and NOT the dynamic Objects, and NOT the XML to pass data between your server and Flash tiers. If you are working with a Java Server, make your Java (methods) accept/return custom classes and NOT Map objects.</p>
<p>With this keystone your architecture will be reliable and performing. You will save tons of time and energy. What do you do with these savings &#8211; none of my business.</p>
<p>Here are the details:</p>
<p>1. _DO_ define similar classes on Java and ActionScript. See details of Java/ActionScript type mapping in the Flex documentation.</p>
<p>2. _DO_ declare these classes as [Bindable] if you envision dynamic updates to the data. Further, _DO_ use collections of these Bindable instances as dataProviders for your DataGrid and let Flex do the miracle: all changes to the data will be reflected by the visual control. There are no miracles, of course: [Bindable] is a shortcut to dispatch event on a data change, the very same event that is expected by ArrayCollection. The collection in turn, dispatches a (different) event on its change. Importantly &#8211; the very same event that is expected by the DataGrid.</p>
<p>Let me put it another way: have you ever used collection.itemUpdated()? Well, once you start DTO&#8217;s &#8220;itemUpdated&#8221; will sound to you like the name of the undocumented event <img src='http://flexblog.faratasystems.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
<p>OK, I will rub it in further: if you marshall (property) Array of Objects, the Array itself is Bindable, but none of the items are.</p>
<p>3. Make sure that your server-side and client-side DTOs _DO_ provide unique! set/get uuid property. Flex loves this property, do get in love with it too. Flex is using it to identify elements of data presented by the list-based controls. You will find numerous uses for it as well. For instance, instead of sorting by industry, ticker you would sort by industry, ticker and uuid. Why? Because then the hash value will be unique for each record, which would result in substantially better performance.</p>
<p>4. _DO NOT_ hunt for value change on the visual controls (aka View). This task belongs to the data layer (aka Model). Consider replacing [Bindable] public var with the get/set property pair and dispatching the event (PropertyChange) yourself:</p>
<p>private var _amount:Number;<br />
public function get amount() : String{<br />
return _amount;<br />
}<br />
public function set amount( value : Number ):void{<br />
var oldValue:Object = this._amount;<br />
if (oldValue !== value)   {<br />
this._amount = value;<br />
dispatchUpdateEvent(&#8220;amount&#8221;, oldValue, value);<br />
}<br />
}<br />
private function dispatchUpdateEvent(propertyName:String, oldValue:Object, value:Object):void {<br />
dispatchEvent(<br />
PropertyChangeEvent.createUpdateEvent(this, propertyName, oldValue, value)<br />
);                    �<br />
}</p>
<p>Then, to act on value change, consider customizing the set method. Better yet, consider extending your ActionScript DTO with another class: leave basic layer of DTOs untouched, do customization in the extension. One more gain right here: now you can intercept (breakpoint) whenever your data changes.</p>
<p>5. _DO_ use extension of DTO class (above) to introduce &#8220;computed columns&#8221;:</p>
<p>public function get unrealizedGain():Number {<br />
return lastPrice &#8211; costBasis; �<br />
}</p>
<p>Again, _DO NOT_ use itemEditEnd of the control for these and similar purposes.</p>
<p>_DO NOT_ be afraid of two [RemoteClass] pointing to the same Java DTO: Flex will resolve the reference in favor of the extension layer.</p>
<p>6. Over your project lifespan, you will see many additional fits for DTOs: custom serialization,  custom toString() and toXML() methods.</p>
<p>Now, you may say that all these recommendation are way too obvious.</p>
<p>Then I just take off my hat and &#8230; see you around Notre-Dame, perhaps.<br />
Otherwise, keep coding.</p>
<p>Victor</p>
]]></content:encoded>
			<wfw:commentRss>http://flexblog.faratasystems.com/2008/02/17/miracle-of-data-transfer-objects/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Boost productivity of your Flex-Java project with Log4Fx component</title>
		<link>http://flexblog.faratasystems.com/2007/11/13/boost-productivity-of-your-flex-java-project-with-log4fx-component</link>
		<comments>http://flexblog.faratasystems.com/2007/11/13/boost-productivity-of-your-flex-java-project-with-log4fx-component#comments</comments>
		<pubDate>Tue, 13 Nov 2007 17:13:13 +0000</pubDate>
		<dc:creator>Victor Rasputnis</dc:creator>
				<category><![CDATA[Flex]]></category>
		<category><![CDATA[Flex 2]]></category>

		<guid isPermaLink="false">http://flexblog.faratasystems.com/?p=268</guid>
		<description><![CDATA[It’s hard to overestimate the importance of having good logging facility when you develop distributed  applications. Did the client’s request reached the server side component? What did the server sent back?  Add to this inability of using debuggers while processing GUI events like focus change, and you may    need to [...]]]></description>
			<content:encoded><![CDATA[<p>It’s hard to overestimate the importance of having good logging facility when you develop distributed  applications. Did the client’s request reached the server side component? What did the server sent back?  Add to this inability of using debuggers while processing GUI events like focus change, and you may    need to spend hours if not days trying to spot some sophisticated errors. That’s why commercial-grade  logger is a must if you work with an application that is spread over the network and is written in  different languages such as Adobe Flex and Java.</p>
<p>Log4Fx is an advanced yet very simple to use logger component for Adobe Flex applications that use Java application servers. You can set up the logging on the client or server sides, and you can redirect the output of the log messages to local log windows or make the log output easily available to the production support teams located remotely.  Think of a production situation when a particular client complains that the application runs slow. Log4Fx allows you to turn on the logging just for this client and you can do it remotely with Web-browser access to the log output.</p>
<p>Log4Fx comes with several convenient and easy to use display panels with log messages. This manual also covers techniques of logging mixed Flex/Java projects with or without Flex Builder.</p>
<p><span style="font-weight: bold;">USING LOG4FX</span></p>
<p>If you’ve been using other loggers like log4j, you’ll be pleasantly surprised seeing how Log4Fx automatically inserts required logging code in your existing Flex project. It comes down to memorizing a couple of keystroke combinations as explained below. But first, you need to install Log4Fx, and then add it to your Flex project.<br />
Just right-click on your Flex Project, select Log4Fx &gt; Add Dependency Files from the popup menu.This action will add several new artifacts to your project:</p>
<p>•    A new Flex component Log4FxLoggingTarget.mxml, will be automatically added to your project directory<br />
•    An extra tag  &lt;Log4FxLoggingTarget xmlns=&#8221;*&#8221;&gt; will be added at the end of the source code of your default Flex application<br />
•    A new application RemoteLogReceiver.mxml is added to the project to provide remote access to the log messages<br />
•    The Log4Fx.swc is added to your project’s build path<br />
•    A small file log4flex.jar is added to the your Java server’s lib folder</p>
<p>Now you can use the hot keys to add required log lines to your application code. You can see the list of available hot keys by pressing CTRL + R.<br />
<img src="http://res.sys-con.com/story/nov07/460527/fig1.JPG" alt="" width="210" height="110" align="left" /><br />
For example, let’s say you are considering adding a line to the application called MyStockProtflio:</p>
<p><span style="color: #993366;">trace(“Entered  the method getPriceQuotes”);</span></p>
<p>Just press the cursor in the script section of your application and press Ctrl+R followed by M, which will insert the  following lines in your program:</p>
<p><span style="color: #993366;"> import mx.logging.Log;</span><br style="color: #993366;" /><span style="color: #993366;"> import mx.logging.ILogger;</span><br style="color: #993366;" /><span style="color: #993366;"> private var logger:ILogger = Log.getLogger(&#8220;MyStockPortfolio&#8221;);</span><br style="color: #993366;" /><br />
Now place the cursor, say in the function getPriceQuotes() and press Ctrl+R followed by D and the following line will be added at your cursor location:</p>
<p><span style="color: #993366;">if (Log.isDebug()) logger.debug(&#8220;&#8221;);</span></p>
<p>Enter the text between the double quotes, and if you’ll set the level of logging to Debug, this message will be sent to the specified destination selected with the Logging Manager as explained below.<br />
If you need to write a log message that will deliver fatal errors, press Ctrl+R, F , and you’ll see a new line in your code:</p>
<p><span style="color: #993366;">if (Log.isFatal()) logger.fatal(&#8220;&#8221;);</span></p>
<p>Just enter appropriate error information inside the quotes, and Log4Fx will send the information of this error to the selected log target.<br />
Here’s a code of the HelloWorld application with highlighted inserts from Log4Fx:</p>
<p>&lt;?xml version=&#8221;1.0&#8243; encoding=&#8221;UTF-8&#8243;?&gt;&lt;mx:Application xmlns:mx=&#8221;http://www.adobe.com/2006/mxml&#8221; layout=&#8221;absolute&#8221;&gt;<br />
&lt;mx:Grid&gt;<br />
&lt;mx:GridRow&gt;<br />
&lt;mx:GridItem&gt;<br />
&lt;mx:LinkButton label=&#8221;Hello world!&#8221;<br />
click=&#8221;logger.warn(&#8216;Warning&#8217;);&#8221;/&gt;<br />
&lt;/mx:GridItem&gt;<br />
&lt;/mx:GridRow&gt;<br />
&lt;mx:GridRow&gt;<br />
&lt;mx:GridItem&gt;<br />
&lt;mx:LinkButton label=&#8221;Hello world again!&#8221;<br />
click=&#8221;logger.info(&#8216;Info&#8217;);&#8221;/&gt;<br />
&lt;/mx:GridItem&gt;<br />
&lt;/mx:GridRow&gt;<br />
&lt;/mx:Grid&gt;<br />
&lt;mx:Script&gt;<br />
&lt;![CDATA[<br />
import mx.logging.Log;<br />
import mx.logging.ILogger;<br />
private var logger:ILogger = Log.getLogger("com.farata.samples");<br />
]]&gt;<br />
&lt;/mx:Script&gt;</p>
<p>&lt;Log4FlexLoggingTarget xmlns=&#8221;*&#8221;/&gt;<br />
&lt;/mx:Application&gt;</p>
<p>You still need to take care of two more items:</p>
<p>1. Define the destination of log messages by specifying the logging target.<br />
2. Using Logging Manager, define the properties for various logging categories, set the default logging level et al.</p>
<p><span style="font-weight: bold;">Using Logging Manager</span></p>
<p>The logging manager is a part of Log4Fx, and it allows you to change the logging settings on the fly while debugging the application is in progress. During the lifespan of the application, you may need to be able to redirect the log messages to a different target(s). This functionality is implemented in Logging Manager, which is a UI component that supports interactive control levels, categories, and targets. This is what you can do with the Logging Manager on the client side:<br />
• Automatically discover and list logging categories, and allow changing of the logging level for each logical category or a package.<br />
• List registered targets/destinations, and set default logging level and other common parameters.<br />
• Store the logging settings on the client&#8217;s computer.</p>
<p>To see this panel, start the application that uses Log4Fx and press CTRL+SHIFT+BACKSPACE – the  logging manager will pop-up on top of your application window. The following screenshot shows the logging manager panel on top of the HelloWorld application after the user pressed CTRL+SHIFT+BACKSPACE.</p>
<p><img src="http://res.sys-con.com/story/nov07/460527/fig2.JPG" alt="" width="1156" height="618" /></p>
<p>You can change the logging level at any time while your application is running. This feature is crucial for mission-critical production applications, where you can’t ask the user to stop the application (i.e. financial trading systems), but need to obtain the logging information to help the customer on the live system.<br />
Even if the user is not an IT professional, s/he can do this by following directions of the production support engineer.<br />
You can also change the default log level by selecting the required log level from the dropdown box. The destination (target) of your log messages can be selected from another dropdown as described in the section Working with Log targets.</p>
<p><span style="font-weight: bold;">WORKING WITH LOG TARGETS</span></p>
<p><strong>Trace</strong><br />
If you set the target Trace on the Logging Manager panel, all program messages will be output using the class from Flex framework called TraceTarget as if you&#8217;ve been using the function trace().</p>
<p><span style="font-weight: bold;">Socket</span><br />
Setting the target to Socket will engage SocketTarget class for logging your program messages via HTTP connection.</p>
<p><img src="http://res.sys-con.com/story/nov07/460527/fig3.JPG" alt="" width="426" height="80" /></p>
<p>If your Flex project was configured to work with Java Servlet container, i.e. Apache Tomcat, adding Log4Fx dependency files creates a small file on the server side log4flex.jar, which contains two Java classes – FlexLoggerServlet and ServerFlexLogger.  The file web.xml will be automatically modified to add a section that maps the requests that contain the url-pattern “logging” to FlexLoggerServlet.</p>
<p>You can also use this reference implementation if you decide to customize the logger to utilize non-Java Web servers, i.e. PHP or .Net.</p>
<p><span style="font-weight: bold;">Server</span><br />
This option can be used by applications that utilize Flex remoting via LiveCycle Data Services ES (LCDS), OpenAMF, or any other remoting transport. If you want to send the log output to the server, create a Java class that will support logging on the server side. Here&#8217;s the sample version of a class that uses popular Log4J component:</p>
<p><span style="color: #993366;">package com.theriabook.logging;</span><br style="color: #993366;" /><span style="color: #993366;">import org.apache.log4j.Logger;</span><br style="color: #993366;" /><span style="color: #993366;">import org.apache.log4j.Level;</span><br style="color: #993366;" /><br style="color: #993366;" /><span style="color: #993366;">public class ServerFlexLogger {</span><br style="color: #993366;" /><span style="color: #993366;"> </span><br style="color: #993366;" /><span style="color: #993366;"> static public void log(String levelStr, String message)</span><br style="color: #993366;" /><span style="color: #993366;"> {</span><br style="color: #993366;" /><span style="color: #993366;"> logger.log(Level.toLevel(levelStr), message);</span><br style="color: #993366;" /><span style="color: #993366;"> }</span><br style="color: #993366;" /><span style="color: #993366;"> static Logger logger; </span><br style="color: #993366;" /><span style="color: #993366;"> static </span><br style="color: #993366;" /><span style="color: #993366;"> {</span><br style="color: #993366;" /><span style="color: #993366;"> logger = Logger.getLogger(&#8220;MyFlexLogger&#8221;);</span><br style="color: #993366;" /><span style="color: #993366;"> logger.setLevel(Level.ALL);</span><br style="color: #993366;" /><span style="color: #993366;"> }</span><br style="color: #993366;" /><span style="color: #993366;">}</span><br style="color: #993366;" /><br />
In Logging Manager, as soon as you select Server as target, a text field will be shown where you need to enter the name of the server side destination that is mapped to the class com.theriabook.logging.ServerFlexLogger.</p>
<p>Now the log messages from your Flex programs will be sent to the server destination ServerFlexLogger and logged there. The section 5.4 shows an example of how such communication could have been programmed manually, but Log4Fx spares you from this. Just configure the Flex remoting destination and enter its name in the Destination field as shown above.</p>
<p><span style="font-weight: bold;">Local Panel</span></p>
<p>Flex developers who spend most of the time “inside” Eclipse IDE send the log output to the local panel, which is nothing else but yet another Eclipse View.<br />
Right-click on your Flex Project, select Log4Fx &gt; Show Workbench Viewer from the popup menu. You&#8217;ll see a new view panel in your Eclipse workbench:<br />
<img src="http://res.sys-con.com/story/nov07/460527/fig4.JPG" alt="" width="559" height="288" /></p>
<p>Select Local Panel as target, and now you can your log messages will be sent to a new Farata Logger View:</p>
<p><img src="http://res.sys-con.com/story/nov07/460527/fig5.JPG" alt="" width="628" height="297" /><br />
The push buttons on the toolbar allow you to turn on/off the output of debug, info, warning, fatal and error messages. You can also sort the messages by level, time, category, and message text.</p>
<p><span style="font-weight: bold;">XPanel<br />
</span><br />
The XPanel target allows to trace Flex/Flash applications interactively in a separate window. It also gives you native platform features like ability to save log to a file, keep the log window always on top and redirect the output to platform-specific debugging API. XPanel runs on Windows 95/98/Me, NT/2000/XP/Vista.  To configure output to the external XPanel, just right-click on your Flex Project, and select Log4Fx &gt; Show External Viewer from the popup menu. You’ll see an empty XPanel window will be displayed. Ensure that the target on the Logging Monitor is set to XPanel. Now your log messages will be streamed to an external XPanel window:<br />
<img src="http://res.sys-con.com/story/nov07/460527/fig6.JPG" alt="" width="530" height="250" /></p>
<p>XPanel&#8217;s toolbar provides quick access to Exit, Save Log, Start/Stop Logging, Clear Log, independent logging levels, Text/DataGrid Mode and “About” menu options.</p>
<p><span style="font-weight: bold;">Log4FlexLoggingTarget Explained<br />
</span><br />
When you first added the Log4Fx dependency files , the file Log4FlexLoggingTarget.mxml was automatically added to your application project. It allows setting default targets for Log4Fx. In this section we&#8217;ll discuss code of the Log4FlexLoggingTarget.mxml:</p>
<p>&lt;fx:LoggingTarget<br />
xmlns:fx=&#8221;http://www.faratasystems.com/2006/components&#8221;<br />
xmlns:mx=&#8221;http://www.adobe.com/2006/mxml&#8221;<br />
defaultLoggerLevel=&#8221;{LogEventLevel.INFO}&#8221;&gt;</p>
<p>&lt;mx:Script&gt;<br />
import mx.logging.LogEventLevel;<br />
&lt;/mx:Script&gt;</p>
<p>&lt;!&#8211; Setting default output to XPanel &#8211;&gt;<br />
&lt;fx:XPanelLogOutput<br />
fieldSeparator=&#8221; -&gt; &#8221; /&gt;<br />
&lt;!&#8211; Setting special popup window for filtering &#8211;&gt;<br />
&lt;fx:adjustmentManager&gt;<br />
&lt;fx:LoggingAdjustmentManager<br />
keyCode=&#8221;{Keyboard.BACKSPACE}&#8221;<br />
shiftKey=&#8221;true&#8221;<br />
ctrlKey=&#8221;true&#8221;&gt;<br />
&lt;mx:Array&gt;<br />
&lt;!&#8211; List of available outputs (with their own settings) &#8211;&gt;<br />
&lt;fx:XPanelOutputDescription /&gt;<br />
&lt;fx:TraceOutputDescription<br />
fieldSeparator=&#8221; -&gt; &#8221;<br />
includeCategory=&#8221;true&#8221;<br />
includeDate=&#8221;true&#8221;<br />
includeLevel=&#8221;true&#8221;<br />
includeTime=&#8221;true&#8221; /&gt;<br />
&lt;fx:SocketOutputDescription /&gt;<br />
&lt;fx:ServerOutputDescription/&gt;<br />
&lt;fx:LocalConnectionOutputDescription/&gt;<br />
&lt;fx:RemoteOutputDescription/&gt;<br />
&lt;/mx:Array&gt;<br />
&lt;/fx:LoggingAdjustmentManager&gt;<br />
&lt;/fx:adjustmentManager&gt;<br />
&lt;/fx:LoggingTarget&gt;<br />
This code performs the following actions:<br />
1. Set the default logger level. You can change it by modifying the value of the property defaultLoggerLevel, which has a default value of LogEventLevel.INFO, and we’ve included this code for illustration purposes.<br />
2. Set the destination of the default output of the logger. By default, the log info goes to XPanel. You can change the default value either by assigning appropriate value to XPanelLogOutput, (for example, LocalConnectionOutput) or by using Logging Manager. You can also specify additional parameters for targets, for example, fieldSeparator, which denotes the field delimiter to be used in log files. All available parameters are listed in Eclipse Help (see, com.theriabook.util.XPanelTarget or other targets). The next section of this document describes how to set such parameters.<br />
3. You can redefine the hot keys that bring up the Logging Settings panel by changing the values of the properties keyCode, shiftKey and/or ctrlKey. For example, if you use the combination keyCode=“{Keyboard.ESCAPE}”, ctrlKey=&#8221;false&#8221; and shiftKey=&#8221;true&#8221; in the code, pressing SHIFT + ESC will open the Logging Monitor window. If none of these properties are set, you can open the Logging Monitor by pressing F12.<br />
4. In the code section “List of available outputs” you can change the list of available logging targets in the Logging Manager panel. By default, it shows XPanelOutput, TraceOutput, SocketOutput, ServerOutput, LocalConnectionOutput ? RemoteOutput, which were described above. If you do not need all targets, remove some of the available outputs from Log4FlexLoggingTarget.mxml.<br />
You can set the default logging level is defined in the file Log4FlexLoggingTarget.mxml and in the Logging Manager panel. The latter has higher priority over the settings specified in Log4FlexLoggingTarget.mxml. For example, after adding Log4Fx to your project, you can specify LogEventLevel.WARN as the default logger level that will take effect on the application startup. But if you change this level to ERROR using the Logging Manager panel, it’ll remember the ERROR level till the next start of your application despite the fact that the file Log4FlexLoggingTarget.mxml still has the WARN level. To remove all logger settings made from the panel, press the button Clear Local Storage on the Logging Manager panel. After that, the settings from the file Log4FlexLoggingTarget.mxml will be in effect again.</p>
<p><span style="font-weight: bold;">Remote Logging<br />
</span><br />
Adding dependency file described above created a new application in your project – RemoteLogReceiver.mxml, which can be used by a remote production support crew.<br />
Let’s say the user’s application is deployed at the following URL:</p>
<p>http://230.123.12.10:8080/myapplication.html</p>
<p>By pressing the CTRL-SHIFT-BACKSPACE, the user brings the Logging Manager and selects the target Remote Logging.<br />
<img src="http://res.sys-con.com/story/nov07/460527/fig7.JPG" alt="" width="592" height="80" /></p>
<p>The destination RemoteLogging is selected automatically, and the user needs to input a password, which he will share with the production support engineer.<br />
Since the RemoteLogReceiver.mxml is also an application that is sitting right next to your main application in Flex Builder’s project, it’ll also will get compiled into an SWF file, the html wrapper will be generated too, and it will be deployed in the Web server of your choice too. The end users will never use it, and they won’t even know that it exists. But production engineer can enter its URL in his browser when needed:</p>
<p>http://230.123.12.10:8080/RemoteLogReceiver.html</p>
<p>Think of an undercover informant who just lives in the neighborhood, but when engaged, it immediately starts sending the information out.<br />
After entering the password provided by the user and pressing the button Connect, he’ll start receiving Log messages sent by the user’s application.</p>
<p><img src="http://res.sys-con.com/story/nov07/460527/fig8.JPG" alt="" width="820" height="507" /></p>
<p>The buttons on the toolbar allow selective output of log messages – it works the same way as with XPanel.</p>
]]></content:encoded>
			<wfw:commentRss>http://flexblog.faratasystems.com/2007/11/13/boost-productivity-of-your-flex-java-project-with-log4fx-component/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Do not miss tomorrows Webcast on Flex, Silverlight and JavaFX</title>
		<link>http://flexblog.faratasystems.com/2007/06/03/do-not-miss-tomorrows-webcast-on-flex-silverlight-and-javafx</link>
		<comments>http://flexblog.faratasystems.com/2007/06/03/do-not-miss-tomorrows-webcast-on-flex-silverlight-and-javafx#comments</comments>
		<pubDate>Sun, 03 Jun 2007 12:23:56 +0000</pubDate>
		<dc:creator>Victor Rasputnis</dc:creator>
				<category><![CDATA[ActionScript]]></category>
		<category><![CDATA[Ajax]]></category>
		<category><![CDATA[Flex]]></category>
		<category><![CDATA[Flex 2]]></category>
		<category><![CDATA[Flex Consulting]]></category>
		<category><![CDATA[Java]]></category>
		<category><![CDATA[Silverlight]]></category>
		<category><![CDATA[Web 2.0]]></category>
		<category><![CDATA[ria]]></category>
		<category><![CDATA[web+reporting]]></category>
		<category><![CDATA[wpf]]></category>

		<guid isPermaLink="false">http://flexblog.faratasystems.com/?p=204</guid>
		<description><![CDATA[Do not miss tomorrow&#8217;s live TV show from Times Square on Rich Internet Appilcations. SYS-CON.TV&#8217;s will webcast an hour-long &#8220;RIA Shoot-Out&#8221; covering major Rich Internet Application (RIA) technologies.
Farata&#8217;s own Yakov Fain will participate in this discussion. If your firm is considering various tools and techniques for development of your next RIA, this show will definitely [...]]]></description>
			<content:encoded><![CDATA[<p>Do not miss tomorrow&#8217;s live TV show from Times Square on Rich Internet Appilcations. SYS-CON.TV&#8217;s will webcast an hour-long &#8220;RIA Shoot-Out&#8221; covering major Rich Internet Application (RIA) technologies.</p>
<p>Farata&#8217;s own Yakov Fain will participate in this discussion. If your firm is considering various tools and techniques for development of your next RIA, this show will definitely help you with making the right decision. This show will feature an interactive Q&#038;A session from viewers during its final segment.</p>
<p>This free event will start at 1PM EST, and you can register at <a href="http://web2.sys-con.com/read/375328.htm">http://web2.sys-con.com/read/375328.htm</a></p>
<p>Enjoy the show,<br />
Victor</p>
<p>Update: The short (edited) version of the podcast is available at <a href="http://tv.sys-con.com/read/385147.htm">http://tv.sys-con.com/read/385147.htm</a></p>
]]></content:encoded>
			<wfw:commentRss>http://flexblog.faratasystems.com/2007/06/03/do-not-miss-tomorrows-webcast-on-flex-silverlight-and-javafx/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Stubborn Flash Player Context Menu: Business or Technology Issue?</title>
		<link>http://flexblog.faratasystems.com/2007/03/16/stubborn-flash-player-context-menu-business-or-technology-issue</link>
		<comments>http://flexblog.faratasystems.com/2007/03/16/stubborn-flash-player-context-menu-business-or-technology-issue#comments</comments>
		<pubDate>Fri, 16 Mar 2007 17:14:19 +0000</pubDate>
		<dc:creator>Victor Rasputnis</dc:creator>
				<category><![CDATA[Flex]]></category>

		<guid isPermaLink="false">http://flexblog.faratasystems.com/?p=177</guid>
		<description><![CDATA[This is what came to my e-mail: &#8220;We are researching ways to move from Swing GUI to browser GUI for some networked applications&#8230;  As you know, the ContextMenu
hideBuiltInItems property doesn&#8217;t turn all of the Flash menu items off&#8230;The bottom line: if we can&#8217;t hide all of the menu items, we can&#8217;t use Flex as [...]]]></description>
			<content:encoded><![CDATA[<p>This is what came to my e-mail: &#8220;We are researching ways to move from Swing GUI to browser GUI for some networked applications&#8230;  As you know, the ContextMenu<br />
hideBuiltInItems property doesn&#8217;t turn all of the Flash menu items off&#8230;The bottom line: if we can&#8217;t hide all of the menu items, we can&#8217;t use Flex as our solution.  This would be a very sad decision, because Flex is an otherwise terrific tool.&#8221;</p>
<p>A very typical approach.</p>
<p>First of all, Adobe engineers have elaborated enough on the subject, the latest and very detailed answer being provide by Kevin Hoyt in this link <a href="http://weblogs.macromedia.com/khoyt/archives/2007/01/context_menus_r.cfm">http://weblogs.macromedia.com/khoyt/archives/2007/01/context_menus_r.cfm</a>. Add items, remove items, globally or per object, but you won’t be able to get rid of the two &#8211; About  and Settings&#8230; &#8211; in Flash Player Virtual Machine as you won’t be able to get rid of the brakes in your car. Buy it with the brakes or don’t drive until Apollo arrives. Period.</p>
<p>But let’s look at the bigger issue. There is a legacy client/server application that for a _business reasons_ needs to be ported to the net. Having spent almost 6 years in Client/Server to Ajax/J2EE conversion projects, I observed that setting the expectations right is the key here: move from Swing or any C/S to browser GUI &#8211; changing a technology platform &#8211; results in a redesign and re-architecture. I would certainly pose the following row of question:</p>
<p>During the re-design, which features of the original system, including, but not limited to UI should be retained? Which features should go? Which features should be added?</p>
<p>I am not even relating to the fact that if we were to disable Settings… we could forfeit ability to save application data to the local storage. In the intranet scenario we can, theoretically, assume that Flash Player settings are correct to begin with. It is obvious anyway, that Flex allows much friendlier and less-clicky UI then the one centered around context menus. No need to wait for the user to right-click and _discover_ the choices, we could have proactively display them as soon as the user moves over the object. Besides UI, lots of things change when you move from 2 tiers to 3. You can not map them one to one, so the ContextMenu might be the least of your worries.</p>
<p>Re-training costs? Sure. Not to mention that you’d have to justify the very cost of the port. But if the _business goal_ it to increasing the user base/revenue, you would not have to concentrate on the ContextMenu. Technology is not the problem here, it&#8217;s a business issue.</p>
<p>I am not saying that there is no way that  ContextMenu can be possibly hidden and overlapped with your own, especially in the Intranet. My point is that it might not be even worth it.</p>
<p>Victor</p>
]]></content:encoded>
			<wfw:commentRss>http://flexblog.faratasystems.com/2007/03/16/stubborn-flash-player-context-menu-business-or-technology-issue/feed</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
		<item>
		<title>How Fast is Development in Flex?</title>
		<link>http://flexblog.faratasystems.com/2007/02/20/how-fast-is-development-in-flex</link>
		<comments>http://flexblog.faratasystems.com/2007/02/20/how-fast-is-development-in-flex#comments</comments>
		<pubDate>Wed, 21 Feb 2007 03:58:19 +0000</pubDate>
		<dc:creator>Victor Rasputnis</dc:creator>
				<category><![CDATA[ActionScript]]></category>
		<category><![CDATA[Flex]]></category>
		<category><![CDATA[Flex 2]]></category>
		<category><![CDATA[Flex Builder]]></category>
		<category><![CDATA[Flex book]]></category>
		<category><![CDATA[ria]]></category>

		<guid isPermaLink="false">http://flexblog.faratasystems.com/?p=165</guid>
		<description><![CDATA[How Fast is Development in Flex?
Ask me what is the easiest way to build RIA apps and you do not have to wait for the answer: it&#8217;s Flex, of course. Ask me is it fast to develop in Flex and I will say &#8220;it depends&#8221;.
First, it depends where are you coming from. Literally. I&#8217;ve seen enough places where [...]]]></description>
			<content:encoded><![CDATA[<p>How Fast is Development in Flex?</p>
<p>Ask me what is the easiest way to build RIA apps and you do not have to wait for the answer: it&#8217;s Flex, of course. Ask me is it fast to develop in Flex and I will say &#8220;it depends&#8221;.</p>
<p>First, it depends where are you coming from. Literally. I&#8217;ve seen enough places where Struts/HTML is the only known UI technology. Meanwhile the business is running a huge VB app that changed hands 6 times before last developer left during the .com days.  Now everyone wants it on the Web, but expectations of the development complexity are distorted by the culture of straw houses.</p>
<p>&#8220;Nevermind that legacy Client/Server system took 10 man years to build. We have never done Struts/HTML app in more then 6 months and Flex is a &#8220;better HTML&#8221; so it should take 3 months in Flex, should it not?&#8221;</p>
<p>This rhetorical question brings me to the second point.</p>
<p>What is simple and straightforward in Flex, has been often out of the question, unthinkable in Web 1.0 applications. The paradox, that I call the &#8220;Home Depot Effect&#8221;, is that once the threshold of &#8220;possible&#8221; has changed, you want it all. It is <em>easy</em> to put the tiles, it is <em>easy </em>to do the lights, it is <em>easy </em>to build the patio, etc. Does it mean you are going to rebuild that old house in the same time you used to paint your Struts/HTML appartment?</p>
<p>Now you know what I meant by &#8220;it depends&#8221;.</p>
<p>Victor</p>
]]></content:encoded>
			<wfw:commentRss>http://flexblog.faratasystems.com/2007/02/20/how-fast-is-development-in-flex/feed</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>When Size Matters</title>
		<link>http://flexblog.faratasystems.com/2007/02/13/when-size-matters</link>
		<comments>http://flexblog.faratasystems.com/2007/02/13/when-size-matters#comments</comments>
		<pubDate>Tue, 13 Feb 2007 17:12:58 +0000</pubDate>
		<dc:creator>Victor Rasputnis</dc:creator>
				<category><![CDATA[Flex]]></category>

		<guid isPermaLink="false">http://flexblog.faratasystems.com/?p=162</guid>
		<description><![CDATA[Modules or RSLs, whatever way you partition your Flex system, if you are delivering it over the public web you want to keep the size as small as possible. What are the best options?
Flex compilers support -link-report option. It let&#8217;s you produce a file of the linker dependencies found during the build of your SWF. [...]]]></description>
			<content:encoded><![CDATA[<p>Modules or RSLs, whatever way you partition your Flex system, if you are delivering it over the public web you want to keep the size as small as possible. What are the best options?</p>
<p>Flex compilers support <em>-link-report</em> option. It let&#8217;s you produce a file of the linker dependencies found during the build of your SWF. Then there is a matching <em>-load-externs</em> option that let you specify the classes you do not want to link, but rather prefer to extern. Conveniently, <em>-load-externs</em> anticipates the input to be in exactly the same XML format as is produced by <em>-link-report</em>.</p>
<p>Speaking of modules and applications &#8211; just as an example case &#8211; this pair of options enables you to <em>extern</em> for the module everything, that will be loaded by the application. You build your application producing <em>-link-report</em>, then apply it for the module (see Flex docs for exact details). However, if you plan to ever reuse the same module for the different hosting application, this technique is not applicable. You&#8217;d need to rebuild the module.</p>
<p>There is an opposite way of  using <em>-link-report</em> option. If you use compiler’s option <em>–include</em> you can have application <em>merge-in</em> all classes required by your libraries .</p>
<p>In this scenario, you run <em>-link-report</em> on the module and instead of optimizing the module, you optimize the application. No need to rebuild your modules to satisfy every individual application – they stay 100% reusable. Instead you tune your applications.</p>
<p>And, speaking of size, do not forget the <em>-debug</em> option. By turning it to false you may strip up to 30% of size taken by debugging information. By the same token, you may want to recompile framework.swf from Adobe Flex Framework source files to take it’s size down in the first place, prior to resorting to <em>–include</em>.</p>
<p>Keep it small.</p>
<p>Victor</p>
]]></content:encoded>
			<wfw:commentRss>http://flexblog.faratasystems.com/2007/02/13/when-size-matters/feed</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Prompting User on Close of Application: Flex Way</title>
		<link>http://flexblog.faratasystems.com/2006/12/17/prompting-user-on-close-of-application-flex-way</link>
		<comments>http://flexblog.faratasystems.com/2006/12/17/prompting-user-on-close-of-application-flex-way#comments</comments>
		<pubDate>Sun, 17 Dec 2006 06:14:26 +0000</pubDate>
		<dc:creator>Victor Rasputnis</dc:creator>
				<category><![CDATA[Flex]]></category>

		<guid isPermaLink="false">http://flexblog.faratasystems.com/?p=134</guid>
		<description><![CDATA[WM_CLOSE, windowClosing, closeQuery&#8230; Which one is closer to your heart? One way or the other you
have to give your user that last chance to save modified data when he or she is closing the application
window. Providing the same functionality in Flex requires help on the JavaScript/HTML side, so this post
will illustrate two techniques in one [...]]]></description>
			<content:encoded><![CDATA[<p>WM_CLOSE, windowClosing, closeQuery&#8230; Which one is closer to your heart? One way or the other you<br />
have to give your user that last chance to save modified data when he or she is closing the application<br />
window. Providing the same functionality in Flex requires help on the JavaScript/HTML side, so this post<br />
will illustrate two techniques in one example.</p>
<p>Preventing the user from closing the browser window has been traditionally done via onbeforeunload event.<br />
Here is the snippet of JavaScript code, which, once you put it in<br />
<em>./html-template/index.template.html</em> will (IE &#038; Mozilla)</p>
<ol>
<li>resolve reference to Flash control;</li>
<li>tentatively invoke ActionScript method getUnsavedDataWarning() ;</li>
<li>force browser to popup the alert &#8220;Are you sure you want to navigate away? &#8230;.. OK/Cancel&#8221;; with your custom text in the middle:</li>
</ol>
<p>&lt;!&#8211; index.template.html &#8211;><br />
.  .  .  .  .<br />
&lt;script language=&#8221;JavaScript&#8221; type=&#8221;text/javascript&#8221;><br />
&lt;!&#8211;<br />
// Give user a chance to save modified data<br />
window.onbeforeunload = function() {<br />
var warning=&#8221;";<br />
var fxControl = document.${application} || window.${application};<br />
if (typeof fxControl.getUnsavedDataWarning==&#8221;function&#8221;) {<br />
warning = fxControl.getUnsavedDataWarning();<br />
}<br />
if (warning!=&#8221;)<br />
return warning;<br />
else<br />
return;<br />
}<br />
// &#8211;><br />
&lt;/script><br />
Now, all of this is in vain, of course, if your Flex application does not advertise the method<br />
getUnsavedDataWarning(). And here is where Flash ExternalInterface API comes very handy. You can<br />
expose any method: static, instance or anonymous, like the one below:</p>
<p><em>import flash.external.ExternalInterface;</em></p>
<p><em>  private const UNSAVED_DATA_WARNING:String = &#8216;You have unsaved changes. You will lose them if you continue.&#8217;;</em></p>
<p>if ( ExternalInterface.available ) {<br />
ExternalInterface.addCallback(<br />
&#8220;getUnsavedDataWarning&#8221;,<br />
function():String {<br />
if (commitRequired) return UNSAVED_DATA_WARNING;<br />
else return &#8221;;<br />
}<br />
);<br />
}</p>
<p>The complete MXML application is listed below. Do not forget to paste the JavaScript stuff in ./html-template/index.template.html:</p>
<p>&lt;?xml version=&#8221;1.0&#8243; encoding=&#8221;utf-8&#8243;?><br />
&lt;mx:Application xmlns:mx=&#8221;http://www.adobe.com/2006/mxml&#8221;<br />
layout=&#8221;vertical&#8221; creationComplete=&#8221;onCreationComplete()&#8221;><br />
&lt;mx:Script>&lt;![CDATA[</p>
<p>import flash.external.ExternalInterface;<br />
private const UNSAVED_DATA_WARNING:String = 'You have unsaved changes. You will lose them if you continue.';<br />
[Bindable] private var commitRequired:Boolean;</p>
<p>private function onCreationComplete():void {<br />
if ( ExternalInterface.available ) {<br />
ExternalInterface.addCallback(<br />
&#8220;getUnsavedDataWarning&#8221;,<br />
function():String {<br />
if (commitRequired) return UNSAVED_DATA_WARNING;<br />
else return &#8221;;<br />
}<br />
);<br />
}<br />
}<br />
]]&gt;&lt;/mx:Script><br />
&lt;mx:Text  text=&#8221;Type something below to test&#8221;  /><br />
&lt;mx:TextInput id=&#8221;input&#8221;   change=&#8221;commitRequired=(input.text!=&#8221;)&#8221;/><br />
&lt;mx:Text text=&#8221;Close window and you will{commitRequired?&#8217; &#8216;:&#8217; not&#8217;} be prompted&#8221; /></p>
<p>&lt;/mx:Application></p>
<p>WM_CLOSE, windowClosing, closeQuery, onbeforeunload&#8230; Tell me who your friends are &#8230; ;   )</p>
<p>Victor</p>
]]></content:encoded>
			<wfw:commentRss>http://flexblog.faratasystems.com/2006/12/17/prompting-user-on-close-of-application-flex-way/feed</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Extending Flex Framework: Value-Aware ComboBox</title>
		<link>http://flexblog.faratasystems.com/2006/12/12/extending-flex-framework-value-aware-combobox</link>
		<comments>http://flexblog.faratasystems.com/2006/12/12/extending-flex-framework-value-aware-combobox#comments</comments>
		<pubDate>Tue, 12 Dec 2006 23:40:30 +0000</pubDate>
		<dc:creator>Victor Rasputnis</dc:creator>
				<category><![CDATA[Flex]]></category>
		<category><![CDATA[Flex 2]]></category>

		<guid isPermaLink="false">http://flexblog.faratasystems.com/?p=132</guid>
		<description><![CDATA[What I love about Flex is that it is a framework. On top of library of the off-the-shelf controls   which fits the bill for many of the Rich Internet Applications needs, Flex enables you to create new   or extend existing components with a simplicity and elegance hardly ever offered by other [...]]]></description>
			<content:encoded><![CDATA[<p>What I love about Flex is that it is a framework. On top of library of the off-the-shelf controls   which fits the bill for many of the Rich Internet Applications needs, Flex enables you to create new   or extend existing components with a simplicity and elegance hardly ever offered by other GUI   development systems. Here is an illustration of extending standard ComboBox component.How do you programmatically select a specific value in a ComboBox? Suppose the ComboBox is   populated with array of states:</p>
<p><em>private var usStates:Array=[<br />
&nbsp;&nbsp;&nbsp;&nbsp;{label:"New York", data:"NY"},<br />
&nbsp;&nbsp;&nbsp;&nbsp;{Colorado", data:"CO"},<br />
&nbsp;&nbsp;&nbsp;&nbsp;{Texas", data:"TX"}<br />
];<br />
.   .   .   .   .   .   .   .<br />
&nbsp;&nbsp;&nbsp;&lt;mx:ComboBox id=&#8221;cbx_states&#8221; dataProvider=&#8221;{usStates}&#8221;/></em>To force Texas to the visible portion of the ComboBox you can write the following index-fetching   loop, comparing val against the <em>label</em> of each element of <em>dataProvider</em>:</p>
<p><em>var val:String; val= ’Texas’ ;<br />
for (var i: int = 0; i < cbx.dataProdider.length; i++) {<br />
&nbsp;&nbsp;&nbsp;&nbsp;if ( val == cbx_states.dataProvider[i].label) {<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;cbx_states.selectedIndex = i;<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;break;<br />
&nbsp;&nbsp;}<br />
}<br />
</em><br />
Alternatively, you could look up the data of dataProvider’s elements :<br />
<em>var val:String;  val= &#8216;TX&#8217;  ;<br />
for (var i: int = 0; i &lt; cbx.dataProdider.length; i++) {<br />
&nbsp;&nbsp;&nbsp;&nbsp;if ( val == cbx.dataProvider[i].data) {<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;cbx_states.selectedIndex = i;<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;break;<br />
&nbsp;&nbsp;&nbsp;&nbsp;}<br />
}</p>
<p></em> Either way these index-fetching loops will clutter the application code instead of simple   <em>cbx_states.value=‘Texas’</em>. But wait, there is <em>value</em> property:  if a selected object has   something in the <em>data</em> property, value refers to  <em>data</em>, otherwise value refers to the   <em>label</em>:<em>mx.control.Alert.show(cbx_states.value); // displays &#8216;NY&#8217;</em></p>
<p>Alas, standard value is read-only. In the following part of the post we will turn value into a   read-write property. Then index-fetching loops to modify the ComboBox selection will be history.</p>
<p>Let&#8217;s extend the original ComboBox so that derived class provides a special setter for the   value property. The setter attempts to match the value with either data or label properties of the   dataProvider. Once a match is found, it modifies the <em>selectedIndex</em>, which should cause the   ComboBox to select the matching object:</p>
<p><em>&lt;?xml version=&#8221;1.0&#8243; encoding=&#8221;utf-8?><br />
&lt;mx:ComboBox xmlns:mx=&#8221;http://www.adobe.com/2006/mxml&#8221; ><br />
&lt;mx:Script><br />
&lt;![CDATA[<br />
&nbsp;&nbsp;&nbsp;public function set value(val:Object)  : void {<br />
&nbsp;&nbsp;&nbsp;       if ( val != null ) {<br />
&nbsp;&nbsp;&nbsp;           for (var i : int = 0; i &lt; dataProvider.length; i++) {<br />
&nbsp;&nbsp;&nbsp;               if ( val == dataProvider[i].data || val == dataProvider[i].label)   {<br />
&nbsp;&nbsp;&nbsp;                   selectedIndex = i;<br />
&nbsp;&nbsp;&nbsp;                   return;<br />
&nbsp;&nbsp;&nbsp;       }    }    }<br />
&nbsp;&nbsp;&nbsp;       selectedIndex = -1;<br />
&nbsp;&nbsp;&nbsp;   }<br />
&nbsp;]]&gt;<br />
&lt;mx:Script><br />
&lt;mx:ComboBox></p>
<p></em> Listing 1. ComboBox.mxml &#8211; Making the value property writeable</p>
<p>If the ComboBox.mxml is located under the com/theriabook/controls, its test application can look   as in  Listing 2 below.</p>
<p><em>&lt;?xml version=&#8221;1.0&#8243; encoding=&#8221;utf-8&#8243;?><br />
&lt;mx:Application xmlns:mx=&#8221;http://www.adobe.com/2006/mxml&#8221;   xmlns:fx=&#8221;com.theriabook.controls.*&#8221;><br />
&nbsp;&nbsp;&nbsp;&lt;mx:ArrayCollection id=&#8221;comboData&#8221;><br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&lt;mx:Array><br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&lt;mx:Object label=&#8221;New York&#8221;   data=&#8221;NY&#8221;/><br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&lt;mx:Object   label=&#8221;Connecticut&#8221; data=&#8221;CT&#8221;/><br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&lt;mx:Object label=&#8221;Illinois&#8221;   data=&#8221;IL&#8221;/><br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&lt;/mx:Array><br />
&nbsp;&nbsp;&nbsp;&lt;/mx:ArrayCollection><br />
&nbsp;&nbsp;&nbsp;&lt;mx:Label text=&#8221;Current bound value is &#8216;{cbx_1.value}&#8217; &#8221; /><br />
&nbsp;&nbsp;&nbsp;&lt;fx:ComboBox id=&#8221;cbx_1&#8243; value=&#8221;IL&#8221; width=&#8221;150&#8243; dataProvider=&#8221;{comboData}&#8221;/><br />
&lt;mx:Application><br />
</em></p>
<p>Listing 2. Using our new ComboBox</p>
<p>Run this  application,  and you’ll see the ComboBox displaying the value New York… while we  would   expect Illinois. We forgot about the order in which objects’ properties (cbx_1) get initialized. In   particular, the  value property is initialized before the dataProvider. And, since during   dataProvider initialization ComboBox, by default, selects the first item, the work performed by our   value setter is wasted. You can prove the point by just trading places of value and dataProvider in   the above application code.</p>
<p>Should I rely on the order of attributes in MXML components? Apparently not. Especially when Flex   offers an excellent mechanism to coordinate the updates to multiple properties of the control – the   <em>commitProperties()</em> method.</p>
<p>Here is how it works: whenever you need to modify a property raise some indicator, store the value   in the temporary variable and call invalidateProperties(), like in the following snippet:</p>
<p><em>&nbsp;private var candidateValue:Object;<br />
&nbsp;private var valueDirty:Boolean = false;</em><em>&nbsp;public function set value(val:Object)  : void {<br />
&nbsp;&nbsp;&nbsp;candidateValue = val;<br />
&nbsp;&nbsp;&nbsp;valueDirty = true;<br />
&nbsp;&nbsp;&nbsp;<strong>invalidateProperties()</strong>;<br />
&nbsp;&nbsp;&nbsp;}</p>
<p></em> In response to <em>invalidateProperties()</em> Flex will guarantee a call of <em>commitProperties()</em>   at a later time,  so that all property changes deferred in the above manner can be consolidated in a   single place and in the pre-determined order:</p>
<p><em>override protected function commitProperties():void {<br />
&nbsp;&nbsp;&nbsp;&nbsp;super.commitProperties();&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;if (dataProviderDirty)    {<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;super.dataProvider = candidateDataProvider;<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;dataProviderDirty = false;<br />
&nbsp;&nbsp;&nbsp;}</p>
<p>&nbsp;&nbsp;&nbsp;if (valueDirty) {<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;applyValue(candidateValue);<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;valueDirty = false;<br />
&nbsp;&nbsp;&nbsp;}<br />
}</p>
<p></em>Aside of co-ordinating updates to different properties, this coding pattern helps to avoid   multiple updates to the same property and, in general, allows setter methods to return faster,   improving the overall performance of the control. The entire code of our “value-aware” ComboBox is   presented in Listing 3:</p>
<p><em>&lt;?xml version=&#8221;1.0&#8243; encoding=&#8221;utf-8&#8243;?><br />
&lt;mx:ComboBox xmlns:mx=&#8221;http://www.adobe.com/2006/mxml&#8221;><br />
&lt;mx:Script><br />
&lt;![DATA[</p>
<p>&nbsp;&nbsp;&nbsp;private var candidateValue:Object;<br />
&nbsp;&nbsp;&nbsp;private var valueDirty:Boolean = false;<br />
&nbsp;&nbsp;&nbsp;private var candidateDataProvider:Object;<br />
&nbsp;&nbsp;&nbsp;private var dataProviderDirty:Boolean = false;<br />
&nbsp;&nbsp;&nbsp;<br />
&nbsp;&nbsp;&nbsp;private function applyValue(val:Object):void {<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; if ((val != null) &#038;&#038; (dataProvider != null)) {<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;  for (var i : int = 0; i &lt;   dataProvider.length; i++) {<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;if ( val ==   dataProvider[i].data || val == dataProvider[i].label) {<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;   ;&nbsp; selectedIndex = i;<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;   ;&nbsp; return;<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; }&nbsp;&nbsp;&nbsp; }&nbsp;&nbsp;&nbsp; }<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; selectedIndex = -1;<br />
&nbsp;&nbsp;&nbsp;}&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;public function set value(val:Object)  : void {<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; candidateValue = val;<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; valueDirty = true;<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; invalidateProperties();<br />
&nbsp;&nbsp;&nbsp;}<br />
&nbsp;&nbsp;&nbsp;override public function set dataProvider(value:Object):void {<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; candidateDataProvider = value;<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; dataProviderDirty = true;<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; invalidateProperties();<br />
&nbsp;&nbsp;&nbsp;}</p>
<p>&nbsp;&nbsp;&nbsp;override protected function commitProperties():void {<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; super.commitProperties();</p>
<p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; if (dataProviderDirty)    {<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;  super.dataProvider =   candidateDataProvider;<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;  dataProviderDirty = false;<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; }</p>
<p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; if (valueDirty) {<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;  applyValue(candidateValue);<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;  valueDirty = false;<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; }<br />
&nbsp;&nbsp;&nbsp;}<br />
&nbsp;&nbsp;&nbsp;]]&gt;<br />
&lt;mx:Script><br />
&lt;mx:ComboBox></p>
<p></em>Listing 3. The value-aware ComboBox</p>
<p>Now everything works as expected.  If you change the ComboBox selection, the top label, which   initially contains Current bound value is “IL” will change accordingly. No miracles here, a regular   Flex data binding one would say. Indeed, good things are easy to take for granted. Still, we have not   provided any binding declarations or binding code in our ComboBox. So why does it work? It works   because the original Flex definition of value getter ComboBox has already been marked with metadata   tag [“Bindable”], which makes the property bindable (you do not have to have a setter to be   bindable):</p>
<p><em>[Bindable("change")]<br />
[Bindable("valueCommitted")]<br />
</em><br />
But wait, you may say, these binding definitions contract us to trigger events change and   valueCommitted. Yet our value setter does not contain a single  dispatchEvent call. Where is the   catch? Events are dispatched inside the code that assigns  selectedIndex. This assignment results in   invocation of selectedIndex setter, which ultimately dispatches events.</p>
<p>Remember, Flex is a framework.Read the code <img src='http://flexblog.faratasystems.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
<p>Victor</p>
]]></content:encoded>
			<wfw:commentRss>http://flexblog.faratasystems.com/2006/12/12/extending-flex-framework-value-aware-combobox/feed</wfw:commentRss>
		<slash:comments>7</slash:comments>
		</item>
		<item>
		<title>Another Praise to ActionScript &#8220;as&#8221; Casting</title>
		<link>http://flexblog.faratasystems.com/2006/12/06/another-praise-to-actionscript-as-casting</link>
		<comments>http://flexblog.faratasystems.com/2006/12/06/another-praise-to-actionscript-as-casting#comments</comments>
		<pubDate>Wed, 06 Dec 2006 06:19:35 +0000</pubDate>
		<dc:creator>Victor Rasputnis</dc:creator>
				<category><![CDATA[Flex]]></category>

		<guid isPermaLink="false">http://flexblog.faratasystems.com/?p=127</guid>
		<description><![CDATA[I had been working on DataGrid that displays heterogenous data: any two rows may share all or just some of the properties, so the DataGrid appears sparse. Then during  &#8220;protecting&#8221; non-editable items per specific row this casting example popped up.
The easiest way to row-by-row disable editing is via itemEditBeginning event:
 mx:DataGrid itemBeginning=&#8221;onItemEditBeginning(event)&#8221; &#8230;
 public function onItemEditBeginning(event:DataGridEvent):void {
  if [...]]]></description>
			<content:encoded><![CDATA[<p>I had been working on DataGrid that displays heterogenous data: any two rows may share all or just some of the properties, so the DataGrid appears sparse. Then during  &#8220;protecting&#8221; non-editable items per specific row this casting example popped up.</p>
<p>The easiest way to row-by-row disable editing is via itemEditBeginning event:</p>
<p><em> mx:DataGrid itemBeginning=&#8221;onItemEditBeginning(event)&#8221; &#8230;</em></p>
<p><em> public function onItemEditBeginning(event:DataGridEvent):void {<br />
  if (event.itemRenderer) {<br />
  // do something to determine whether item is editable, preventDefault otherwise<br />
 }<br />
}</em></p>
<p>Now let&#8217;s fantasize that items populating your dataProvider might be implementing IEditableItem, which mandates method isFieldEditable():</p>
<p><em> function isFieldEditable(dataField:String):Boolean;</em></p>
<p>Then you can write something like</p>
<p>Variant1:<br />
<em> var item:Object = event.itemRenderer.data ;<br />
 if (item is IEditableItem) {<br />
  if (!item.isFieldEditable(dataField)) {<br />
   event.preventDefault();<br />
  }<br />
 }</em></p>
<p>OR &#8211; Variant2:<br />
<em> var item:Object = event.itemRenderer.data ;<br />
  if (item is IEditableItem) {<br />
    if (!IEditableItem(item).isFieldEditable(dataField)) {<br />
     event.preventDefault();<br />
    }<br />
  }</em></p>
<p>OR &#8211; Variant3:<br />
<em> var item:IEditableItem = event.itemRenderer.data as IEditableItem;<br />
 if (item) {<br />
  if (!item.isFieldEditable(dataField)) {<br />
     event.preventDefault();<br />
  }<br />
 }</em><br />
Variant1 looks simple, but may cost you some sleep when another developer redefines IEditableItem, which won&#8217;t be discovered during compilation. Variant2 applies regular casting to take care of that potential re-factoring and &#8230; gets annoying with IEditableItem/IEditableItem. Variant 3 combines clarity of 1 with reliability of 3: when item is not IEditableItem &#8220;as&#8221; casting returns null, otherwise we are already strongly typed.<em> </em>Call it hair splitting and I won&#8217;t argue much. After all, this does the job too:</p>
<p><em> if (typeof item["isFieldEditable"]==&#8221;function&#8221;) {<br />
  if (!item["isFieldEditable"](dataField)) {<br />
   event.preventDefault();<br />
  }<br />
 }</em></p>
<p> <img src='http://flexblog.faratasystems.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /><br />
Victor</p>
]]></content:encoded>
			<wfw:commentRss>http://flexblog.faratasystems.com/2006/12/06/another-praise-to-actionscript-as-casting/feed</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>New daoFlex release 0.11:Data Synchronization via Flex Remoting</title>
		<link>http://flexblog.faratasystems.com/2006/10/22/new-daoflex-release-011data-synchronization-via-flex-remoting</link>
		<comments>http://flexblog.faratasystems.com/2006/10/22/new-daoflex-release-011data-synchronization-via-flex-remoting#comments</comments>
		<pubDate>Mon, 23 Oct 2006 00:08:12 +0000</pubDate>
		<dc:creator>Victor Rasputnis</dc:creator>
				<category><![CDATA[ActionScript]]></category>
		<category><![CDATA[Flex]]></category>
		<category><![CDATA[Flex 2]]></category>
		<category><![CDATA[Java]]></category>

		<guid isPermaLink="false">http://flexblog.faratasystems.com/?p=104</guid>
		<description><![CDATA[As a tribute to MAX2006, we have uploaded the latest release of our open-source daoFlex code generator and library.
What’s cool in this release? We now support complete data synchronization via Flex Remoting. Here is how: we&#8217;ve created a ActionScript class DataCollection that  descends from   ArrayCollection, but it is “destination-aware” and has its [...]]]></description>
			<content:encoded><![CDATA[<p>As a tribute to MAX2006, we have uploaded the latest release of our <a target="_blank" href="http://www.faratasystems.com/download/daoFlex/daoFlex.zip">open-source daoFlex code generator and library</a>.</p>
<p>What’s cool in this release? We now support complete data synchronization via Flex Remoting. Here is how: we&#8217;ve created a ActionScript class <em>DataCollection</em> that  descends from   ArrayCollection, but it is “destination-aware” and has its own methods  <em>fill()</em> and <em>sync()</em>. DataCollection knows how many elements have been modified, created, deleted, etc. and can manipulate them freely.</p>
<p>ActionScript class <em>BatchService </em>allows sending updates done to multiple DataCollections in our batch. We wrote a small <em>BatchGateway</em> destination which applies such batch as a unit of work (JTA transaction). More, you can batch arbitrary remote calls, say invoking a stored procedure in the same transaction. And watch this: you can do this without writing a single line in Java, except <a target="_blank" href="http://www.faratasystems.com/download/daoFlex/welcome.html">defining annotated abstract classes</a>.</p>
<p>So now you can use Flex Remoting for your data synchronization with back-end on par with Flex Data Services. These technologies are complementary to each other. Use Flex Data Services when you need the server push and pagination. For all other use cases Remoting is sufficient. Classes generated by daoFlex are universal for either solution. You take the side, we will supply the ammo <img src='http://flexblog.faratasystems.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
<p>If you are in Vegas this week, I&#8217;ll be showing it in action  at <a href="http://barcamp.org/MAXUP">MAXUP</a>.</p>
<p>Victor Rasputnis</p>
]]></content:encoded>
			<wfw:commentRss>http://flexblog.faratasystems.com/2006/10/22/new-daoflex-release-011data-synchronization-via-flex-remoting/feed</wfw:commentRss>
		<slash:comments>6</slash:comments>
		</item>
		<item>
		<title>ActionScript 3: Overloading constructors with &#8230;(rest)</title>
		<link>http://flexblog.faratasystems.com/2006/10/16/actionscript-3-overloading-constructors-with-rest</link>
		<comments>http://flexblog.faratasystems.com/2006/10/16/actionscript-3-overloading-constructors-with-rest#comments</comments>
		<pubDate>Mon, 16 Oct 2006 11:24:30 +0000</pubDate>
		<dc:creator>Victor Rasputnis</dc:creator>
				<category><![CDATA[ActionScript]]></category>
		<category><![CDATA[Flex]]></category>
		<category><![CDATA[Flex 2]]></category>
		<category><![CDATA[oop]]></category>
		<category><![CDATA[ria]]></category>

		<guid isPermaLink="false">http://flexblog.faratasystems.com/?p=100</guid>
		<description><![CDATA[ActionScript 3 allows a function to have a variable number of arguments by using so-called … (rest) parameter. Ellipses followed by the name represent an array parameter that can contain any number of comma-delimited arguments:
public static function calcTax(… taxParams):Number{
for (uint i=0; i< taxParams.length; i++){
trace(taxParams[i]);
}
}
Java programmers may find the … (rest) similar to the varargs notation. [...]]]></description>
			<content:encoded><![CDATA[<p class="BodyCopyajax">ActionScript 3 allows a function to have a variable number of arguments by using so-called … (rest) parameter. Ellipses followed by the name represent an array parameter that can contain any number of comma-delimited arguments:</p>
<p class="CodeSnippetAJAX">public static function calcTax(… taxParams):Number{<br />
for (uint i=0; i< taxParams.length; i++){<br />
trace(taxParams[i]);<br />
}<br />
}</p>
<p class="BodyCopyajax">Java programmers may find the … (rest) similar to the varargs notation. You can mix the … (rest) with other function parameters as long as it’s the last parameter listed.</p>
<p class="BodyCopyajax">Unless you use the rest parameter, AS3 creates in memory a special object called arguments, which is an array that include references to each of the arguments and a reference to function  itself (arguments.callee). AS3 allows you to call a function with more parameters than were included in the function declaration, and each of the parameters can be access by using the arguments[i] notation.</p>
<p class="BodyCopyajax">Here’s an idea of using … (rest) parameter to overcome the absence of overloaded  constructors in AS3:</p>
<p class="BodyCopyajax">public function MyCLass(&#8230;args) {<br />
switch (args.length) {<br />
case 0: constructor1(); return;<br />
case 1: constructor2(args[0]); return;<br />
case 2: constructor3(args[0], args[1]); return;<br />
&#8230;<br />
}  }</p>
<p class="BodyCopyajax">This sample covers the case of constructors having different number of parameters. But if you want this solution to work with functions having the same number of parameters but different types, you’d need to add the type check to each of these cases above, i.e.</p>
<p class="BodyCopyajax">if(args[0] is String) {<br />
//do one thing<br />
}else if (args[0] is Number){<br />
// do another thing<br />
}</p>
]]></content:encoded>
			<wfw:commentRss>http://flexblog.faratasystems.com/2006/10/16/actionscript-3-overloading-constructors-with-rest/feed</wfw:commentRss>
		<slash:comments>6</slash:comments>
		</item>
	</channel>
</rss>
