Hello Stackoverflowers,
i'm creating a reusable flex tree component. And i would like to stick in the itemclick funtion. So that when a user clicks anywhere on one of the tree's Branches. the branch expands. My problem is that i don't know how i can get the listener function to fire. What i would like to do is create the tree completely in as3. (no mxml). Normaly i set the itemClick on tree in the mxml. but i want to do this in as3. My component has alot more functions in it but i have deleted them so that it becomes easier to read.
Can anyone help me out on this one? I Thought if i override the createChilderen function and add the eventlistener in there, that i would work. But no luck.
this is my code;
package
{
import mx.controls.Tree;
import mx.controls.listClasses.IListItemRenderer;
import mx.events.ItemClickEvent;
import mx.events.ListEvent;
public class MyTree extends Tree
{
public function MyTree()
{
super();
}
private function tree_itemClick(evt:ListEvent):void {
var item:Object = Tree(evt.currentTarget).selectedItem;
if (dataDescriptor.isBranch(item)) {
expandItem(item, !isItemOpen(item), true);
}
}
override protected function createChildren():void{
super.createChildren();
addEventListener(ListEvent.ITEM_CLICK, tree_itemClick, true);
}
}
}
DJ