actionscript-3 - 有没有办法禁用 ColorPicker 的左/右键盘箭头?

标签 actionscript-3 apache-flex flash-builder flex4.5 flexbuilder

我正在开发具有 ColorPicker 组件的 Flash Builder 应用程序。当 ColorPicker 获得焦点并且我按下键盘上的向左或向右箭头时,颜色会发生变化。

文档来自 there表示这是 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.

不幸的是,将焦点设置为 false 没有帮助。 有没有办法避免使用键盘箭头更改颜色?

谢谢。

最佳答案

支持键盘导航的 Flex 组件会覆盖 UIComponent 定义的名为 keyDownHandler() 的 protected 方法。还有一个 keyUpHandler() 方法,但您通常只需要使用一个或另一个。

在这种情况下,ColorPicker 组件会覆盖 keyDownHandler()。挺长的,可以在Apache Flex github repo里面看到在第 1436 行。

您创建一个自定义颜色选择器类来覆盖此方法,并且在按下箭头键时不调用父类(super class)方法:

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

请注意,这是未经测试的,您可能需要比这更多的逻辑才能使其正常工作。我建议检查父类(super class)方法;)

关于actionscript-3 - 有没有办法禁用 ColorPicker 的左/右键盘箭头?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19090427/

相关文章:

apache-flex - flex中有 sleep 功能吗?

linux - 使用 FB4Linux 编译 AIR 应用程序不起作用

actionscript-3 - 为什么要使用自定义事件而不是直接方法调用?

css - 覆盖 Flex 控件的标签级外部 CSS

apache-flex - 无法解析 <s :Sequence> to a component implementation after adding AIR 3. 6

actionscript-3 - Flex Printjob崩溃

windows - 你能得到 NativeWindow 的最小化事件吗?

actionscript-3 - TextField() - 如何防止鼠标选择

actionscript-3 - 在 Flash AS3 中嵌入 YouTube 视频时缺少操作栏

flash - ActionScript 编译器