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);
        }
    }
}
 
         加载中,请稍侯......
 加载中,请稍侯......
      
精彩评论