The following example shows you how you can preventAnyItem from being selected by adding an attribute (named "clickable", but you cocould name it anything you wanted) and using E4X expressions to determine if the currently clicked item shocould be selectable or not.
Full code after the jump.
Note that in the following example, items with the "(x)" suffix are not-selectable, only the following nodes shocould be selectable: "grandchild 1", "grandchild 2 ″, and "child 4 ″.
<? XML version = "1.0" encoding = "UTF-8" ?>
<! -- Http://blog.flexexamples.com/2008/01/16/preventing-specific-items-from-being-selected-in-a-flex-tree-control/ -->
< MX: Application Xmlns: MX = "Http://www.adobe.com/2006/mxml"
Layout = "Vertical"
Verticalalign = "Middle"
Backgroundcolor = "White"
Creationcomplete = "Init ();" >
<MX: script>
<! [CDATA [
Import MX. Events. listevent;
Private function Init (): void {
Tree. openitems = DP... node;
}
Private function tree_itemclick (EVT: listevent): void {
VaR item: Object = EVT. currenttarget. selecteditem;
VaR nonselectable: Boolean = (item. hasownproperty ("@ clickable") & (item. (@ clickable = "false ")));
If (nonselectable ){
Tree. selecteditem = NULL;
}
}
]>
</ MX: script >
< MX: XML ID = "DP" >
< Root >
< Node Label = "Parent 1 (x )" Clickable = "False" >
< Node Label = "CHILD 1 (x )" Clickable = "False" />
< Node Label = "Child 2 (x )" Clickable = "False" >
< Node Label = "Grandchild 1" />
< Node Label = "Grandchild 2" />
</ Node >
< Node Label = "Child 3 (x )" Clickable = "False" />
< Node Label = "Child 4" />
</ Node >
</ Root >
</ MX: XML >
< MX: Tree ID = "Tree"
Dataprovider = "{DP }"
Showroot = "False"
Labelfield = "@ Label"
Width = "200"
Itemclick = "Tree_itemclick (event );" />
</MX: Application>