AIR/as3 stage keylistener覆盖输入文本域



我正在构建一个移动AIR应用程序(Android &IOS)与Adobe Flash Builder 4.6,我有这个恼人的问题。

因为我想在Android设备上"捕捉"回键,所以我在主类中添加了以下代码:

stage.addEventListener(KeyboardEvent.KEY_DOWN, keyDown);
private function keyDown(k:KeyboardEvent):void {    
if(k.keyCode == Keyboard.BACK) {
    backClicked(); // function handling the back-action, not important 
    k.preventDefault();
}

现在在其他地方-嵌套在一些类-我有一个textfield:

TF = new TextField();
TF.type = TextFieldType.INPUT;

但是当我在文本框上设置焦点时,软键盘确实出现了,但我不能输入一个字符。当我禁用keylistener: no problem.

似乎侦听器重写了我的输入字段。有什么解决办法吗?

我也为我的移动应用程序实现了后退按钮功能,但我过去只在我的特定视图被激活时注册keydown事件,并在视图被停用时删除注册的

in <s:view ....... viewActivate ="enableHardwareKeyListeners(event)" viewDeactivate="destroyHardwareKeyListeners(event)">
// add listener only for android device
if (Check for android device) {
    NativeApplication.nativeApplication.addEventListener(KeyboardEvent.KEY_DOWN, handleHardwareKeysDown, false, 0);
    NativeApplication.nativeApplication.addEventListener(KeyboardEvent.KEY_UP, handleHardwareKeysUp, false, 0); 
    this.setFocus();                    
}

private function destroyHardwareKeyListeners(event:ViewNavigatorEvent):void
{
    if (NativeApplication.nativeApplication.hasEventListener(KeyboardEvent.KEY_DOWN))
        NativeApplication.nativeApplication.removeEventListener(KeyboardEvent.KEY_DOWN, handleHardwareKeysDown);
    if (NativeApplication.nativeApplication.hasEventListener(KeyboardEvent.KEY_UP))
        NativeApplication.nativeApplication.removeEventListener(KeyboardEvent.KEY_UP, handleHardwareKeysUp);
}
private function handleHardwareKeysDown(e:KeyboardEvent):void
{
    if (e.keyCode == Keyboard.BACK) {
        e.preventDefault();
        // your code
    } else {
    }
}           
private function handleHardwareKeysUp(e:KeyboardEvent):void
{
    if (e.keyCode == Keyboard.BACK)
        e.preventDefault();
}

最新更新