2

我正在使用 Adob​​e Flash Builder 4.6 构建一个移动 AIR 应用程序(Android 和 IOS),我遇到了这个烦人的问题。

因为我想在 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();
}

现在在其他地方 - 嵌套在某些类中 - 我有一个文本字段:

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

但是当我将焦点放在文本字段上时,确实会出现软键盘,但我无法输入单个字符。当我禁用 keylistener 时:没问题。

似乎听众正在覆盖我的输入字段。有什么解决方法吗?

4

1 回答 1

3

我还为我的移动应用程序实现了后退按钮功能,但我过去只在我的特定视图被激活时注册 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();
}

希望这可以帮助你。

于 2013-03-21T19:08:37.740 回答