Question

I am developing Flash Builder application that has ColorPicker component. When the ColorPicker has focus and I press left of right arrow from keyboard, the color changes.

Documentation from there says that this is a default behavior for the ColorPicker:

When the swatch panel is closed, but has the focus, pressing the Up and Down arrow keys has no effect. The Left and Right Arrow keys change the color picker selection, moving through the colors as if the panel were open.

Unfortunately, set focus to false doesn't help. Is there a way to avoid changing color using keyboard arrows?

Thank you.

Was it helpful?

Solution

Flex components that support keyboard navigation override a protected method called keyDownHandler() that is defined by UIComponent. There is also a keyUpHandler() method, but you typically only need to use one or the other.

In this case, the ColorPicker component overrides keyDownHandler(). It's quite long, you can see it in the Apache Flex github repo on line 1436.

You create a custom color picker class that overrides this method and does not call the super class method if the arrow keys are pressed:

override protected function keyDownHandler(event:KeyboardEvent):void
{
    var keyCode:uint = event.keyCode;
    // don't call the super class for these keys
    if ( !(keyCode == Keyboard.LEFT || keyCode == Keyboard.RIGHT) )
    {
        super.keyDownHandler(event);
    }
}

Note, this is untested, you might need more logic than this to make it work properly. I recommend inspecting the super class method ;)

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top