我正在开发具有 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/