2

I am using Flash CS5 and ActionScript 3.

I need to dynamically (in response to an event) flip the wordWrap property of a TLFTextField from true to false and vice versa. I had it working with the old TextField class, but I I can't get it to work with TLF.

I declare my field and set it up like so, with wordWrap set to 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();

To change the word wrapping, I've tried the following:

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

But this has no effect - the text stays wrapped. Can anyone tell me what I'm missing?

Thanks in advance,

Amanda

Amanda_A
  • 323
  • 1
  • 3
  • 10

2 Answers2

2

to change wordwrap to false, there has to be text set. ( i needed about half an hour to get it working!)

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

this following should work:

if(field.text == ""){

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

} else {

  field.wordWrap = false;

}

trace(field.wordWrap); // should echo false
  • 1
    You're lucky - I spent the last 5 hours banging my head against the wall over this. It doesn't quite work the way you described it in your answer, though: **Everytime** you set the `text` or `htmlText` properties, the value is reset to `true`- so the only way to set `wordWrap` to `false` is *after* setting the text you actually want the field to contain. This sucks so bad, it's hard to find the words to describe it... but then again, TLFTextField is a horrible sucker, anyway. – weltraumpirat Oct 21 '12 at 20:42
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.

kachingy123
  • 197
  • 1
  • 12
  • Thanks for catching the missing parenthesis - not sure how I managed to forget those! I just tried it again with the parenthesis and it didn't change anything. Unfortunately I need the AutoSize.LEFT, but I did try commenting that out and the word wrap still doesn't change. I will try posting it as a possible bug to Adobe if no one can figure it out. – Amanda_A Mar 19 '11 at 13:19