Search code examples
actionscript-3apache-flextabnavigator

FLEX - Disable spacebar


I've got an application, which is tabbed (using TabNavigator).

When it starts, I switch tab to nr.2 (default is tab 1). I need to be able to hold down spacebar and drag the mouse to pan, but when I do this it switches back to the first tab. So the spacebar is triggering it to switch.

I've tried using a custom lass that extends tabNavigator, like the code below, but it's not working. Also tried setting focusEnabled = false without luck.

Any idea how I would solve this?

Thanks a lot in advance, Stian Berg Larsen

package components
{
import mx.containers.TabNavigator;
import flash.events.KeyboardEvent;

public class myTabNavigator extends TabNavigator
{
    public function myTabNavigator()
    {
        super();
    }

    protected override function keyDownHandler(e : KeyboardEvent) : void {
        if (e.keyCode == 32) { // Spacebar
            return;
        }
        super.keyDownHandler(e);
    }

}

}


Solution

  • That is probably caused because you are not stopping your event from bubbling.

    Try this:

    protected override function keyDownHandler(e : KeyboardEvent) : void {
        if (e.keyCode == 32) { // Spacebar
            e.preventDefault();
            e.stopImmediatePropagation();
            return;
        }
        super.keyDownHandler(e);
    }