开发者

Flex tree space default event listener

I have noticed that when I select tree node if space is clicked the selected nod开发者_C百科e gets opened... how could I remove this event?


It doesn't look like there's a way to prevent the event and if there is one I'm not sure it's wise since the Tree's keyDownHandler does a little bit more than just opening the node.

I solved it by creating a custom Tree. Sadly I had to copy a few lines of code from the Tree's 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);
        }
    }
}
0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