开发者

flex tree itemclick event, doesn't work

开发者 https://www.devze.com 2023-01-20 23:05 出处:网络
I\'m creating a reusable flex tree component. And i would like to stick in the itemclick function. So that when a user clicks anywhere on one of the tree\'s Branches. the branch expands.

I'm creating a reusable flex tree component. And i would like to stick in the itemclick function. 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). Normally I set the itemClick on tree in the mxml. but I want to do this in as3. My component has a lot 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 it 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.createChil开发者_如何学JAVAdren();
            addEventListener(ListEvent.ITEM_CLICK, tree_itemClick, true);
        }

    }
}


package
{
import mx.controls.Tree;
import mx.events.ListEvent;

public class MyTree extends Tree
{
    public function MyTree()
    {
        super();

        addEventListener(ListEvent.ITEM_CLICK, itemClickHandler);
    }

    private function itemClickHandler(event:ListEvent):void
    {
        trace("Success");
    }

}
}
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号