2

我正在使用 Flash CS5 和 ActionScript 3。

我需要动态(响应事件)将 TLFTextField 的 wordWrap 属性从 true 翻转为 false,反之亦然。我让它与旧的 TextField 类一起使用,但我无法让它与 TLF 一起使用。

我声明我的字段并像这样设置它,将 wordWrap 设置为 true:

this.field = new TLFTextField;
field.multiline = true;
field.wordWrap = true;
field.autoSize = TextFieldAutoSize.LEFT;

field.tlfMarkup = my_content;

this.addChild(field);
var myTextFlow:TextFlow = field.textFlow;
myTextFlow.hostFormat = format; //format is a TextLayoutFormat declared earlier
myTextFlow.flowComposer.updateAllControllers();

要更改自动换行,我尝试了以下方法:

field.wordWrap = false;
field.multiline = false;
var myTextFlow:TextFlow = field.textFlow;
myTextFlow.flowComposer.updateAllControllers();

但这没有任何效果 - 文本保持换行。谁能告诉我我错过了什么?

提前致谢,

阿曼达

4

2 回答 2

2

要将 wordwrap 更改为 false,必须设置文本。(我需要大约半小时才能让它工作!)

field.wordWrap = false;
trace(field.wordWrap); // will echo true

以下应该有效:

if(field.text == ""){

  field.text = "a";
  field.wordWrap = false;
  field.text = "";

} else {

  field.wordWrap = false;

}

trace(field.wordWrap); // should echo false
于 2011-08-12T07:22:57.977 回答
0

First off, have you tried: this.field = new TLFTextField();

You didn't have the parenthesis.

At least worth a look at. (Also I believe this is Beta currently so there is a possibility of a bug?)

Finally, you might consider testing this without the AutoSize... sometimes causes problems.

Sorry that I can't be a little more helpful with an exact solution.

于 2011-03-17T21:01:46.897 回答