<?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>DaveOnCode &#187; flex</title>
	<atom:link href="http://www.daveoncode.com/tag/flex/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.daveoncode.com</link>
	<description>coder and technology lover</description>
	<lastBuildDate>Sun, 16 May 2010 16:55:18 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0</generator>
		<item>
		<title>Handling doubleclick on Flex components</title>
		<link>http://www.daveoncode.com/2010/04/07/handling-doubleclick-on-flex-components/</link>
		<comments>http://www.daveoncode.com/2010/04/07/handling-doubleclick-on-flex-components/#comments</comments>
		<pubDate>Wed, 07 Apr 2010 10:34:53 +0000</pubDate>
		<dc:creator>Davide Zanotti</dc:creator>
				<category><![CDATA[flex]]></category>
		<category><![CDATA[actionscript]]></category>

		<guid isPermaLink="false">http://www.daveoncode.com/?p=598</guid>
		<description><![CDATA[Handling a common event like a double click is not so simple as we may assume when it comes to Flex programming. In fact there are several critical aspects related to this event, first of all we have to set the attribute doubleClickEnabled to true in order to make our components double clickable, and this]]></description>
			<content:encoded><![CDATA[<p>Handling a common event like a double click is not so simple as we may assume when it comes to Flex programming.<br />
In fact there are several critical aspects related to this event, first of all we have to set the attribute <strong>doubleClickEnabled</strong> to <strong>true</strong> in order to make our components double clickable, and this sounds pretty silly to me. Why should I enable an object to receive an event which is so common and &#8220;natural&#8221;? This is incoherent from a software design perspective end totally unexpected by the user. Anyway this is not a real problem, because once we know about it we have just to use a setter, but double click is somehow buggy in the framework and its broadcasting can be blocked mysteriously when using certain components. I faced this issue by trying to handle a double click on a DataGrid which makes use of custom item renderers and I tested that by double clicking on the &#8220;special cells&#8221; (those rendered by my own renderers) the <strong>MouseEvent.DOUBLE_CLICK</strong> is not dispatched/cacthed. To solve the problem I had to draw an invisible rectangle using the underlying Actionscript graphics API! This is my workaround:</p>
<div class="codecolorer-container actionscript mac-classic" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br />2<br />3<br /></div></td><td><div class="actionscript codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #0066CC;">this</span>.<span style="color: #006600;">graphics</span>.<span style="color: #0066CC;">beginFill</span><span style="color: #66cc66;">&#40;</span>0xffffff, <span style="color: #cc66cc;">0</span><span style="color: #66cc66;">&#41;</span>;<br />
<span style="color: #0066CC;">this</span>.<span style="color: #006600;">graphics</span>.<span style="color: #006600;">drawRect</span><span style="color: #66cc66;">&#40;</span><span style="color: #cc66cc;">0</span>, <span style="color: #cc66cc;">0</span>, <span style="color: #0066CC;">this</span>.<span style="color: #006600;">parent</span>.<span style="color: #0066CC;">width</span>, <span style="color: #0066CC;">this</span>.<span style="color: #006600;">parent</span>.<span style="color: #0066CC;">height</span><span style="color: #66cc66;">&#41;</span>;<br />
<span style="color: #0066CC;">this</span>.<span style="color: #006600;">graphics</span>.<span style="color: #0066CC;">endFill</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;</div></td></tr></tbody></table></div>
<p>Finally, it seems that double click is <strong>completely ignored</strong> by Firefox 3.6 on Mac OS X, but fortunately this seems to been fixed in the last release (3.6.3)</p>
]]></content:encoded>
			<wfw:commentRss>http://www.daveoncode.com/2010/04/07/handling-doubleclick-on-flex-components/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Get hours, minutes and seconds from a number without maths operations</title>
		<link>http://www.daveoncode.com/2010/02/05/get-hours-minutes-and-seconds-from-number-without-maths-operations/</link>
		<comments>http://www.daveoncode.com/2010/02/05/get-hours-minutes-and-seconds-from-number-without-maths-operations/#comments</comments>
		<pubDate>Fri, 05 Feb 2010 15:09:11 +0000</pubDate>
		<dc:creator>Davide Zanotti</dc:creator>
				<category><![CDATA[actionscript]]></category>
		<category><![CDATA[flex]]></category>

		<guid isPermaLink="false">http://www.daveoncode.com/?p=589</guid>
		<description><![CDATA[Today I&#8217;m gonna show you a secret ninja technique to extract hours, minutes and seconds from a number (representing an amount of seconds). In my example I will show an Actionscript code, but this can be implemented in JavaScript and maybe other languages too. So, the scenario is the following: we have a number representing]]></description>
			<content:encoded><![CDATA[<p>Today I&#8217;m gonna show you a secret ninja technique to extract hours, minutes and seconds from a number (representing an amount of seconds). In my example I will show an Actionscript code, but this can be implemented in JavaScript and maybe other languages too.<br />
So, the scenario is the following: we have a number representing seconds and we want to know how many hours this amount of seconds contains, how many minutes and how many remaining seconds. We know that a minute is composed by 60 seconds and an hour by 60 minutes and we could write a series of maths operations in order to accomplish our objective, but there is a way far simple and fast: use the Date class!<br />
Date class already implements all the methods we need:</p>
<ul>
<li><strong>getHours()</strong></li>
<li><strong>getMinutes()</strong></li>
<li><strong>getSeconds()</strong></li>
</ul>
<p>So, in order to take advantage of these useful methods, all we have to do is initialize a &#8220;fake&#8221; date using the amount of seconds we want to &#8220;split&#8221; into hours, minutes and seconds. The Date class has several OPTIONAL arguments that can be specified during its initializations, these are:</p>
<ul>
<li><strong>year</strong></li>
<li><strong>month</strong></li>
<li><strong>date</strong> (day number)</li>
<li><strong>hours</strong></li>
<li><strong>minutes</strong></li>
<li><strong>seconds</strong></li>
<li><strong>milliseconds</strong></li>
</ul>
<p>Because theme all are optional, we can create a date object by specifying only the know arguments (in our case seconds) and by assigning null or zero to the others:</p>
<div class="codecolorer-container actionscript mac-classic" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br /></div></td><td><div class="actionscript codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #000000; font-weight: bold;">var</span> <span style="color: #0066CC;">date</span>:<span style="color: #0066CC;">Date</span> = <span style="color: #000000; font-weight: bold;">new</span> <span style="color: #0066CC;">Date</span><span style="color: #66cc66;">&#40;</span><span style="color: #000000; font-weight: bold;">null</span>, <span style="color: #000000; font-weight: bold;">null</span>, <span style="color: #000000; font-weight: bold;">null</span>, <span style="color: #cc66cc;">0</span>, <span style="color: #cc66cc;">0</span>, <span style="color: #cc66cc;">9137</span><span style="color: #66cc66;">&#41;</span>;</div></td></tr></tbody></table></div>
<p>Then by calling getHours, getMinutes and getSeconds we will obtain what we expect:</p>
<div class="codecolorer-container actionscript mac-classic" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br />2<br />3<br /></div></td><td><div class="actionscript codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #0066CC;">trace</span><span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">&quot;hours: &quot;</span>, <span style="color: #0066CC;">date</span>.<span style="color: #0066CC;">getHours</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span>; <span style="color: #808080; font-style: italic;">// 2 hours</span><br />
<span style="color: #0066CC;">trace</span><span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">&quot;minutes: &quot;</span>, <span style="color: #0066CC;">date</span>.<span style="color: #0066CC;">getMinutes</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span>; <span style="color: #808080; font-style: italic;">// 32 minutes</span><br />
<span style="color: #0066CC;">trace</span><span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">&quot;seconds: &quot;</span>, <span style="color: #0066CC;">date</span>.<span style="color: #0066CC;">getSeconds</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span>; <span style="color: #808080; font-style: italic;">// 17 seconds</span></div></td></tr></tbody></table></div>
<p>Not sure about the result? Let&#8217;s test it:</p>
<p>60 * 60 * 2 = <strong>7200</strong>; (seconds contained in 2 hours)<br />
32 * 60 = <strong>1920</strong>; (seconds contained in 32 minutes)<br />
7200 + 1920 + 17 = <strong>9137</strong>; (original seconds!)</p>
]]></content:encoded>
			<wfw:commentRss>http://www.daveoncode.com/2010/02/05/get-hours-minutes-and-seconds-from-number-without-maths-operations/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Resolve Flex&#8217;s error: &#8220;Type was not found or was not a compile-time constant&#8221;</title>
		<link>http://www.daveoncode.com/2009/08/02/flex-type-was-not-found-or-was-not-a-compile-time-constant/</link>
		<comments>http://www.daveoncode.com/2009/08/02/flex-type-was-not-found-or-was-not-a-compile-time-constant/#comments</comments>
		<pubDate>Sun, 02 Aug 2009 10:23:09 +0000</pubDate>
		<dc:creator>Davide Zanotti</dc:creator>
				<category><![CDATA[flex]]></category>
		<category><![CDATA[compile]]></category>
		<category><![CDATA[error]]></category>
		<category><![CDATA[flex builder]]></category>

		<guid isPermaLink="false">http://www.daveoncode.com/?p=446</guid>
		<description><![CDATA[I just faced the terrible nightmare of &#8220;Type was not found or was not a compile-time constant&#8221; error (Flex Builder) and I lost several time to figure out what the problem was. I realized that I was using the same name for MXML Application file which was already used by a class inside one of]]></description>
			<content:encoded><![CDATA[<p>I just faced the terrible nightmare of &#8220;Type was not found or was not a compile-time constant&#8221; error (Flex Builder) and I lost several time to figure out what the problem was.<br />
I realized that I was using the same name for MXML Application file which was already used by a class inside one of my packages. So, by renaming the file I solved the problem, but I was not completely satisfied and I looked for a way to avoid the error mantaining the same file/class name. Initially I tried to use namespaces, but as the reference says: <em> &#8220;Applying a namespace means placing a definition into a namespace. Definitions that can be placed into namespaces include functions, variables, and constants (<strong>you cannot place a class into a custom namespace</strong>)&#8221;</em>. I finally solved by renaming class references inside my package with the full qualified name (from MyClass to com.mysite.foo.MyClass)</p>
]]></content:encoded>
			<wfw:commentRss>http://www.daveoncode.com/2009/08/02/flex-type-was-not-found-or-was-not-a-compile-time-constant/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Flex 4 (Gumbo) beta released!</title>
		<link>http://www.daveoncode.com/2009/06/03/flex-4-gumbo-sdk-beta-released/</link>
		<comments>http://www.daveoncode.com/2009/06/03/flex-4-gumbo-sdk-beta-released/#comments</comments>
		<pubDate>Wed, 03 Jun 2009 15:30:49 +0000</pubDate>
		<dc:creator>Davide Zanotti</dc:creator>
				<category><![CDATA[flex]]></category>
		<category><![CDATA[flex 4]]></category>
		<category><![CDATA[flex gumbo]]></category>
		<category><![CDATA[sdk]]></category>

		<guid isPermaLink="false">http://www.daveoncode.com/?p=431</guid>
		<description><![CDATA[Flex 4 beta (codename: Gumbo) has been released, I just finished to read about the new major release. These are the main news: Improved compiler performance New skinning and component architecture (named Spark) Added suppurt to FXG (learn more about FXG) New states model ASDoc tool has been improved and is now possible to use]]></description>
			<content:encoded><![CDATA[<p>Flex 4 beta (codename: Gumbo) has been released, I just finished to read about the new major release. These are the main news:</p>
<ol>
<li>Improved compiler performance</li>
<li>New skinning and component architecture (named Spark)</li>
<li>Added suppurt to FXG (<a href="http://livedocs.adobe.com/flex/gumbo/html/WS145DAB0B-A958-423f-8A01-12B679BA0CC7.html">learn more about FXG</a>)</li>
<li>New states model</li>
<li>ASDoc tool has been improved and is now possible to use ASDoc tags in mxml documents</li>
<li>CSS has been improved to support descendant and id selectors (finally the previous missing &#8220;cascading part&#8221; of CSS has been provided!)</li>
<li>Backwards compatibility with Flex 3</li>
</ol>
<p>The new sdk is available on <a href="http://labs.adobe.com/technologies/flex4sdk/">Adobe Labs</a></p>
<p>More about Gumbo here:</p>
<p><a href="http://opensource.adobe.com/wiki/display/flexsdk/Gumbo+Component+Architecture">An Introduction to the Gumbo Component Architecture</a> (by Deepa Subramaniam)<br />
<a href="http://www.adobe.com/devnet/flex/articles/flex4sdk_whatsnew.html">What&#8217;s new in Flex 4 SDK beta</a> (by Matt Chotin)<br />
<a href="http://www.adobe.com/devnet/flex/articles/flex3and4_differences.html">Differences between Flex 3 and Flex 4</a> (by Joan Lafferty)</p>
]]></content:encoded>
			<wfw:commentRss>http://www.daveoncode.com/2009/06/03/flex-4-gumbo-sdk-beta-released/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>ObjectCollector: Accessing Flex’s objects by id (even dynamic generated) from anywhere</title>
		<link>http://www.daveoncode.com/2009/05/20/objectcollector-accessing-dynamic-generated-flex-objects-by-id/</link>
		<comments>http://www.daveoncode.com/2009/05/20/objectcollector-accessing-dynamic-generated-flex-objects-by-id/#comments</comments>
		<pubDate>Wed, 20 May 2009 14:34:40 +0000</pubDate>
		<dc:creator>Davide Zanotti</dc:creator>
				<category><![CDATA[flex]]></category>

		<guid isPermaLink="false">http://www.daveoncode.com/?p=413</guid>
		<description><![CDATA[Ok, let me explain my last experiment&#8230; Problem Flex&#8217;s components have a nice id property which can be used to easily referencing object created. All you know, that if I get the following mxml Application file: 123456&#60;?xml version=&#34;1.0&#34; encoding=&#34;utf-8&#34;?&#62; &#60;mx:Application xmlns:mx=&#34;http://www.adobe.com/2006/mxml&#34; layout=&#34;vertical&#34;&#62; &#160; &#160; &#60;mx:TextInput id=&#34;input1&#34; width=&#34;300&#34; /&#62; &#60;/mx:Application&#62; I can then create a Script]]></description>
			<content:encoded><![CDATA[<p>Ok, let me explain my last experiment&#8230;</p>
<h2>Problem</h2>
<p></p>
<p>Flex&#8217;s components have a nice <strong>id</strong> property which can be used to easily referencing object created.<br />
All you know, that if I get the following mxml Application file:</p>
<div class="codecolorer-container xml mac-classic" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br />2<br />3<br />4<br />5<br />6<br /></div></td><td><div class="xml codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;?xml</span> <span style="color: #000066;">version</span>=<span style="color: #ff0000;">&quot;1.0&quot;</span> <span style="color: #000066;">encoding</span>=<span style="color: #ff0000;">&quot;utf-8&quot;</span><span style="color: #000000; font-weight: bold;">?&gt;</span></span><br />
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;mx:Application</span> <span style="color: #000066;">xmlns:mx</span>=<span style="color: #ff0000;">&quot;http://www.adobe.com/2006/mxml&quot;</span> <span style="color: #000066;">layout</span>=<span style="color: #ff0000;">&quot;vertical&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span><br />
<br />
&nbsp; &nbsp; <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;mx:TextInput</span> <span style="color: #000066;">id</span>=<span style="color: #ff0000;">&quot;input1&quot;</span> <span style="color: #000066;">width</span>=<span style="color: #ff0000;">&quot;300&quot;</span> <span style="color: #000000; font-weight: bold;">/&gt;</span></span><br />
<br />
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/mx:Application<span style="color: #000000; font-weight: bold;">&gt;</span></span></span></div></td></tr></tbody></table></div>
<p>I can then create a <strong>Script</strong> block into which I&#8217;ll point to TextInput in this way:</p>
<div class="codecolorer-container actionscript mac-classic" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br /></div></td><td><div class="actionscript codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">input1.<span style="color: #0066CC;">text</span> = <span style="color: #ff0000;">&quot;text dynamically added :)&quot;</span>;</div></td></tr></tbody></table></div>
<p>Perfect, but how can I reference dynamically created objects (components outside Application)?</p>
<p><span id="more-413"></span></p>
<p>The simplest example I can do is the following:</p>
<div class="codecolorer-container xml mac-classic" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;height:300px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br />2<br />3<br />4<br />5<br />6<br />7<br />8<br />9<br />10<br />11<br />12<br />13<br />14<br />15<br />16<br />17<br />18<br />19<br />20<br />21<br />22<br /></div></td><td><div class="xml codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;?xml</span> <span style="color: #000066;">version</span>=<span style="color: #ff0000;">&quot;1.0&quot;</span> <span style="color: #000066;">encoding</span>=<span style="color: #ff0000;">&quot;utf-8&quot;</span><span style="color: #000000; font-weight: bold;">?&gt;</span></span><br />
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;mx:Application</span> <span style="color: #000066;">xmlns:mx</span>=<span style="color: #ff0000;">&quot;http://www.adobe.com/2006/mxml&quot;</span> <span style="color: #000066;">layout</span>=<span style="color: #ff0000;">&quot;vertical&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span><br />
<br />
&nbsp; &nbsp; <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;mx:Script<span style="color: #000000; font-weight: bold;">&gt;</span></span></span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #339933;">&lt;![CDATA[</span><br />
<br />
<span style="color: #339933;"> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;private function test():void {</span><br />
<br />
<span style="color: #339933;"> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;var input:TextInput = new TextInput();</span><br />
<span style="color: #339933;"> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;input.id = &quot;input2&quot;;</span><br />
<span style="color: #339933;"> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;</span><br />
<span style="color: #339933;"> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;this.addChild(input);</span><br />
<br />
<span style="color: #339933;"> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;// Here I get an error which says input2 is undefined!</span><br />
<span style="color: #339933;"> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;input2.text = &quot;foo&quot;;</span><br />
<br />
<span style="color: #339933;"> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;}</span><br />
<br />
<span style="color: #339933;"> &nbsp; &nbsp; &nbsp; &nbsp;]]&gt;</span><br />
&nbsp; &nbsp; <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/mx:Script<span style="color: #000000; font-weight: bold;">&gt;</span></span></span><br />
<br />
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/mx:Application<span style="color: #000000; font-weight: bold;">&gt;</span></span></span></div></td></tr></tbody></table></div>
<h2>Solution</h2>
<p></p>
<p>Define a place where to store references to desired objects, which will be accessible through id from anywhere.<br />
So, I created a singleton class called <strong>ObjectCollector</strong> which provides a simple, elegant and secure solution to the problem. You can use it in this way:</p>
<div class="codecolorer-container actionscript mac-classic" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;height:300px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br />2<br />3<br />4<br />5<br />6<br />7<br />8<br />9<br />10<br />11<br />12<br />13<br />14<br />15<br />16<br />17<br />18<br />19<br />20<br />21<br />22<br />23<br />24<br />25<br />26<br />27<br />28<br />29<br />30<br />31<br />32<br />33<br />34<br />35<br />36<br /></div></td><td><div class="actionscript codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #808080; font-style: italic;">// From anywhere you first create and register objects:</span><br />
<br />
<span style="color: #000000; font-weight: bold;">var</span> collector:ObjectCollector = ObjectCollector.<span style="color: #006600;">getInstance</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;<br />
<span style="color: #000000; font-weight: bold;">var</span> myObj1:<span style="color: #0066CC;">Button</span> = <span style="color: #000000; font-weight: bold;">new</span> <span style="color: #0066CC;">Button</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;<br />
<br />
myObj1.<span style="color: #0066CC;">width</span> = <span style="color: #cc66cc;">300</span>;<br />
myObj1.<span style="color: #006600;">label</span> = <span style="color: #ff0000;">&quot;my first button&quot;</span>;<br />
<span style="color: #808080; font-style: italic;">// id is mandatory, otherwise you'll get an error</span><br />
myObj1.<span style="color: #006600;">id</span> = <span style="color: #ff0000;">&quot;myFirstButton&quot;</span>;<br />
<br />
<span style="color: #000000; font-weight: bold;">var</span> myObj2:TextInput = <span style="color: #000000; font-weight: bold;">new</span> TextInput<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;<br />
myObj2.<span style="color: #0066CC;">text</span> = <span style="color: #ff0000;">&quot;hello world&quot;</span>;<br />
<span style="color: #808080; font-style: italic;">// id is mandatory, otherwise you'll get an error</span><br />
myObj2.<span style="color: #006600;">id</span> = <span style="color: #ff0000;">&quot;myTextField&quot;</span>;<br />
<br />
collector.<span style="color: #006600;">registerObject</span><span style="color: #66cc66;">&#40;</span>myObj1<span style="color: #66cc66;">&#41;</span>;<br />
collector.<span style="color: #006600;">registerObject</span><span style="color: #66cc66;">&#40;</span>myObj2<span style="color: #66cc66;">&#41;</span>;<br />
<br />
<span style="color: #808080; font-style: italic;">/* ...then in another (or the same) place you can<br />
get references to your desired objects<br />
(this time by specifying the id)<br />
When you retrieve objects from the collector you should <br />
always cast (upcast!) them to the right type<br />
(Because objects are collected as generic Object classes)<br />
*/</span><br />
<br />
<span style="color: #000000; font-weight: bold;">var</span> btn:<span style="color: #0066CC;">Button</span> = <span style="color: #0066CC;">Button</span><span style="color: #66cc66;">&#40;</span>ObjectCollector.<span style="color: #006600;">getInstance</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>.<span style="color: #006600;">getObject</span><span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">&quot;myFirstButton&quot;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span>;<br />
<br />
<span style="color: #808080; font-style: italic;">// When/if you don't need these reference anymore</span><br />
<span style="color: #808080; font-style: italic;">// you can remove them by id:</span><br />
<br />
ObjectCollector.<span style="color: #006600;">getInstance</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>.<span style="color: #006600;">unregisterObject</span><span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">&quot;myFirstButton&quot;</span><span style="color: #66cc66;">&#41;</span>;<br />
<br />
<span style="color: #808080; font-style: italic;">// or all together:</span><br />
<br />
ObjectCollector.<span style="color: #006600;">getInstance</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>.<span style="color: #006600;">unregisterAll</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;</div></td></tr></tbody></table></div>
<h2>Download</h2>
<p>You can download the class <a href="http://www.daveoncode.com/_dave_stuff/ObjectCollector.zip">here</a></p>
<h2>Documentation</h2>
<p>A brief documentation is available <a href="http://www.daveoncode.com/_docs/utils/com/daveoncode/util/ObjectCollector.html">here</a></p>
]]></content:encoded>
			<wfw:commentRss>http://www.daveoncode.com/2009/05/20/objectcollector-accessing-dynamic-generated-flex-objects-by-id/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Deploy and work with Flex swc library</title>
		<link>http://www.daveoncode.com/2009/04/07/deploy-and-work-with-flex-swc-library/</link>
		<comments>http://www.daveoncode.com/2009/04/07/deploy-and-work-with-flex-swc-library/#comments</comments>
		<pubDate>Tue, 07 Apr 2009 13:49:01 +0000</pubDate>
		<dc:creator>Davide Zanotti</dc:creator>
				<category><![CDATA[flex]]></category>
		<category><![CDATA[actionscript]]></category>
		<category><![CDATA[RSL]]></category>
		<category><![CDATA[swc]]></category>

		<guid isPermaLink="false">http://www.daveoncode.com/?p=371</guid>
		<description><![CDATA[When we need to use a series of Actionscript classes in several projects and centralize them into a single place, the best option available is to deploy our classes as an SWC library and then add it to the &#8220;library path&#8221; under Flex Builder&#8217;s &#8220;build path&#8221; panel. Deploy an swc file To obtain an SWC]]></description>
			<content:encoded><![CDATA[<p>When we need to use a series of Actionscript classes in several projects and centralize them into a single place, the best option available is to deploy our classes as an SWC library and then add it to the &#8220;library path&#8221; under Flex Builder&#8217;s &#8220;build path&#8221; panel.</p>
<p><span id="more-371"></span></p>
<p><strong style="margin: 20px 0">Deploy an swc file</strong></p>
<p>To obtain an SWC file, we have first to create a library project by selecting &#8220;<strong>New > Flex Library Project</strong>&#8221; from Flex builder&#8217;s menu.<br />
The file will be automatically generated under the bin folder as soon a new class is created and/or modified (under <strong>src </strong>folder) and it will have the same name of the project. Is also possible to copy .as files from a folder and paste them into src folder, but in this case the SWC file won&#8217;t be (re)deployed until we select the new added classes under &#8220;<strong>Flex Library Build Path</strong>&#8220;.<br />
There are two other cases for which Flex Builder won&#8217;t (re)deploy the SWC file and is important to keep these in mind, because no errors nor notification messages will be showed by the ide and this could lead to a waste of time trying to figure out what is going on.<br />
The two big things to remember are:</p>
<p>1. Be sure to check &#8220;<strong>Include Adobe AIR libraries</strong>&#8221; under &#8220;<strong>Flex library compiler</strong>&#8221; settings (this can be defined during library creation step or after) when the library make use of AIR api<br />
2. Be sure that package path, declared into imported classes, match the structure of src folder (if we import a class &#8220;MyClass&#8221; with a package declaration like &#8220;com.mysite.ui&#8221; then src folder must contain &#8220;com/mysite/ui&#8221; and &#8220;MyClass&#8221; must be placed there, if we put it under the src root it won&#8217;t be compiled into SWC)</p>
<p><strong style="margin: 20px 0">Import the swc file into a project</strong></p>
<p>Once we get our library project and our compiled swc, we can import it into others Flex projects by going to &#8220;<strong>Flex build path > Library path</strong>&#8221; and selecting &#8220;<strong>Add project</strong>&#8220;. There are two ways of using the imported library and to determine the type of linkage to it: a static link (by choosing the default option &#8220;<strong>Merge into code</strong>&#8220;) or dynamic link (by choosing the default option &#8220;<strong>Runtime shared library (RSL)</strong>&#8220;). The difference between the two types of linkage are that, in the first all library content are compiled into the final project&#8217;s swf file, so once you import and merge the library, its swc file is not necessary anymore and you can distribute your application without the external library (it&#8217;s already embedded into the app), by using an RSL instead the library is loaded at runtime and the application swf doesn&#8217;t keep it&#8217;s data, but only a reference to its location, so the resulting file is smaller than the previous one, but you must be sure to release the Flex application in conjunction with the external library in order to works, otherwise Flex Builder will show an error saying &#8220;unable to open path/yourlib.swc&#8221; (where &#8220;path&#8221; is the path to the library you previously imported).</p>
]]></content:encoded>
			<wfw:commentRss>http://www.daveoncode.com/2009/04/07/deploy-and-work-with-flex-swc-library/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>ArrayCollection: filterFuntion with multiple filter functions using decorator pattern</title>
		<link>http://www.daveoncode.com/2009/03/30/arraycollection-filterfuntion-with-multiple-filter-functions-using-decorator-pattern/</link>
		<comments>http://www.daveoncode.com/2009/03/30/arraycollection-filterfuntion-with-multiple-filter-functions-using-decorator-pattern/#comments</comments>
		<pubDate>Mon, 30 Mar 2009 10:21:11 +0000</pubDate>
		<dc:creator>Davide Zanotti</dc:creator>
				<category><![CDATA[flex]]></category>
		<category><![CDATA[actionscript]]></category>
		<category><![CDATA[collection]]></category>
		<category><![CDATA[design patterns]]></category>

		<guid isPermaLink="false">http://www.daveoncode.com/?p=358</guid>
		<description><![CDATA[I was looking for an elegant solution to implement multiple filter functions on an ArrayCollection (which provides a method filterFunction() that can be assigned dynamically in order to filter data inside the collection). The first and only valid solution I found was that one from Cristian Rotundu, he has extended ArrayCollection class providing a filterFunctions]]></description>
			<content:encoded><![CDATA[<p>I was looking for an elegant solution to implement multiple filter functions on an <strong>ArrayCollection</strong> (which provides a method <strong><em>filterFunction()</em></strong> that can be assigned dynamically in order to filter data inside the collection). The first and only valid solution I found was that one from <a href="http://blog.rotundu.eu/flex/arraycollection-with-multiple-filter-functions/">Cristian Rotundu</a>, he has extended <strong>ArrayCollection</strong> class providing a <strong>filterFunctions</strong> properties which accepts an Array of functions which will be executed in sequence (into a loop) once filterFunction is triggered. Anyway I didn&#8217;t want to subclass <strong>ArrayCollection</strong> and by using the decorator pattern I implemented my own multiple filters version.</p>
<p>So, this is what I done:</p>
<ol>
<li>I defined an interface <strong>IFilter</strong>, which declares only one method: <strong><em>apply()</em></strong></li>
<li>I defined a dummy <strong>Filter</strong> class (which implements <strong>IFilter</strong> in a basic way just to agree to the interface), that is used as a basic empty filter to decorate. It also has a constant called ALL_VALUES which is used as a wildcard for filters (it&#8217;s a simple string with value &#8220;*&#8221;, which means &#8220;all values are allowed&#8221;)</li>
<li>I defined an abstract <strong>AbstractFilterDecorator</strong> class</li>
<li>I created as many subclass of <strong>AbstractFilterDecorator</strong> as the filters I need (yes I treat filters as classes not mere functions)</li>
</ol>
<p>The implementation code is the following:</p>
<div class="codecolorer-container actionscript mac-classic" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br />2<br />3<br />4<br />5<br />6<br />7<br />8<br />9<br /></div></td><td><div class="actionscript codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #000000; font-weight: bold;">var</span> <span style="color: #0066CC;">data</span>:ArrayCollection = ArrayCollection<span style="color: #66cc66;">&#40;</span>grid.<span style="color: #006600;">dataProvider</span><span style="color: #66cc66;">&#41;</span>;<br />
<span style="color: #000000; font-weight: bold;">var</span> filter:IFilter = <span style="color: #000000; font-weight: bold;">new</span> Filter<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <br />
filter = <span style="color: #000000; font-weight: bold;">new</span> LevelFilter<span style="color: #66cc66;">&#40;</span>filter, levelValue<span style="color: #66cc66;">&#41;</span>;<br />
filter = <span style="color: #000000; font-weight: bold;">new</span> CategoryFilter<span style="color: #66cc66;">&#40;</span>filter, categoryValue<span style="color: #66cc66;">&#41;</span>;<br />
filter = <span style="color: #000000; font-weight: bold;">new</span> DateFilter<span style="color: #66cc66;">&#40;</span>filter, dateValue, <span style="color: #ff0000;">&quot;DD/MM/YY&quot;</span><span style="color: #66cc66;">&#41;</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <br />
<span style="color: #0066CC;">data</span>.<span style="color: #006600;">filterFunction</span> = filter.<span style="color: #0066CC;">apply</span>;<br />
<span style="color: #0066CC;">data</span>.<span style="color: #006600;">refresh</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;</div></td></tr></tbody></table></div>
<p>The filter object is wrapped by decorators which all accepts 2 common arguments: an IFilter reference and an Object representing a value. The DateFilter has a third parameter which is used to configure an internal DateFormatter (from mx.formatters package).<br />
I&#8217;m pretty satisfied :)<br />
Uh&#8230; and if you are worried about performance, it is fast enough because filter object are created once and then the function assigned to <strong>filterFunction</strong> is a reference to the resulting decorated filter.</p>
<p><strong>UPDATE:</strong><br />
I realized a very simple <a href="http://www.daveoncode.com/_dave_stuff/samples/Filters/bin-debug/Filters.html">example application</a> which can be downloaded <a href="http://www.daveoncode.com/_dave_stuff/samples/Filters.zip">here</a>.<br />
This following is the content of the mxml file:</p>
<div class="codecolorer-container actionscript mac-classic" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;height:300px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br />2<br />3<br />4<br />5<br />6<br />7<br />8<br />9<br />10<br />11<br />12<br />13<br />14<br />15<br />16<br />17<br />18<br />19<br />20<br />21<br />22<br />23<br />24<br />25<br />26<br />27<br />28<br />29<br />30<br />31<br />32<br />33<br />34<br />35<br />36<br />37<br />38<br />39<br />40<br />41<br />42<br />43<br />44<br />45<br />46<br />47<br />48<br />49<br />50<br />51<br />52<br />53<br />54<br />55<br />56<br />57<br />58<br />59<br />60<br />61<br />62<br />63<br />64<br />65<br /></div></td><td><div class="actionscript codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #66cc66;">&lt;</span>?<span style="color: #0066CC;">xml</span> <span style="color: #0066CC;">version</span>=<span style="color: #ff0000;">&quot;1.0&quot;</span> encoding=<span style="color: #ff0000;">&quot;utf-8&quot;</span>?<span style="color: #66cc66;">&gt;</span><br />
<span style="color: #66cc66;">&lt;</span>mx:Application xmlns:mx=<span style="color: #ff0000;">&quot;http://www.adobe.com/2006/mxml&quot;</span> layout=<span style="color: #ff0000;">&quot;vertical&quot;</span><span style="color: #66cc66;">&gt;</span><br />
<br />
&nbsp; &nbsp; <span style="color: #66cc66;">&lt;</span>mx:Script<span style="color: #66cc66;">&gt;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #66cc66;">&lt;!</span><span style="color: #66cc66;">&#91;</span>CDATA<span style="color: #66cc66;">&#91;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0066CC;">import</span> mx.<span style="color: #006600;">collections</span>.<span style="color: #006600;">ArrayCollection</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0066CC;">import</span> com.<span style="color: #006600;">daveoncode</span>.<span style="color: #006600;">filters</span>.<span style="color: #66cc66;">*</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0066CC;">private</span> <span style="color: #000000; font-weight: bold;">function</span> applyFilters<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>:<span style="color: #0066CC;">void</span> <span style="color: #66cc66;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">var</span> <span style="color: #0066CC;">data</span>:ArrayCollection &nbsp;= ArrayCollection<span style="color: #66cc66;">&#40;</span>userGrid.<span style="color: #006600;">dataProvider</span><span style="color: #66cc66;">&#41;</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">var</span> filter:IFilter = <span style="color: #000000; font-weight: bold;">new</span> Filter<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; filter = <span style="color: #000000; font-weight: bold;">new</span> AgeFilter<span style="color: #66cc66;">&#40;</span>filter, ageFilterValue.<span style="color: #0066CC;">text</span><span style="color: #66cc66;">&#41;</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; filter = <span style="color: #000000; font-weight: bold;">new</span> DateFilter<span style="color: #66cc66;">&#40;</span>filter, dateFilterValue.<span style="color: #006600;">selectedDate</span><span style="color: #66cc66;">&#41;</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; filter = <span style="color: #000000; font-weight: bold;">new</span> SexFilter<span style="color: #66cc66;">&#40;</span>filter, sexFilterValue.<span style="color: #006600;">value</span><span style="color: #66cc66;">&#41;</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0066CC;">data</span>.<span style="color: #006600;">filterFunction</span> = filter.<span style="color: #0066CC;">apply</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0066CC;">data</span>.<span style="color: #006600;">refresh</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #66cc66;">&#125;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #66cc66;">&#93;</span><span style="color: #66cc66;">&#93;</span><span style="color: #66cc66;">&gt;</span><br />
&nbsp; &nbsp; <span style="color: #66cc66;">&lt;/</span>mx:Script<span style="color: #66cc66;">&gt;</span><br />
&nbsp; &nbsp; <br />
&nbsp; &nbsp; <span style="color: #66cc66;">&lt;</span>mx:Panel title=<span style="color: #ff0000;">&quot;Filters&quot;</span> <span style="color: #0066CC;">width</span>=<span style="color: #ff0000;">&quot;600&quot;</span><span style="color: #66cc66;">&gt;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #66cc66;">&lt;</span>mx:Form<span style="color: #66cc66;">&gt;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #66cc66;">&lt;</span>mx:FormItem label=<span style="color: #ff0000;">&quot;Age:&quot;</span><span style="color: #66cc66;">&gt;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #66cc66;">&lt;</span>mx:TextInput id=<span style="color: #ff0000;">&quot;ageFilterValue&quot;</span> <span style="color: #0066CC;">width</span>=<span style="color: #ff0000;">&quot;30&quot;</span> <span style="color: #66cc66;">/&gt;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #66cc66;">&lt;/</span>mx:FormItem<span style="color: #66cc66;">&gt;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #66cc66;">&lt;</span>mx:FormItem label=<span style="color: #ff0000;">&quot;Sex:&quot;</span><span style="color: #66cc66;">&gt;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #66cc66;">&lt;</span>mx:ComboBox id=<span style="color: #ff0000;">&quot;sexFilterValue&quot;</span> dataProvider=<span style="color: #ff0000;">&quot;{[{data: Filter.ALL_VALUES, label: 'ALL'}, {data: 'm', label: 'Male'}, {data: 'f', label: 'Female'}]}&quot;</span> <span style="color: #66cc66;">/&gt;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #66cc66;">&lt;/</span>mx:FormItem<span style="color: #66cc66;">&gt;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #66cc66;">&lt;</span>mx:FormItem label=<span style="color: #ff0000;">&quot;Join date:&quot;</span><span style="color: #66cc66;">&gt;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #66cc66;">&lt;</span>mx:DateField id=<span style="color: #ff0000;">&quot;dateFilterValue&quot;</span> formatString=<span style="color: #ff0000;">&quot;DD/MM/YY&quot;</span> <span style="color: #66cc66;">/&gt;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #66cc66;">&lt;/</span>mx:FormItem<span style="color: #66cc66;">&gt;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #66cc66;">&lt;</span>mx:FormItem<span style="color: #66cc66;">&gt;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #66cc66;">&lt;</span>mx:<span style="color: #0066CC;">Button</span> label=<span style="color: #ff0000;">&quot;Apply filters&quot;</span> click=<span style="color: #ff0000;">&quot;{this.applyFilters()}&quot;</span> <span style="color: #66cc66;">/&gt;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #66cc66;">&lt;/</span>mx:FormItem<span style="color: #66cc66;">&gt;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #66cc66;">&lt;/</span>mx:Form<span style="color: #66cc66;">&gt;</span><br />
&nbsp; &nbsp; <span style="color: #66cc66;">&lt;/</span>mx:Panel<span style="color: #66cc66;">&gt;</span><br />
&nbsp; &nbsp; <br />
&nbsp; &nbsp; <span style="color: #66cc66;">&lt;</span>mx:Panel title=<span style="color: #ff0000;">&quot;Users&quot;</span> <span style="color: #0066CC;">width</span>=<span style="color: #ff0000;">&quot;600&quot;</span><span style="color: #66cc66;">&gt;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #66cc66;">&lt;</span>mx:DataGrid id=<span style="color: #ff0000;">&quot;userGrid&quot;</span> <span style="color: #0066CC;">width</span>=<span style="color: #ff0000;">&quot;100%&quot;</span><span style="color: #66cc66;">&gt;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #66cc66;">&lt;</span>mx:dataProvider<span style="color: #66cc66;">&gt;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #66cc66;">&lt;</span>mx:ArrayCollection<span style="color: #66cc66;">&gt;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #66cc66;">&lt;</span>mx:Array<span style="color: #66cc66;">&gt;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #66cc66;">&lt;</span>mx:<span style="color: #0066CC;">Object</span> age=<span style="color: #ff0000;">&quot;24&quot;</span> sex=<span style="color: #ff0000;">&quot;f&quot;</span> <span style="color: #0066CC;">name</span>=<span style="color: #ff0000;">&quot;Susan&quot;</span> joinDate=<span style="color: #ff0000;">&quot;{new Date(2007, 5, 15)}&quot;</span> <span style="color: #66cc66;">/&gt;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #66cc66;">&lt;</span>mx:<span style="color: #0066CC;">Object</span> age=<span style="color: #ff0000;">&quot;36&quot;</span> sex=<span style="color: #ff0000;">&quot;f&quot;</span> <span style="color: #0066CC;">name</span>=<span style="color: #ff0000;">&quot;Ashley&quot;</span> joinDate=<span style="color: #ff0000;">&quot;{new Date(1998, 7, 20)}&quot;</span> <span style="color: #66cc66;">/&gt;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #66cc66;">&lt;</span>mx:<span style="color: #0066CC;">Object</span> age=<span style="color: #ff0000;">&quot;24&quot;</span> sex=<span style="color: #ff0000;">&quot;f&quot;</span> <span style="color: #0066CC;">name</span>=<span style="color: #ff0000;">&quot;Jennifer&quot;</span> joinDate=<span style="color: #ff0000;">&quot;{new Date(2001, 3, 24)}&quot;</span> <span style="color: #66cc66;">/&gt;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #66cc66;">&lt;</span>mx:<span style="color: #0066CC;">Object</span> age=<span style="color: #ff0000;">&quot;19&quot;</span> sex=<span style="color: #ff0000;">&quot;f&quot;</span> <span style="color: #0066CC;">name</span>=<span style="color: #ff0000;">&quot;Emma&quot;</span> joinDate=<span style="color: #ff0000;">&quot;{new Date(2002, 3, 24)}&quot;</span> <span style="color: #66cc66;">/&gt;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #66cc66;">&lt;</span>mx:<span style="color: #0066CC;">Object</span> age=<span style="color: #ff0000;">&quot;44&quot;</span> sex=<span style="color: #ff0000;">&quot;f&quot;</span> <span style="color: #0066CC;">name</span>=<span style="color: #ff0000;">&quot;Carol&quot;</span> joinDate=<span style="color: #ff0000;">&quot;{new Date(1999, 9, 16)}&quot;</span> <span style="color: #66cc66;">/&gt;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #66cc66;">&lt;</span>mx:<span style="color: #0066CC;">Object</span> age=<span style="color: #ff0000;">&quot;28&quot;</span> sex=<span style="color: #ff0000;">&quot;m&quot;</span> <span style="color: #0066CC;">name</span>=<span style="color: #ff0000;">&quot;Peter&quot;</span> joinDate=<span style="color: #ff0000;">&quot;{new Date(2005, 3, 12)}&quot;</span> <span style="color: #66cc66;">/&gt;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #66cc66;">&lt;</span>mx:<span style="color: #0066CC;">Object</span> age=<span style="color: #ff0000;">&quot;35&quot;</span> sex=<span style="color: #ff0000;">&quot;m&quot;</span> <span style="color: #0066CC;">name</span>=<span style="color: #ff0000;">&quot;Mike&quot;</span> joinDate=<span style="color: #ff0000;">&quot;{new Date(2008, 10, 10)}&quot;</span> <span style="color: #66cc66;">/&gt;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #66cc66;">&lt;</span>mx:<span style="color: #0066CC;">Object</span> age=<span style="color: #ff0000;">&quot;26&quot;</span> sex=<span style="color: #ff0000;">&quot;m&quot;</span> <span style="color: #0066CC;">name</span>=<span style="color: #ff0000;">&quot;Dave&quot;</span> joinDate=<span style="color: #ff0000;">&quot;{new Date(2008, 10, 10)}&quot;</span> <span style="color: #66cc66;">/&gt;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #66cc66;">&lt;</span>mx:<span style="color: #0066CC;">Object</span> age=<span style="color: #ff0000;">&quot;44&quot;</span> sex=<span style="color: #ff0000;">&quot;m&quot;</span> <span style="color: #0066CC;">name</span>=<span style="color: #ff0000;">&quot;William&quot;</span> joinDate=<span style="color: #ff0000;">&quot;{new Date(2004, 9, 16)}&quot;</span> <span style="color: #66cc66;">/&gt;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #66cc66;">&lt;</span>mx:<span style="color: #0066CC;">Object</span> age=<span style="color: #ff0000;">&quot;24&quot;</span> sex=<span style="color: #ff0000;">&quot;m&quot;</span> <span style="color: #0066CC;">name</span>=<span style="color: #ff0000;">&quot;Sean&quot;</span> joinDate=<span style="color: #ff0000;">&quot;{new Date(2006, 3, 24)}&quot;</span> <span style="color: #66cc66;">/&gt;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #66cc66;">&lt;/</span>mx:Array<span style="color: #66cc66;">&gt;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #66cc66;">&lt;/</span>mx:ArrayCollection<span style="color: #66cc66;">&gt;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #66cc66;">&lt;/</span>mx:dataProvider<span style="color: #66cc66;">&gt;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #66cc66;">&lt;/</span>mx:DataGrid<span style="color: #66cc66;">&gt;</span><br />
&nbsp; &nbsp; <span style="color: #66cc66;">&lt;/</span>mx:Panel<span style="color: #66cc66;">&gt;</span><br />
&nbsp; &nbsp; <br />
<span style="color: #66cc66;">&lt;/</span>mx:Application<span style="color: #66cc66;">&gt;</span></div></td></tr></tbody></table></div>
]]></content:encoded>
			<wfw:commentRss>http://www.daveoncode.com/2009/03/30/arraycollection-filterfuntion-with-multiple-filter-functions-using-decorator-pattern/feed/</wfw:commentRss>
		<slash:comments>15</slash:comments>
		</item>
		<item>
		<title>Set DataGridColumn&#8217;s width in percentage with ease</title>
		<link>http://www.daveoncode.com/2009/03/18/set-datagridcolumns-width-in-percentage-with-ease/</link>
		<comments>http://www.daveoncode.com/2009/03/18/set-datagridcolumns-width-in-percentage-with-ease/#comments</comments>
		<pubDate>Wed, 18 Mar 2009 22:40:06 +0000</pubDate>
		<dc:creator>Davide Zanotti</dc:creator>
				<category><![CDATA[flex]]></category>
		<category><![CDATA[actionscript]]></category>

		<guid isPermaLink="false">http://www.daveoncode.com/?p=350</guid>
		<description><![CDATA[I was trying to set the columns of a DataGrid to a certain percentage, but I discovered that inexplicably DataGridColumn doesn&#8217;t provide percentageWidth property nor it accepts a percentage string as width property&#8230; so I did a quick search on google and I found that is sad but true and moreover the solution I found]]></description>
			<content:encoded><![CDATA[<p>I was trying to set the columns of a DataGrid to a certain percentage, but I discovered that inexplicably DataGridColumn doesn&#8217;t provide percentageWidth property nor it accepts a percentage string as width property&#8230; so I did a quick search on google and I found that is sad but true and moreover the solution I found on the web is to use a function to calculate each single column width after creationComplete event is dispatched&#8230; terrible! However I did a test before, by assign a decimal value to width (0.5 instead of 50%) and it works! The width property in fact accepts a Number as value not an int, so we can specify a value under 1, which is treated as a percentage&#8230; what surprise me, is that no one seems to had this idea&#8230; anyway I hope this will be helpful for all.</p>
<p>This is a piece of my AS code to set DataGridColumn width in percentage:</p>
<div class="codecolorer-container actionscript mac-classic" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br />2<br /></div></td><td><div class="actionscript codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">col = <span style="color: #000000; font-weight: bold;">new</span> DataGridColumn<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;<br />
col.<span style="color: #0066CC;">width</span> = options<span style="color: #66cc66;">&#91;</span>i<span style="color: #66cc66;">&#93;</span> == <span style="color: #ff0000;">&quot;Message&quot;</span> ? <span style="color: #cc66cc;">0.6</span> : <span style="color: #cc66cc;">0.1</span>;</div></td></tr></tbody></table></div>
<p>In my code I&#8217;m setting the columns to 10% and to 60% only for &#8220;Message&#8221; column.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.daveoncode.com/2009/03/18/set-datagridcolumns-width-in-percentage-with-ease/feed/</wfw:commentRss>
		<slash:comments>11</slash:comments>
		</item>
		<item>
		<title>Extending Flex&#8217;s logging framework to write custom log files</title>
		<link>http://www.daveoncode.com/2009/02/23/extending-flexs-logging-framework-to-write-custom-log-files/</link>
		<comments>http://www.daveoncode.com/2009/02/23/extending-flexs-logging-framework-to-write-custom-log-files/#comments</comments>
		<pubDate>Mon, 23 Feb 2009 18:19:06 +0000</pubDate>
		<dc:creator>Davide Zanotti</dc:creator>
				<category><![CDATA[flex]]></category>
		<category><![CDATA[actionscript]]></category>
		<category><![CDATA[debug]]></category>
		<category><![CDATA[logging]]></category>
		<category><![CDATA[programming]]></category>

		<guid isPermaLink="false">http://www.daveoncode.com/?p=308</guid>
		<description><![CDATA[In these days I played with Flex&#8217;s logging framework and I extended it to write log messages to files, both plain text .log files and dynamic HTML, CSS formatted and Javascript powered files with the ability to filter message type (debug, error, fatal and so on). The logging framework is a powerful feature that comes]]></description>
			<content:encoded><![CDATA[<p>In these days I played with Flex&#8217;s logging framework and I extended it to write log messages to files, both plain text .log files and dynamic HTML, CSS formatted and Javascript powered files with the ability to filter message type (debug, error, fatal and so on).</p>
<p>The logging framework is a powerful feature that comes with Flex&#8217;s sdk and it&#8217;s composed by the classes under <strong>mx.logging </strong>package, which includes the two &#8220;subpackages&#8221; <strong>mx.logging.errors</strong> and <strong>mx.logging.target</strong>.</p>
<p>Java developers should be already confident whit such framework, because logging api are commonly used in Java programming,  Actionscript /Flash/Flex developers may find this tool a novelty (as I did).</p>
<p>The objective of logging framework is to provide a tool that offers a far better, flexible and centralized way to debug an application than simple use a lot of <strong>trace()</strong> callings. With Flex&#8217;s debugging framework we are able to print and filtering among different types of message based on their severity, such:</p>
<ul>
<li>DEBUG</li>
<li>ERROR</li>
<li>FATAL</li>
<li>INFO</li>
<li>WARN</li>
</ul>
<p>We can also print the timestamp of the message and the class it refers to, and finally we can simultaneously print messages to different targets.</p>
<p><span id="more-308"></span></p>
<h3 style="margin: 20px 0">How it works</h3>
<p>The logging framework is basically represented by 3 units: a logger, a target and a log event. The first component is the main class of the framework and its job is to register the different &#8220;loggable classes&#8221;, register one or more targets and dispatch log events. A target is a class which receives a LogEvent event and handles it by printing its information (message, date, level&#8230;) somewhere. A LogEvent event is dispatched when one of the logger methods such: <strong>debug()</strong>, <strong>error()</strong>, <strong>fatal()</strong>, <strong>info()</strong>, <strong>log()</strong> or <strong>warn()</strong> is called.</p>
<p>The steps required to use the logging system are the following:</p>
<p>1. Registering the classes for logging:</p>
<div class="codecolorer-container actionscript3 mac-classic" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br />2<br />3<br />4<br />5<br />6<br />7<br />8<br />9<br />10<br />11<br />12<br />13<br />14<br />15<br />16<br />17<br />18<br /></div></td><td><div class="actionscript3 codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #9900cc; font-weight: bold;">package</span> com<span style="color: #000066; font-weight: bold;">.</span>daveoncode <span style="color: #000000;">&#123;</span><br />
<br />
&nbsp; &nbsp; <span style="color: #0033ff; font-weight: bold;">import</span> mx<span style="color: #000066; font-weight: bold;">.</span>logging<span style="color: #000066; font-weight: bold;">.*;</span><br />
<br />
&nbsp; &nbsp; <span style="color: #0033ff; font-weight: bold;">public</span> <span style="color: #9900cc; font-weight: bold;">class</span> Foo <span style="color: #000000;">&#123;</span><br />
<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0033ff; font-weight: bold;">private</span> <span style="color: #6699cc; font-weight: bold;">var</span> _logger<span style="color: #000066; font-weight: bold;">:</span>ILogger<span style="color: #000066; font-weight: bold;">;</span><br />
<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0033ff; font-weight: bold;">public</span> <span style="color: #339966; font-weight: bold;">function</span> Foo<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span> <span style="color: #000000;">&#123;</span><br />
<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0033ff; font-weight: bold;">this</span><span style="color: #000066; font-weight: bold;">.</span>_logger = Log<span style="color: #000066; font-weight: bold;">.</span>getLogger<span style="color: #000000;">&#40;</span><span style="color: #990000;">&quot;com.daveoncode.Foo&quot;</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0033ff; font-weight: bold;">this</span><span style="color: #000066; font-weight: bold;">.</span>_logger<span style="color: #000066; font-weight: bold;">.</span>debug<span style="color: #000000;">&#40;</span><span style="color: #990000;">&quot;debugging message from Foo class&quot;</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0033ff; font-weight: bold;">this</span><span style="color: #000066; font-weight: bold;">.</span>_logger<span style="color: #000066; font-weight: bold;">.</span>warn<span style="color: #000000;">&#40;</span><span style="color: #990000;">&quot;warning message from Foo class&quot;</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span><br />
<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000;">&#125;</span><br />
<br />
&nbsp; &nbsp; <span style="color: #000000;">&#125;</span><br />
<span style="color: #000000;">&#125;</span></div></td></tr></tbody></table></div>
<p>The code above will register the class Foo under the package com.daveoncode and then it will broadcast a debug and a warning message</p>
<p>2. Initialize and configure a logging target such TraceTarget (typically in the main class):</p>
<div class="codecolorer-container actionscript3 mac-classic" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br />2<br />3<br />4<br />5<br />6<br />7<br />8<br />9<br />10<br />11<br />12<br />13<br /></div></td><td><div class="actionscript3 codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #6699cc; font-weight: bold;">var</span> basicTarget<span style="color: #000066; font-weight: bold;">:</span>TraceTarget = <span style="color: #0033ff; font-weight: bold;">new</span> TraceTarget<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span><br />
<br />
<span style="color: #009900; font-style: italic;">// Apply filters</span><br />
basicTarget<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">filters</span> = <span style="color: #000000;">&#91;</span><span style="color: #990000;">&quot;com.daveoncode.*&quot;</span><span style="color: #000000;">&#93;</span><span style="color: #000066; font-weight: bold;">;</span><br />
<br />
<span style="color: #009900; font-style: italic;">// Log all log levels.</span><br />
basicTarget<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">level</span> = LogEventLevel<span style="color: #000066; font-weight: bold;">.</span>ALL<span style="color: #000066; font-weight: bold;">;</span><br />
<br />
<span style="color: #009900; font-style: italic;">// Add date, time, category, and log level to the output</span><br />
basicTarget<span style="color: #000066; font-weight: bold;">.</span>includeDate = <span style="color: #0033ff; font-weight: bold;">true</span><span style="color: #000066; font-weight: bold;">;</span><br />
basicTarget<span style="color: #000066; font-weight: bold;">.</span>includeTime = <span style="color: #0033ff; font-weight: bold;">true</span><span style="color: #000066; font-weight: bold;">;</span><br />
basicTarget<span style="color: #000066; font-weight: bold;">.</span>includeCategory = <span style="color: #0033ff; font-weight: bold;">true</span><span style="color: #000066; font-weight: bold;">;</span><br />
basicTarget<span style="color: #000066; font-weight: bold;">.</span>includeLevel = <span style="color: #0033ff; font-weight: bold;">true</span><span style="color: #000066; font-weight: bold;">;</span></div></td></tr></tbody></table></div>
<p>The code above will print log messages of all &#8220;subscribed&#8221; classes inside the package com.daveoncode, including all information available (date, time, category, level)</p>
<p>3. Add the target to the logger:</p>
<div class="codecolorer-container actionscript3 mac-classic" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br /></div></td><td><div class="actionscript3 codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">Log<span style="color: #000066; font-weight: bold;">.</span>addTarget<span style="color: #000000;">&#40;</span>basicTarget<span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span></div></td></tr></tbody></table></div>
<p>The previous steps can be repeated as many times as we need, in order to registering several classes and several targets (<span onclick="dr4sdgryt(event)">perhaps </span>with different filters and info settings).</p>
<h3 style="margin: 20px 0">How to extend the framework</h3>
<p>To extend the framework we can create new target classes, which print LogEvent data to different location and display data as we like. In my experiment I created a &#8220;mini subframework&#8221; which can print logs to text files or html files. I created the following 7 classes:</p>
<ol>
<li>LogFileTarget</li>
<li>IStreamDataWriter</li>
<li>AbstractDataWriter</li>
<li>PlainTextDataWriter</li>
<li>HTMLDataWriter</li>
<li>InvalidLogFileTargetError</li>
<li>UnsupportedWriteModeError</li>
</ol>
<p>The first, as the name suggest is a custom target class, which extends LineFormattedTarget (a target class available in Flex&#8217;s framework), it has a parametric constructor which allows the user to choose the name of the file, its directory, the type of file (txt or html) and the charset that will be used to write the file. IStreamDataWriter is an interface which simply declares one method called writeData(), the main purpose of this interface is to use it in polymorphism. IStreamDataWriter is implemented by AbstractDataWriter as an abstract method (abstract is not supported yet in as3, but is treated as abstract), this class also has a secondary method which is used by two subclasses <strong>PlainTextDataWriter </strong>and <strong>HTMLDataWriter</strong>. These classes have the duty to physically write data to the file by handling the event received by <strong>LogFileTarget </strong>which delegates the business logic to them and are used based on the writeMode configuration of  <strong>LogFileTarget</strong>, which for ease has two public constants called <strong>MODE_PLAIN_TEXT</strong> and <strong>MODE_HTML. InvalidLogFileTargetError</strong> and <strong>UnsupportedWriteModeError </strong>are obviously two custom error which are both (potentially) thrown by <strong>LogFileTarget.</strong></p>
<p>This is a sample code using my own classes:</p>
<div class="codecolorer-container actionscript3 mac-classic" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;height:300px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br />2<br />3<br />4<br />5<br />6<br />7<br />8<br />9<br />10<br />11<br />12<br />13<br />14<br />15<br />16<br />17<br />18<br />19<br />20<br />21<br />22<br />23<br />24<br />25<br />26<br />27<br />28<br />29<br />30<br />31<br /></div></td><td><div class="actionscript3 codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #009900; font-style: italic;">// this will print to an html file</span><br />
<span style="color: #6699cc; font-weight: bold;">var</span> HTMLTarget<span style="color: #000066; font-weight: bold;">:</span>LogFileTarget = <span style="color: #0033ff; font-weight: bold;">new</span> LogFileTarget<span style="color: #000000;">&#40;</span><span style="color: #990000;">&quot;applicationLog&quot;</span><span style="color: #000066; font-weight: bold;">,</span> File<span style="color: #000066; font-weight: bold;">.</span>desktopDirectory<span style="color: #000066; font-weight: bold;">,</span> LogFileTarget<span style="color: #000066; font-weight: bold;">.</span>MODE_HTML<span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span><br />
<br />
<span style="color: #009900; font-style: italic;">// this will print to a txt file</span><br />
<span style="color: #6699cc; font-weight: bold;">var</span> txtTarget<span style="color: #000066; font-weight: bold;">:</span>LogFileTarget = <span style="color: #0033ff; font-weight: bold;">new</span> LogFileTarget<span style="color: #000000;">&#40;</span><span style="color: #990000;">&quot;applicationLog&quot;</span><span style="color: #000066; font-weight: bold;">,</span> File<span style="color: #000066; font-weight: bold;">.</span>desktopDirectory<span style="color: #000066; font-weight: bold;">,</span> LogFileTarget<span style="color: #000066; font-weight: bold;">.</span>MODE_PLAIN_TEXT<span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span><br />
<br />
HTMLTarget<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">filters</span> = <span style="color: #000000;">&#91;</span><span style="color: #990000;">&quot;*&quot;</span><span style="color: #000000;">&#93;</span><span style="color: #000066; font-weight: bold;">;</span><br />
<br />
&nbsp;<span style="color: #009900; font-style: italic;">// Log all log levels.</span><br />
HTMLTarget<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">level</span> = LogEventLevel<span style="color: #000066; font-weight: bold;">.</span>ALL<span style="color: #000066; font-weight: bold;">;</span><br />
<br />
<span style="color: #009900; font-style: italic;">// Add date, time, category, and log level to the output.</span><br />
HTMLTarget<span style="color: #000066; font-weight: bold;">.</span>includeDate = <span style="color: #0033ff; font-weight: bold;">true</span><span style="color: #000066; font-weight: bold;">;</span><br />
HTMLTarget<span style="color: #000066; font-weight: bold;">.</span>includeTime = <span style="color: #0033ff; font-weight: bold;">true</span><span style="color: #000066; font-weight: bold;">;</span><br />
HTMLTarget<span style="color: #000066; font-weight: bold;">.</span>includeCategory = <span style="color: #0033ff; font-weight: bold;">true</span><span style="color: #000066; font-weight: bold;">;</span><br />
HTMLTarget<span style="color: #000066; font-weight: bold;">.</span>includeLevel = <span style="color: #0033ff; font-weight: bold;">true</span><span style="color: #000066; font-weight: bold;">;</span><br />
<br />
txtTarget<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">filters</span> = <span style="color: #000000;">&#91;</span><span style="color: #990000;">&quot;*&quot;</span><span style="color: #000000;">&#93;</span><span style="color: #000066; font-weight: bold;">;</span><br />
<br />
<span style="color: #009900; font-style: italic;">// Log all log levels.</span><br />
txtTarget<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">level</span> = LogEventLevel<span style="color: #000066; font-weight: bold;">.</span>ALL<span style="color: #000066; font-weight: bold;">;</span><br />
<br />
<span style="color: #009900; font-style: italic;">// Add date, time, category, and log level to the output.</span><br />
txtTarget<span style="color: #000066; font-weight: bold;">.</span>includeDate = <span style="color: #0033ff; font-weight: bold;">true</span><span style="color: #000066; font-weight: bold;">;</span><br />
txtTarget<span style="color: #000066; font-weight: bold;">.</span>includeTime = <span style="color: #0033ff; font-weight: bold;">true</span><span style="color: #000066; font-weight: bold;">;</span><br />
txtTarget<span style="color: #000066; font-weight: bold;">.</span>includeCategory = <span style="color: #0033ff; font-weight: bold;">true</span><span style="color: #000066; font-weight: bold;">;</span><br />
txtTarget<span style="color: #000066; font-weight: bold;">.</span>includeLevel = <span style="color: #0033ff; font-weight: bold;">true</span><span style="color: #000066; font-weight: bold;">;</span><br />
<br />
<span style="color: #009900; font-style: italic;">// Add targets</span><br />
Log<span style="color: #000066; font-weight: bold;">.</span>addTarget<span style="color: #000000;">&#40;</span>HTMLTarget<span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span><br />
Log<span style="color: #000066; font-weight: bold;">.</span>addTarget<span style="color: #000000;">&#40;</span>txtTarget<span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span></div></td></tr></tbody></table></div>
<p>Of course this experiment will works only in AIR applications, because we need to use flash.fileystem classes.</p>
<p>These are the two different output that my classes will generate:<br />
<a href="http://www.daveoncode.com/_dave_stuff/samples/applicationLog.log">Text file</a><br />
<a href="http://www.daveoncode.com/_dave_stuff/samples/applicationLog.html">HTML file</a></p>
<p>The cool aspect of html version (LogFileTarget.MODE_HTML) is that you can filter by log type :)</p>
<p>If you want to use or take a look to my experiment, feel free to download my logging package <a href="http://www.daveoncode.com/_dave_stuff/doc_logging_framework-1.0.zip">here</a> (let me know your opinion)</p>
]]></content:encoded>
			<wfw:commentRss>http://www.daveoncode.com/2009/02/23/extending-flexs-logging-framework-to-write-custom-log-files/feed/</wfw:commentRss>
		<slash:comments>5</slash:comments>
		</item>
		<item>
		<title>Create custom reusable Flex&#8217;s components with Actionscript</title>
		<link>http://www.daveoncode.com/2009/01/28/create-custom-reusable-flexs-components-with-actionscript/</link>
		<comments>http://www.daveoncode.com/2009/01/28/create-custom-reusable-flexs-components-with-actionscript/#comments</comments>
		<pubDate>Wed, 28 Jan 2009 21:51:26 +0000</pubDate>
		<dc:creator>Davide Zanotti</dc:creator>
				<category><![CDATA[actionscript]]></category>
		<category><![CDATA[flex]]></category>
		<category><![CDATA[as3]]></category>
		<category><![CDATA[custom components]]></category>
		<category><![CDATA[custom tags]]></category>
		<category><![CDATA[mxml]]></category>
		<category><![CDATA[namespace]]></category>

		<guid isPermaLink="false">http://www.daveoncode.com/?p=223</guid>
		<description><![CDATA[I&#8217;ve played for a while with Flex&#8217;s library and now I&#8217;m experimenting my own custom components and I would like to share them and the knowledge necessary to build personal, reusable cool components. Fundamentally there are two ways to realize custom Flex&#8217;s components: one (and the easiest) is to create an MXML file, the second]]></description>
			<content:encoded><![CDATA[<p>I&#8217;ve played for a while with Flex&#8217;s library and now I&#8217;m experimenting my own custom components and I would like to share them and the knowledge necessary to build personal, reusable cool components.</p>
<p><span>Fundamentally there are two ways to realize custom Flex&#8217;s components: one (and the easiest) is to create an MXML file, the second is to create an <span>Actionscript</span> class.</span></p>
<p><span><span id="more-223"></span><br />
</span></p>
<h2>MXML component</h2>
<p><span>The MXML file will contains a components like a Canvas (which is an excellent class to start to build on) as the root node, instead of the classic Application and it will be filled by others  several small components already available in Flex (Label, <span>TextField</span>, Button&#8230;), realizing a new complex object which can will be used inside MXML Applications by simply writing a tag with the same name of the MXML file. Another step required is to create an XML name space for the custom component created, this can be accomplished simply by insert an </span><em><strong><span><span>xmlns</span></span></strong></em><span> attribute inside the Application node, similarly to the default <span>mx</span> name space from adobe (<span>xmlns</span>:<span>mx</span>=&#8221;http://www.adobe.com/2006/<span>mxml</span>&#8220;), it must report a name after the colons and a path to the package containing the component. This is an example of a name space declaration for my own custom tag:</span></p>
<pre><span>&lt;<span>mx</span>:Application <span>xmlns</span>:<span>mx</span>="http://www.adobe.com/2006/<span>mxml</span>" <span>xmlns</span>:dz="com.<span>daveoncode</span>.controls.*" layout="vertical"&gt;</span></pre>
<p><span>It creates a name space called &#8220;dz&#8221; for all the classes (the &#8220;*&#8221; <span>wildcard</span> means &#8220;all&#8221;) inside the package &#8220;com/<span>daveoncode</span>/controls&#8221;. This is instead how a simple MXML based component could be (this is only a basic example, a such component is pretty useless):</span></p>
<pre><span>&lt;?<span>xml</span> version="1.0" encoding="<span>utf</span>-8"?&gt;</span>
<span>&lt;<span>mx</span>:Panel <span>xmlns</span>:<span>mx</span>="http://www.adobe.com/2006/<span>mxml</span>" title="<span>Login</span>" width="400" height="300"&gt;</span>
    &lt;mx:Form&gt;

<span>        &lt;<span>mx</span>:<span>FormItem</span> label="<span>UserName</span>:"&gt;</span>
<span>            &lt;<span>mx</span>:<span>TextInput</span> width="200" /&gt;</span>
<span>        &lt;/<span>mx</span>:<span>FormItem</span>&gt;</span>

<span>        &lt;<span>mx</span>:<span>FormItem</span> label="Password:"&gt;</span>
<span>            &lt;<span>mx</span>:<span>TextInput</span> width="200" <span>displayAsPassword</span>="true" /&gt;</span>
<span>        &lt;/<span>mx</span>:<span>FormItem</span>&gt;</span>

<span>        &lt;<span>mx</span>:<span>FormItem</span>&gt;</span>
<span>            &lt;<span>mx</span>:Button label="<span>Login</span>" /&gt;</span>
<span>        &lt;/<span>mx</span>:<span>FormItem</span>&gt;</span>

<span>    &lt;/<span>mx</span>:Form&gt;</span>
&lt;/mx:Panel&gt;</pre>
<p><span>Now, supposing that we save the example above as <span>LoginPanel</span>.<span>mxml</span>, under &#8220;com/<span>oursite</span>/components&#8221;, we can use it in a <span>mxml</span> Application in this way:</span></p>
<pre><span>&lt;<span>mx</span>:Application <span>xmlns</span>:cc="com.<span>oursite</span>.components.*" <span>xmlns</span>:<span>mx</span>="http://www.adobe.com/2006/<span>mxml</span>" layout="absolute"&gt;</span>
<span>    &lt;cc:<span>LoginPanel</span> /&gt;</span>
...</pre>
<p><span>This is pretty cool, because lets us separate defined areas of a GUI (like a <span>login</span> panel) and reuse them everywhere with no efforts&#8230; although this is an useful thing, is not so much exciting as creating a real custom component (something that is not made of other existent Flex components), whit its own properties, methods and style support!</span><br />
<span> To create such object, we should write it entirely in <span>Actionscript</span>.</span></p>
<h2><span><span>Actionscript</span> component</span></h2>
<p>We can start from extending an existent Flex class, in order to inherit all the necessary methods to interact properly with the framework. The most important thing to know, is how to handle our class configuration, in fact in Flex we can&#8217;t put configuration logic inside constructor, because it will be automatically called by Flex every time a tag with the components name is encountered and there is no way to pass arguments to the constructor from the MXML tag, so such approach:</p>
<pre><span>public function <span>MyCustomComponent</span>(param1:String, param2:Number) {</span>

    this.param1 = param1;
    this.param2 = param2;

}</pre>
<p><span>cant&#8217; be used! We have instead to write getter and setter which will be automatically called by Flex when required. This kind of getter/setter must use <span>Actionscript&#8217;s</span> </span><strong>get</strong> and <strong>set</strong> keywords, in order to get/set a property. So, we have to forget classic getter/setter methods like:</p>
<pre><span>public function <span>setMyParam</span>(value:String):void {</span>
    myParam = value;
}

<span>public function <span>getMyParam</span>():String {</span>
<span>    return <span>myParam</span>;</span>
}</pre>
<p>and adopt these:</p>
<pre><span>public function set <span>myParam</span>(value:String):void {</span>
    myParam = value;
}

<span>public function get <span>myParam</span>():String {</span>
<span>    return <span>myParam</span>;</span>
}</pre>
<p><span>The get/set key is a really cool feature of <span>Actionscript</span> language, because it lets to set an object property in a declarative manner (<span>myObject</span>.property = X), without <span>renunce</span> to encapsulation. In this way when in MXML file we will declare tag&#8217;s attributes:</span></p>
<pre><span>&lt;cc:<span>MyCustomComponent</span> <span>myParam</span>="Hello!" /&gt; </span></pre>
<p><span>Those setters will be used&#8230; but when exactly? Good question, another thing to understand, in order to realize custom and good components, is in fact the <span>creational</span> procedure adopted by the framework, which is divisible in these steps (in execution order):</span></p>
<ol>
<li><strong>Construction</strong>: in this step the component is instantiated and code inside the constructor is executed (typically the code will consist of a calling to super() and optionally event listeners configuration and few more)</li>
<li><strong>Configuration</strong><span>: <span>getters</span> methods are invoked by Flex to configure class&#8217; instance</span></li>
<li><strong>Attachment</strong><span>: this step <span>occours</span> only when the component is added to the display list. This is an automatic task if the component is called from an MXML (with the relative tag) and <span>occours</span> through <span>Actionscript</span> when </span><em><span><span>addChild</span>() </span></em>or <em><span><span>addChildAt</span>()</span></em> are invoked</li>
<li><strong>Initialization</strong>: this is the most intense phase, because during initialization a lot of tasks are performed and several methods invoked. The first thing that happens is the dispatching of <em><span><span>preinitialize</span></span></em><span> event (<span>FlexEvent</span>.PREINITIALIZE), then the protected method </span><em>createChildren() </em>is called (we have to override this method in order to populate our custom components with desired content), after its execution another event is dispatched, this time is the <em>initialize</em><span> (<span>FlexEvent</span>.INITIALIZE). After these, a series of <span>invalidations</span> and validations operations <span>occours</span> and finally <span>creationcomplete</span> is dispatched (<span>FlexEvent</span>.CREATION_COMPLETE)</span></li>
</ol>
<p><span>I realized a custom component called <span>StarPicker</span>, it is a control which can be used to rate objects (songs,  movies, books&#8230;)</span><span> by selecting (with a click) among N stars (N is one of the several parameters that can be <span>configurated</span> by the user, such color, size, space between stars and so on)</span><span>,  it is <span>bindable</span></span><span> (we can bind another control to <span>StarPicker&#8217;s</span> value)</span> and finally it support CSS styles&#8230; yes, with Flex we can create extreme custom components that will support custom user-defined properties (such &#8220;power&#8221;, &#8220;coolness&#8221;&#8230;)<span>. Although I&#8217;m quite embarrassed</span> (because I&#8217;m not already so confident with Flex), I&#8217;m going to show you how I realized my first Flex component.</p>
<p>My first step was create an Actionscript class (under my package &#8220;com.daveoncode.controls&#8221;) which extends Canvas, then I defined several public constants for default settings, by using the Flex naming convenction &#8220;DEFAULT_MY_SETTING_NAME&#8221;, several private variable to handle settings values and as many private variables to track settings changes. So, before the constructor I&#8217;ve such stuff (every prameter has 3 types of variables/constants related to it):</p>
<pre>public static const DEFAULT_STARS:uint = 5;
// ...more constants

private var _stars:uint;
// ...more vars

private var starsDefined:Boolean;
// ...more booleans</pre>
<p>The constructor contains a call to super and some listeners creation (and I enable the doubleclick over the component):</p>
<pre>public function StarPicker() {

    super();

    // This component allows double click in order to deselect stars
    this.doubleClickEnabled = true;

    // Listens for preinitialize event
    this.addEventListener(FlexEvent.PREINITIALIZE, this.preInitializeHandler);

    // Listens for the click event over the stars
    this.addEventListener(MouseEvent.CLICK, this.clickHandler);

    // Listens for the double click event over the stars
    this.addEventListener(MouseEvent.DOUBLE_CLICK, this.doubleClickHandler);

}</pre>
<p>The only thing I want to analize in the code above is the listener for FlexEvent.PREINITIALIZE&#8230; why I used this listener? The answer is: I use it to set default values if they are not provided by the user (with user I mean who use the component in the MXML file, not the Application&#8217;s user), because I want to handle default settings only after all the setters are called by Flex in order to set properly the boolean flags &#8220;myparamDefined&#8221;, which I use to grant the right precedence between style and inline tag&#8217;s attribute. If a flag is setted (myparamDefined == true) then when CSS assign a value to the same parameter this is not used, because inline attribute have the precedence and win. So the handler has several ternary operators like:</p>
<pre>this._stars = this._stars == 0 ? StarPicker.DEFAULT_STARS : this._stars;</pre>
<p>In order to populate the picker with stars I override  <strong>createChildren()</strong> method, into which I use <strong>addChild()</strong> to insert N Star object (which is a Class in the same package, which basically draws a star shape and has methods to change colors and size), I also override  <strong>measure()</strong> method which is used by Flex to know the exact size of the components (typycally when it must calculates clipping and resizing):</p>
<pre>override protected function measure():void {

    super.measure();

    // StarPicker's height will be the same as the stars
    this.measuredHeight = this.measuredMinHeight = this._starSize + this._starBorderSize;

    // StarPicker's width will be the same as the sum of the stars width + space
    this.measuredWidth = this.measuredMinWidth = (this._starSize + this._starSpace) * this._stars;

}</pre>
<p>In practice I&#8217;m telling Flex that my component should be never clipped and is larger as the sum of the stars width it contains. Oh&#8230; I also override the <strong>styleChanged()</strong> method, which is called by Flex every time a component&#8217;s style parameter changes:</p>
<pre>override public function styleChanged(styleProp:String):void {

    super.styleChanged(styleProp);

    this._stars = this.stars;
    // ... other (re)settings

}</pre>
<p>And style metatags? Yes, I putted them before class declaration:</p>
<pre>[Style(name="stars", type="uint", inherit="no")]
// ... more styles</pre>
<p>With style metatag we can declare the name of styles properties that our components will suport, so with the previous declaration will be possible to create CSS like:</p>
<pre>.myCustomComponent {
    stars: 4;
}</pre>
<p>Ok, I wrote too much, this is an example of the custom component that I realized (you can download, use and view source code by selecting &#8220;Flex components&#8221; on blog&#8217;s menu):</p>

    <object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" id="starpicker" width="600" height="370" align="left" name="starpicker">
      <param name="movie" value="http://www.daveoncode.com/wp-content/uploads/2009/01/customcomponent.swf" />
      <param name="align" value="left" />
      <param name="name" value="starpicker" />
      <!--[if !IE]>-->
      <object type="application/x-shockwave-flash" data="http://www.daveoncode.com/wp-content/uploads/2009/01/customcomponent.swf" width="600" height="370" align="left" name="starpicker">
      <!--<![endif]-->
        <p>The Flash plugin is required to view this object.</p>
      <!--[if !IE]>-->
      </object>
      <!--<![endif]-->
    </object>

<p>The example above is not a screenshot&#8230; you can test it ;-)<br style="clear: both" /></p>
]]></content:encoded>
			<wfw:commentRss>http://www.daveoncode.com/2009/01/28/create-custom-reusable-flexs-components-with-actionscript/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
	</channel>
</rss>
