<?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/category/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>I released my first interesting Flex component :)</title>
		<link>http://www.daveoncode.com/2009/08/07/cool-flex-component-imagenavigator-released/</link>
		<comments>http://www.daveoncode.com/2009/08/07/cool-flex-component-imagenavigator-released/#comments</comments>
		<pubDate>Fri, 07 Aug 2009 12:52:23 +0000</pubDate>
		<dc:creator>Davide Zanotti</dc:creator>
				<category><![CDATA[flex]]></category>

		<guid isPermaLink="false">http://www.daveoncode.com/?p=478</guid>
		<description><![CDATA[Today, I released my component &#8220;ImageNavigator&#8221;, you can see it here and download source code. I&#8217;m pretty satisfied about it, but it needs some little improvements and I&#8217;ve got some ideas to extend its features&#8230; so don&#8217;t consider it as the final version :P]]></description>
			<content:encoded><![CDATA[<p>Today, I released my component &#8220;ImageNavigator&#8221;, you can see it <a href="http://www.daveoncode.com/custom-flex-image-navigator-component-zoom-drag-photoshop/">here</a> and download source code. I&#8217;m pretty satisfied about it, but it needs some little improvements and I&#8217;ve got some ideas to extend its features&#8230; so don&#8217;t consider it as the final version :P</p>
]]></content:encoded>
			<wfw:commentRss>http://www.daveoncode.com/2009/08/07/cool-flex-component-imagenavigator-released/feed/</wfw:commentRss>
		<slash:comments>0</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>Preparing for Adobe Flex 3 + AIR certification</title>
		<link>http://www.daveoncode.com/2009/05/25/preparing-for-adobe-flex-3-air-certification/</link>
		<comments>http://www.daveoncode.com/2009/05/25/preparing-for-adobe-flex-3-air-certification/#comments</comments>
		<pubDate>Mon, 25 May 2009 07:58:29 +0000</pubDate>
		<dc:creator>Davide Zanotti</dc:creator>
				<category><![CDATA[air]]></category>
		<category><![CDATA[flex]]></category>

		<guid isPermaLink="false">http://www.daveoncode.com/?p=421</guid>
		<description><![CDATA[I&#8217;m preparing for the Adobe Flex 3 + AIR certification and I would like to share two AIR applications which I&#8217;m using to study an test my Flex knowledge. The first is pretty famous, so maybe you already know it: Tour The Flex. It provides hundreds examples of all components available in the framework and]]></description>
			<content:encoded><![CDATA[<p>I&#8217;m preparing for the Adobe Flex 3 + AIR certification and I would like to share two AIR applications which I&#8217;m using to study an test my Flex knowledge.<br />
The first is pretty famous, so maybe you already know it: <strong><a href="http://www.adobe.com/devnet/flex/tourdeflex/">Tour The Flex</a></strong>.<br />
It provides hundreds examples of all components available in the framework and includes Adobe reference.<br />
The second is a real helpful app (which I discovered through Twitter), because it consist in an exam simulator (flex 3 + air). Is possible to choose between 8 different test, once a test begins a timer will show you the remaining time and at the end of test the reached score will be showed. Wrongs questions will be explained and you&#8217;ll be pointed to Adobe reference for clarifications.<br />
The (free!) application is available here: <a href="http://software.pxldesigns.com/attest">http://software.pxldesigns.com/attest</a></p>
]]></content:encoded>
			<wfw:commentRss>http://www.daveoncode.com/2009/05/25/preparing-for-adobe-flex-3-air-certification/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>
	</channel>
</rss>
