The following example shows how you can use
Isbranch ()
Method to determine if a specific node in a tree control is a branch (folder) or leaf (item ). <? XML version = "1.0" encoding = "UTF-8" ?>
<! -- Http://blog.flexexamples.com/2007/11/30/using-the-isbranch-method-to-determine-if-a-tree-item-is-a-branch-or-leaf/ -->
< MX: Application Xmlns: MX = "Http://www.adobe.com/2006/mxml"
Layout = "Vertical"
Verticalalign = "Middle"
Backgroundcolor = "White" >
mx: script >
Import MX. Events. listevent;
Private function tree_itemclick (EVT: listevent): void {
VaR itemisbranch: Boolean = tree. datadescriptor. isbranch (tree. selecteditem );
LBL. Text = itemisbranch. tostring ();
}
Private function tree_labelfunc (item: XML): String {
VaR returnstr: String = item. @ label;
VaR itemisbranch: Boolean = tree. datadescriptor. isbranch (item );
If (itemisbranch ){
Returnstr + = "(Branch )";
}
Return returnstr;
}
]>
</ MX: script >
< MX: XML ID = "Xmldp" >
< Node >
< Node Label = "1.a" />
< Node Label = "1. B" />
< Node Label = "1.c" >
< Node Label = "1. c. I" />
< Node Label = "1. C. II" />
< Node Label = "1. C. III" />
< Node Label = "1. C. IV" />
< Node Label = "1. C. V" />
</ Node >
< Node Label = "1.d" />
< Node Label = "1.e" >
< Node Label = "1. e. I" />
< Node Label = "1. E. II" />
< Node Label = "1. E. III" >
< Node Label = "1. E. III." />
</ Node >
< Node Label = "1. E. IV" />
</ Node >
< Node Label = "1.f" />
</ Node >
</ MX: XML >
< MX: applicationcontrolbar Dock = "True" >
< MX: Form Stylename = "Plain" >
< MX: formitem Label = "Isbranch ():" >
< MX: Label ID = "LBL" Fontweight = "Bold" />
</ MX: formitem >
</ MX: Form >
</ MX: applicationcontrolbar >
< MX: Tree ID = "Tree"
Dataprovider = "{Xmldp }"
Labelfunction = "Tree_labelfunc"
Showroot = "False"
Width = "50%"
Rowcount = "6"
Itemclick = "Tree_itemclick (event );" />
</MX: Application>