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?
3 Answers
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.

- 3,209
- 2
- 17
- 15
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

- 50,687
- 19
- 144
- 218
Add:
stage.focus = stage;
To the SliderEvent.CHANGE handler
This will shift focus to the stage, and therefore disable keyboard activity on the slider.

- 4,578
- 5
- 37
- 59