闪存AS3:ENTER不会被检测到,但Ctrl + Enter优良工程 [英] Flash AS3: ENTER does not get detected, but CTRL+ENTER works fine
问题描述
在我的重点是输入文本字段中,pressing CTRL + ENTER
的作品,但 ENTER
做不是。
When my focus is inside the input text field, pressing CTRL+ENTER
works but ENTER
does not.
pressing 输入
时,我的重点是任何地方,但在输入文本字段工作得很好。
Pressing Enter
when my focus is anywhere BUT the input text field works just fine..
我的目的是检测是否 ENTER
键pressed用户填写后场,但它似乎只对 Ctrl + Enter
My intention is to detect if ENTER
key was pressed after the user fills out the field, but it seems to only work for CTRL+ENTER
的ActionScript 3
// works:
stage.addEventListener(KeyboardEvent.KEY_DOWN, enterHandler);
// ignored:
email.addEventListener(KeyboardEvent.KEY_DOWN, enterHandler);
function enterHandler(event:KeyboardEvent):void{
if(event.keyCode == Keyboard.ENTER ){
email.text = 'Thanks!';
}
}
ENTER
结果的字符code 的== 0,而 Ctrl + Enter
是字符code 的== 13
ENTER
results in charCode == 0, whereas CTRL+ENTER
is charCode == 13
电子邮件
使用文本工具创建并设置为可编辑
email
was created using the Text tool and set to "Editable"
注意:我测试在Chrome和Firefox运行Flash V10
Note: I am testing in Chrome and Firefox running Flash v10
推荐答案
我假设你正在调试你的日常生活工作(控制>测试影片>在Flash Professional 的)?这里的问题是,键盘快捷键有precedence在键盘事件和回车键是键盘快捷键的控制>播放的在控制的菜单,而你是测试你的电影。
i'm assuming you're debugging your work in ADL (Control > Test Movie > in Flash Professional)? the problem here is that the keyboard shortcuts have precedence over keyboard events and the enter key is the keyboard shortcut for Control > Play in the Control menu while you are testing your movie.
然而,这是可能的,很容易禁用快捷键,同时测试你的电影。当你的影片播放,转到 控制>禁用快捷键的。现在你的键盘事件,回车键将正确执行。
however, it's possible and very easy to disable the keyboard shortcuts while testing your movie. when your movie is playing, goto Control > Disable Keyboard Shortcuts. now your keyboard event for the enter key will execute properly.
哦,你应该使用 event.key code
而不是 event.char code
。
oh, and you should use event.keyCode
instead of event.charCode
.
好吧,如果你想输入的键盘事件,火灾,当你正在里面输入文本字段,你只需要TextEvent,并将监听器添加到文本字段:
ok, if you want Enter keyboard event to fire when your currently inside an input TextField, you simply have to add TextEvent listener to the TextField:
import flash.events.TextEvent;
import flash.text.TextField;
import flash.text.TextFieldAutoSize;
import flash.text.TextFieldType;
var tf:TextField = new TextField();
tf.border = true;
tf.multiline = true; //Must be set to true for the textField to accept enter key
tf.type = TextFieldType.INPUT;
tf.width = 200;
tf.height = 20;
tf.addEventListener(TextEvent.TEXT_INPUT, keyboardReturnHandler);
function keyboardReturnHandler(evt:TextEvent):void
{
if (evt.text == "\n")
{
evt.preventDefault();
trace("text field enter");
}
}
addChild(tf);
这篇关于闪存AS3:ENTER不会被检测到,但Ctrl + Enter优良工程的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!