如何在没有舞台引用的情况下设置输入文本字段的焦点?
我有一个文本输入字段:
var textfield:TextField = new TextField();
textfield.text = "";
textfield.type = TextFieldType.INPUT;
addChild(textfield);
因为这个文本字段不驻留在主类中,所以我没有执行以下操作的阶段参考:
textfield.stage.focus = textfield;
or
stage.focus = textfield
如何强制文本字段在位置零处显示闪烁行?
I got a text-InputField:
var textfield:TextField = new TextField();
textfield.text = "";
textfield.type = TextFieldType.INPUT;
addChild(textfield);
because this textfield don't reside in the main-class, I don't have a stage-reference for doing:
textfield.stage.focus = textfield;
or
stage.focus = textfield
How can I force the textfield to display the blinking line at position zero?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
您可以在主类中添加对舞台的静态引用,并通过它设置焦点(或创建一个专用类以在任何位置获取舞台引用)。
主类代码:
Textfield 类代码:
You can add a static reference to the stage in your main class and set focus through it (or create a dedicaced class to get stage reference wherever you are).
Main class code :
Textfield class code :
这是一种 Flash 播放器错误,因为如果您使用 stage.focus=textfield 设置焦点,则文本字段实际上具有焦点(您可以写一些东西),但没有闪烁的光标。另一方面,只有当您在播放器(而不是浏览器)中本地启动 swf 时,才会出现闪烁的光标。
为了告诉人们他们现在可以写一些东西,您可以自己制作一个光标 - 只需创建一条线,为其设置动画并在有人写下第一个字母时隐藏。
It's sort of a flash player bug, because if you set focus with stage.focus=textfield, textfield actually has focus (you can write something), but there is no blinking cursor. On the other hand, there is a blinking cursor, but only when you launch swf locally in player (not in browser).
To inform people that they can write something right now, you can make a cursor by yourself - just create a line, animate it and hide when someone writes a first letter.
光标焦点有时确实有效,这更令人沮丧。我有两个几乎相同的应用程序遇到这种情况。不起作用的那个有一个正在运行的动画。这可能是一个冲突。
The cursor focus does work sometimes, which is all the more frustrating. I have this situation with two almost identical apps. The one that doesn't work has an animation running. It may be a conflict.
最后我得到了解决方案
尝试这个代码它会工作
你必须命名文本字段然后你可以轻松使用它
Finally I got the solution
try this code it will work
you have to name the textfield then you can use it easily