Flex树空间默认事件监听器

时间:2010-10-07 10:44:48

标签: flex events flex3 tree

我注意到当我选择树节点时,如果单击空格,则会打开所选节点...我该如何删除此事件?

1 个答案:

答案 0 :(得分:1)

看起来没有办法防止这个事件,如果有一个我不确定它是明智的,因为Tree的keyDownHandler比打开节点做的多一点。

我通过创建自定义树来解决它。遗憾的是,我不得不从Tree的keyDownHandler中复制几行代码。

public class MyTree extends Tree
{
    override protected function keyDownHandler(event:KeyboardEvent):void
    {
        if (event.keyCode == Keyboard.SPACE)
        {
            // Code copied from Tree's keyDownHandler

            // if user has moved the caret cursor from the selected item
            // move the cursor back to selected item
            if (caretIndex != selectedIndex)
            {
                // erase the caret
                var renderer:IListItemRenderer = indexToItemRenderer(caretIndex);

                if (renderer)
                    drawItem(renderer);
                caretIndex = selectedIndex;
            }

            event.stopImmediatePropagation();
        }
        else
        {
            super.keyDownHandler(event);
        }
    }
}