<?xml version="1.0" encoding="UTF-8"?><!-- generator="wordpress/2.2.1" -->
<rss version="2.0" 
	xmlns:content="http://purl.org/rss/1.0/modules/content/">
<channel>
	<title>Comments on: Displaying the number of children in each branch of a Flex Tree control</title>
	<link>http://blog.flexexamples.com/2008/01/11/displaying-the-number-of-children-in-each-branch-of-a-flex-tree-control/</link>
	<description>A bunch of examples for Adobe Flex and ActionScript</description>
	<pubDate>Thu, 08 Jan 2009 13:11:05 +0000</pubDate>
	<generator>http://wordpress.org/?v=2.2.1</generator>

	<item>
		<title>By: peterd</title>
		<link>http://blog.flexexamples.com/2008/01/11/displaying-the-number-of-children-in-each-branch-of-a-flex-tree-control/#comment-10927</link>
		<author>peterd</author>
		<pubDate>Mon, 07 Apr 2008 04:02:40 +0000</pubDate>
		<guid>http://blog.flexexamples.com/2008/01/11/displaying-the-number-of-children-in-each-branch-of-a-flex-tree-control/#comment-10927</guid>
		<description>Dusan,

Yeah, this blog isn't very friendly for posting code. You'd need to escape your &#60; as &#38;lt; before posting.

As for your ComboBox question, set the &lt;code&gt;prompt&lt;/code&gt; property. For an example, see &lt;a href="http://blog.flexexamples.com/2007/09/25/creating-a-simple-label-function-on-a-flex-combobox-control/" rel="nofollow"&gt;&lt;u&gt;"Creating a simple label function on a Flex ComboBox control"&lt;/u&gt;&lt;/a&gt;.

