删除 Flash 滑块组件上的键盘控制

发布于 2024-10-31 00:47:45 字数 60 浏览 1 评论 0原文

默认情况下,可以使用键盘操作 Flash 滑块组件。有没有办法禁用此行为,以便用户只能用鼠标拖动滑块组件?

by default the flash slider component can be manipulated with the keyboard. Is there a way to disable this behavior so that users can only drag the slider component with their mouse?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

风筝有风,海豚有海 2024-11-07 00:47:45

很简单,只需将“Slider”对象的“focusEnabled”公共属性设置为 false:

import fl.controls.Slider;

var slider:Slider = new Slider();
addChild(slider);

slider.focusEnabled = false; 

这将表明“Slider”对象在用户单击它后无法接收焦点,因此不允许键盘与其交互。

Simple, just set the 'focusEnabled' public property of the 'Slider' object to false:

import fl.controls.Slider;

var slider:Slider = new Slider();
addChild(slider);

slider.focusEnabled = false; 

This will indicate that the 'Slider' object can't recieve focus after the user clicks on it and therefore not allow the keyboard to interact with it.

卷耳 2024-11-07 00:47:45

正如@Taurayi 和@Grant 提到的,改变焦点很简单。

这是一种更肮脏的方法,可以做同样的事情:

slider.addEventListener(FocusEvent.FOCUS_IN, onFocus);
function onFocus(event:FocusEvent):void {
    stage.focus = null;
}

尽管 slider.focusEnabled = false; 更简单。

这是一种更肮脏的方法:

import flash.sampler.getMemberNames;

removeKeyboardListeners(slider);

function removeKeyboardListeners(dispatcher:EventDispatcher):void{
    var members:Object=getMemberNames(dispatcher);
    for each (var name:QName in members) {
        if (name.localName=="listeners") {
            var numListeners:int = dispatcher[name].length;
            for(var i:int = 0 ; i < numListeners ; i++){
                try{
                    try{
                        if(dispatcher[name][i]){
                            dispatcher.removeEventListener(KeyboardEvent.KEY_DOWN,dispatcher[name][i]);
                            dispatcher.removeEventListener(KeyboardEvent.KEY_UP,dispatcher[name][i]);
                        }
                    }catch(e:Error){trace(e.message);}
                }catch(e:ReferenceError){}
            }
        }
    }
}

如果您想要一种冗长但不那么肮脏的方法,只需将 fl.controls.Slider 子类化并将其设置为库中 Slider 符号的类即可。在您的子类中,您将添加:

override protected function keyDownHandler(event:KeyboardEvent):void {}

keyDownHandler 继承自 fl.core.UIComponent 并在 Slider.as 中继承,因为它处理键盘更新。

华泰

As @Taurayi and @Grant mentioned, changing focus would be the simples.

Here's a dirtier way of doing somewhat the same:

slider.addEventListener(FocusEvent.FOCUS_IN, onFocus);
function onFocus(event:FocusEvent):void {
    stage.focus = null;
}

Although slider.focusEnabled = false; is much simpler.

Here's an even dirtier way:

import flash.sampler.getMemberNames;

removeKeyboardListeners(slider);

function removeKeyboardListeners(dispatcher:EventDispatcher):void{
    var members:Object=getMemberNames(dispatcher);
    for each (var name:QName in members) {
        if (name.localName=="listeners") {
            var numListeners:int = dispatcher[name].length;
            for(var i:int = 0 ; i < numListeners ; i++){
                try{
                    try{
                        if(dispatcher[name][i]){
                            dispatcher.removeEventListener(KeyboardEvent.KEY_DOWN,dispatcher[name][i]);
                            dispatcher.removeEventListener(KeyboardEvent.KEY_UP,dispatcher[name][i]);
                        }
                    }catch(e:Error){trace(e.message);}
                }catch(e:ReferenceError){}
            }
        }
    }
}

And if you want a lengthy, but less dirty way, simply subclass fl.controls.Slider and set that as the class for the Slider symbol in your library. In your subclass you would add:

override protected function keyDownHandler(event:KeyboardEvent):void {}

keyDownHandler is inherited from fl.core.UIComponent and in Slider.as it handles the keyboard updates.

HTH

花伊自在美 2024-11-07 00:47:45

添加:

 stage.focus = stage;

到 SliderEvent.CHANGE 处理程序

这会将焦点转移到舞台,从而禁用滑块上的键盘活动。

Add:

 stage.focus = stage;

To the SliderEvent.CHANGE handler

This will shift focus to the stage, and therefore disable keyboard activity on the slider.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文