2013-03-21 37 views
2

我建立一個移動AIR應用程式(Android & IOS),我有這個惱人的問題。AIR/AS3階段的KeyListener覆蓋與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(); 
} 

現在別的地方 - 嵌套在一些類 - 我有一個文本框:

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

但是,當我將焦點放在文本字段上時,軟鍵盤確實出現,但我無法鍵入單個字符。當我禁用keylistener時:沒問題。

好像監聽器重寫我的輸入字段。有沒有解決這個問題的方法?

+0

拋出一個代碼打入'keyDown'功能,做一個基於設備的調試和複製你的過程中獲得的bug。看看它是否註冊'k.keyCode'作爲後退按鈕。如果是這樣,你需要弄清楚爲什麼。如果是這種情況,您可能在AIR SDK中發現了一個錯誤。 – 2013-03-21 18:01:36

回答

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(); 
} 

願這可以幫助你。

+1

是的,我與事件的類似的解決方法: \t this.addEventListener(GtpEvent.TF_FOCUS,TFFocus); this.addEventListener(GtpEvent.TF_NOFOCUS,TFUnfocus); \t \t \t 私有函數TFFocus(克:GtpEvent):無效{ \t stage.removeEventListener(KeyboardEvent.KEY_DOWN,的keyDown); } \t \t 私有函數TFUnfocus(克:GtpEvent):無效{ \t stage.addEventListener(KeyboardEvent.KEY_DOWN,的keyDown); } – 2013-03-26 14:02:08