Peter</description>
		<content:encoded><![CDATA[<p>Dusan,</p>
<p>Yeah, this blog isn&#8217;t very friendly for posting code. You&#8217;d need to escape your &lt; as &amp;lt; before posting.</p>
<p>As for your ComboBox question, set the <code>prompt</code> property. For an example, see <a href="http://blog.flexexamples.com/2007/09/25/creating-a-simple-label-function-on-a-flex-combobox-control/" rel="nofollow"><u>&#8220;Creating a simple label function on a Flex ComboBox control&#8221;</u></a>.</p>
<p>Peter</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Dusan</title>
		<link>http://blog.flexexamples.com/2008/01/11/displaying-the-number-of-children-in-each-branch-of-a-flex-tree-control/#comment-10894</link>
		<author>Dusan</author>
		<pubDate>Sun, 06 Apr 2008 23:41:05 +0000</pubDate>
		<guid>http://blog.flexexamples.com/2008/01/11/displaying-the-number-of-children-in-each-branch-of-a-flex-tree-control/#comment-10894</guid>
		<description>it seems that i cannot post xml code, probly i cose i dont know how, but nevermind, this is what i  used in tree xml
 node label="empty folder" isBranch="true"</description>
		<content:encoded><![CDATA[<p>it seems that i cannot post xml code, probly i cose i dont know how, but nevermind, this is what i  used in tree xml<br />
 node label=&#8221;empty folder&#8221; isBranch=&#8221;true&#8221;</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Dusan</title>
		<link>http://blog.flexexamples.com/2008/01/11/displaying-the-number-of-children-in-each-branch-of-a-flex-tree-control/#comment-10893</link>
		<author>Dusan</author>
		<pubDate>Sun, 06 Apr 2008 23:37:27 +0000</pubDate>
		<guid>http://blog.flexexamples.com/2008/01/11/displaying-the-number-of-children-in-each-branch-of-a-flex-tree-control/#comment-10893</guid>
		<description>my tree isnt in the post above, dont know what happened lol


  
    
    
  
  
    
  
  
  
</description>
		<content:encoded><![CDATA[<p>my tree isnt in the post above, dont know what happened lol</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Dusan</title>
		<link>http://blog.flexexamples.com/2008/01/11/displaying-the-number-of-children-in-each-branch-of-a-flex-tree-control/#comment-10892</link>
		<author>Dusan</author>
		<pubDate>Sun, 06 Apr 2008 23:36:22 +0000</pubDate>
		<guid>http://blog.flexexamples.com/2008/01/11/displaying-the-number-of-children-in-each-branch-of-a-flex-tree-control/#comment-10892</guid>
		<description>First, thanks for your time, and thanks for the help, you helped me a lot. Now:

i did some work and find out some things, and realised what u meant.I used "isBranch="true"" in tree XML and it seems that that did the trick. I got this XML now: 


  
    
    
  
  
    
  
  
  



my tree looks like this:
    

i used your function tree_labelFunc:
private function tree_labelFunc(item:XML):String {
                var label:String = item.@label;
                if (tree1.dataDescriptor.hasChildren(item)) {selectednode.text = label;
                	comboBoxFolder[j] = label;
                    label += " (" + tree1.dataDescriptor.getChildren(item).length + ")";
                }
                return label;
            }
Tree is now just like i wanted. Only one thing i need now, its about combobox, im using this:

private function comboBox_labelFunc(item:XML):String {return item.@label;} 

this works fine since i dont have any leafs in root of the tree, and i wont have them.
now, the thing i need is, when i start application selected item in combobox is first item in combobox, in this case its "news", how do i set that when application starts noone of the items are selected.

Dusan.</description>
		<content:encoded><![CDATA[<p>First, thanks for your time, and thanks for the help, you helped me a lot. Now:</p>
<p>i did some work and find out some things, and realised what u meant.I used &#8220;isBranch=&#8221;true&#8221;" in tree XML and it seems that that did the trick. I got this XML now: </p>
<p>my tree looks like this:</p>
<p>i used your function tree_labelFunc:<br />
private function tree_labelFunc(item:XML):String {<br />
                var label:String = <a href="mailto:item.@label;">item.@label;</a><br />
                if (tree1.dataDescriptor.hasChildren(item)) {selectednode.text = label;<br />
                	comboBoxFolder[j] = label;<br />
                    label += &#8221; (&#8221; + tree1.dataDescriptor.getChildren(item).length + &#8220;)&#8221;;<br />
                }<br />
                return label;<br />
            }<br />
Tree is now just like i wanted. Only one thing i need now, its about combobox, im using this:</p>
<p>private function comboBox_labelFunc(item:XML):String {return <a href="mailto:item.@label;}">item.@label;}</a> </p>
<p>this works fine since i dont have any leafs in root of the tree, and i wont have them.<br />
now, the thing i need is, when i start application selected item in combobox is first item in combobox, in this case its &#8220;news&#8221;, how do i set that when application starts noone of the items are selected.</p>
<p>Dusan.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: peterd</title>
		<link>http://blog.flexexamples.com/2008/01/11/displaying-the-number-of-children-in-each-branch-of-a-flex-tree-control/#comment-10135</link>
		<author>peterd</author>
		<pubDate>Sat, 05 Apr 2008 01:20:50 +0000</pubDate>
		<guid>http://blog.flexexamples.com/2008/01/11/displaying-the-number-of-children-in-each-branch-of-a-flex-tree-control/#comment-10135</guid>
		<description>Dusan,

Sorry, I guess I'm confused. It seems you're trying to display possibly nested data in a linear List. How would you know if a node is an empty branch or just a leaf node?
The &lt;code&gt;isBranch()&lt;/code&gt; method works on a Tree because Trees can have multiple levels with children, whereas a list is usually only for displaying flat data.

If you only want to display the "i) four (4)" and "ii) three (2)" branches, I think you'd need to use the following E4X which grabs all branches with at least one child:
&lt;pre class="code"&gt;
dataProvider="{treeDP..node.(children().length() != 0)}"
&lt;/pre&gt;

Otherwise, how would your Flex application know if it was looking at an empty branch or a leaf node (unless you put some sort of flag in your XML nodes indicating whether something was a branch or leaf).

Peter</description>
		<content:encoded><![CDATA[<p>Dusan,</p>
<p>Sorry, I guess I&#8217;m confused. It seems you&#8217;re trying to display possibly nested data in a linear List. How would you know if a node is an empty branch or just a leaf node?<br />
The <code>isBranch()</code> method works on a Tree because Trees can have multiple levels with children, whereas a list is usually only for displaying flat data.</p>
<p>If you only want to display the &#8220;i) four (4)&#8221; and &#8220;ii) three (2)&#8221; branches, I think you&#8217;d need to use the following E4X which grabs all branches with at least one child:</p>
<pre class="code">
dataProvider="{treeDP..node.(children().length() != 0)}"
</pre>
<p>Otherwise, how would your Flex application know if it was looking at an empty branch or a leaf node (unless you put some sort of flag in your XML nodes indicating whether something was a branch or leaf).</p>
<p>Peter</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Dusan</title>
		<link>http://blog.flexexamples.com/2008/01/11/displaying-the-number-of-children-in-each-branch-of-a-flex-tree-control/#comment-10116</link>
		<author>Dusan</author>
		<pubDate>Fri, 04 Apr 2008 22:59:12 +0000</pubDate>
		<guid>http://blog.flexexamples.com/2008/01/11/displaying-the-number-of-children-in-each-branch-of-a-flex-tree-control/#comment-10116</guid>
		<description>uhh, i guess u dont understand me :(
when i put this i code i get both leafs and branches in combobox, i need only branches. I've been trying to solve this whole day :(. i tried to make something with "isBranch()", but with no success.</description>
		<content:encoded><![CDATA[<p>uhh, i guess u dont understand me :(<br />
when i put this i code i get both leafs and branches in combobox, i need only branches. I&#8217;ve been trying to solve this whole day :(. i tried to make something with &#8220;isBranch()&#8221;, but with no success.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: peterd</title>
		<link>http://blog.flexexamples.com/2008/01/11/displaying-the-number-of-children-in-each-branch-of-a-flex-tree-control/#comment-10113</link>
		<author>peterd</author>
		<pubDate>Fri, 04 Apr 2008 22:48:12 +0000</pubDate>
		<guid>http://blog.flexexamples.com/2008/01/11/displaying-the-number-of-children-in-each-branch-of-a-flex-tree-control/#comment-10113</guid>
		<description>Dusan,

Something like this?
&lt;pre class="code"&gt;
&#60;mx:ComboBox id="checkBox"
        dataProvider="{treeDP..node}"
        labelFunction="comboBox_labelFunc" /&#62;
&lt;/pre&gt;

Peter</description>
		<content:encoded><![CDATA[<p>Dusan,</p>
<p>Something like this?</p>
<pre class="code">
&lt;mx:ComboBox id="checkBox"
        dataProvider="{treeDP..node}"
        labelFunction="comboBox_labelFunc" /&gt;
</pre>
<p>Peter</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Dusan</title>
		<link>http://blog.flexexamples.com/2008/01/11/displaying-the-number-of-children-in-each-branch-of-a-flex-tree-control/#comment-10093</link>
		<author>Dusan</author>
		<pubDate>Fri, 04 Apr 2008 21:33:42 +0000</pubDate>
		<guid>http://blog.flexexamples.com/2008/01/11/displaying-the-number-of-children-in-each-branch-of-a-flex-tree-control/#comment-10093</guid>
		<description>dataProvider="{treeDP..node.(children().length() != 0)}" , i guess tells that its using non-empty branches, what if i have empty branches and want to display them in combobox? The thing is that im downloading XML file ( which can be changed ) from server and im displaying it as tree. Now when tree is displayed i can add empty branches, and also add leafs in that branches. And i want to display them in combobox ( branches, not leafs :) )

ty a lot for help so far</description>
		<content:encoded><![CDATA[<p>dataProvider=&#8221;{treeDP..node.(children().length() != 0)}&#8221; , i guess tells that its using non-empty branches, what if i have empty branches and want to display them in combobox? The thing is that im downloading XML file ( which can be changed ) from server and im displaying it as tree. Now when tree is displayed i can add empty branches, and also add leafs in that branches. And i want to display them in combobox ( branches, not leafs :) )</p>
<p>ty a lot for help so far</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Dusan</title>
		<link>http://blog.flexexamples.com/2008/01/11/displaying-the-number-of-children-in-each-branch-of-a-flex-tree-control/#comment-10089</link>
		<author>Dusan</author>
		<pubDate>Fri, 04 Apr 2008 21:23:47 +0000</pubDate>
		<guid>http://blog.flexexamples.com/2008/01/11/displaying-the-number-of-children-in-each-branch-of-a-flex-tree-control/#comment-10089</guid>
		<description>i'll try it now :) and get back to you</description>
		<content:encoded><![CDATA[<p>i&#8217;ll try it now :) and get back to you</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: peterd</title>
		<link>http://blog.flexexamples.com/2008/01/11/displaying-the-number-of-children-in-each-branch-of-a-flex-tree-control/#comment-10087</link>
		<author>peterd</author>
		<pubDate>Fri, 04 Apr 2008 21:21:29 +0000</pubDate>
		<guid>http://blog.flexexamples.com/2008/01/11/displaying-the-number-of-children-in-each-branch-of-a-flex-tree-control/#comment-10087</guid>
		<description>Dusan,

Something like this?
&lt;pre class="code"&gt;
&#60;mx:XML id="treeDP"&#62;
    &#60;root&#62;
        &#60;node label="i) One" /&#62;
        &#60;node label="i) Two" /&#62;
        &#60;node label="i) Three" /&#62;
        &#60;node label="i) Four"&#62;
            &#60;node label="ii) One" /&#62;
            &#60;node label="ii) Two" /&#62;
            &#60;node label="ii) Three"&#62;
                &#60;node label="iii) One" /&#62;
                &#60;node label="iii) Two" /&#62;
            &#60;/node&#62;
            &#60;node label="ii) Four" /&#62;
        &#60;/node&#62;
        &#60;node label="i) Five" /&#62;
        &#60;node label="i) Six" /&#62;
    &#60;/root&#62;
&#60;/mx:XML&#62;

&#60;mx:ComboBox id="checkBox"
        dataProvider="{treeDP..node.(children().length() != 0)}"
        labelFunction="comboBox_labelFunc" /&#62;

&#60;mx:Script&#62;
    &#60;![CDATA[
        private function comboBox_labelFunc(item:XML):String {
            var numChildren:int = item.children().length();
            var suffix:String = "";
            if (numChildren != 0) {
                suffix = " (" + numChildren + ")";
            }  
            return item.@label + suffix;
        }
    ]]&#62;
&#60;/mx:Script&#62;
&lt;/pre&gt;

Peter</description>
		<content:encoded><![CDATA[<p>Dusan,</p>
<p>Something like this?</p>
<pre class="code">
&lt;mx:XML id="treeDP"&gt;
    &lt;root&gt;
        &lt;node label="i) One" /&gt;
        &lt;node label="i) Two" /&gt;
        &lt;node label="i) Three" /&gt;
        &lt;node label="i) Four"&gt;
            &lt;node label="ii) One" /&gt;
            &lt;node label="ii) Two" /&gt;
            &lt;node label="ii) Three"&gt;
                &lt;node label="iii) One" /&gt;
                &lt;node label="iii) Two" /&gt;
            &lt;/node&gt;
            &lt;node label="ii) Four" /&gt;
        &lt;/node&gt;
        &lt;node label="i) Five" /&gt;
        &lt;node label="i) Six" /&gt;
    &lt;/root&gt;
&lt;/mx:XML&gt;

&lt;mx:ComboBox id="checkBox"
        dataProvider="{treeDP..node.(children().length() != 0)}"
        labelFunction="comboBox_labelFunc" /&gt;

&lt;mx:Script&gt;
    &lt;![CDATA[
        private function comboBox_labelFunc(item:XML):String {
            var numChildren:int = item.children().length();
            var suffix:String = "";
            if (numChildren != 0) {
                suffix = " (" + numChildren + ")";
            }
            return <a href="mailto:item.@label">item.@label</a> + suffix;
        }
    ]]&gt;
&lt;/mx:Script&gt;
</pre>
<p>Peter</p>
]]></content:encoded>
	</item>
</channel>
</rss>
