views:

16

answers:

1

I have noticed that when I select tree node if space is clicked the selected node gets opened... how could I remove this event?

+1  A: 

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);
        }
    }
}
Gerhard