AIR / AS3阶段的KeyListener覆盖输入文本框

编程入门 行业动态 更新时间:2024-10-28 10:21:54
本文介绍了AIR / AS3阶段的KeyListener覆盖输入文本框的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我要建一个移动AIR应用程序(Android的&安培; IOS)与Adobe Flash Builder中4.6和我有这个恼人的问题。

I'm building a mobile AIR app (Android & IOS) with Adobe Flash Builder 4.6 and I'm having this annoying problem.

由于我要'抓'我增加了以下code到我的主类在Android设备背面键:

Because I want to 'catch' the back-key on Android devices I added the following code to my main class:

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

现在别的地方 - 嵌套在一些类 - 我有一个文本框:

Now somewhere else - nested in some classes - I've got a textfield:

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

但是,当我把重点放在软键盘也出现在文本字段,但是我不能键入单个字符。当我禁用的KeyListener:没问题

But when I set focus on the textfield the soft keyboard does appear, but I can't type a single character. When I disable the keylistener: no problem.

好像监听器重写我的输入字段。有没有什么解决办法对此怎么看?

Seems like the listener is overriding my input field. Is there any workaround on this?

推荐答案

我也实现了我的移动应用程序的后退按钮功能,但我用注册keydown事件,只有当我的特定视图被激活,并取消注册时,视图得到解除。

I have also implemented the back button functionality for my mobile apps , but i used to register keydown event only when my particular view is activated and removed the registered when view get deactivated.

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

愿这可以帮助你。

May this can help you.

更多推荐

AIR / AS3阶段的KeyListener覆盖输入文本框

本文发布于:2023-11-23 14:57:13,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1621865.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:文本框   阶段   AIR   KeyListener

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!