本文介绍了如何设置重点在TLFTextField的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

像标题所说的那样。如何在运行时设置TLFTextField的焦点?



我已经做了一些研究,并且找到了一些像这样回答的问题,如



如何设置焦点到TLFTextfield对象

在几个论坛上,他们说使用这个代码

  stage.focus = txt; 

  txt.stage.focus = txt; 

  txt.textFlow.interactionManager.setFocus(); 

但是没有为我工作..我会尝试简单的项目,仍然失败..



我需要用 TLFTextField 显示 MovieClip 所以用户只需键入编辑TLFTextfield即可。



我的代码:

  public function TFLayer(){
tf = new TLFTextField();
tf.width = 400;
tf.height = 30;
tf.x = 300;
tf.y = 300;
tf.border = true;
tf.type = TextFieldType.INPUT;
tf.backgroundColor = 0xffffff;
tf.text =Lorem ipsum;
addChild(tf);

tf.textFlow.interactionManager.setFocus();


解决方案

$ c> TLFTextField 命名为 tf ,您可以启用焦点:

  import flashx.textLayout.edit.EditManager; 

tf.textFlow.interactionManager = new EditManager();
tf.textFlow.interactionManager.selectRange(0,0);
tf.textFlow.interactionManager.setFocus();

使用此方法,文本字段已准备好接收来自键盘的输入;但是,光标不会闪烁。因此,没有可见的焦点指示。
$ b

TLFTextFields 对用户输入不是最佳的。考虑使用 TextField TextArea 来代替。


like the title said. How to set focus on TLFTextField on runtime?

I already do some research and find a few question answered in SO like this How to set focus to a TLFTextfield object

And on few forum, they said to use this code

stage.focus = txt;

or

txt.stage.focus = txt;

or

txt.textFlow.interactionManager.setFocus();

But none works for me.. I'd try on simple project and still failed..

I need to show a MovieClip with a TLFTextField and focus on it.. So user can just type to edit the TLFTextfield.

my code:

public function TFLayer() {
    tf = new TLFTextField();
    tf.width = 400;
    tf.height = 30;
    tf.x = 300;
    tf.y = 300;
    tf.border = true;
    tf.type = TextFieldType.INPUT;
    tf.backgroundColor = 0xffffff;
    tf.text = "Lorem ipsum";
    addChild(tf);

    tf.textFlow.interactionManager.setFocus();
}
解决方案

Given an editable TLFTextField named tf, you can enable focus with:

import flashx.textLayout.edit.EditManager;

tf.textFlow.interactionManager = new EditManager();
tf.textFlow.interactionManager.selectRange(0, 0);
tf.textFlow.interactionManager.setFocus();

Using this method, the text field is focused ready to receive input from the keyboard; however, the cursor will not blink. Therefore, there's no visual indication of focus.

TLFTextFields are not optimal for user input. Consider using TextField or TextArea instead.

这篇关于如何设置重点在TLFTextField的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-09 21:36