0

We have a library with a bunch of TextFields inside MovieClips. During runtime, we make an instance of one of these, run getTextFormat on it to get the formatting, then create a bunch of TextFields in code and run setTextFormat on them to give them the same formatting.

I'm trying to do the same thing but with TLFTextFields. I have the following:

var text:TLFTextField = new classFromLib();
text.selectable = true; //required for getTextFormat to work, flash bug
textFormat = text.getTextFormat();
text.selectable = false; // set it back to false

The problem now is textFormat.leading is -2147483648, and textFormat.letterSpacing is NaN. This produces the following 2 runtime errors respectively when running text.setTextFormat(textFormat):

Property lineHeight value -2147483648 is out of range

Property trackingRight value NaN is out of range

If I set textFormat.leading and textFormat.letterSpacing to null before I run setTextFormat, then everything works, but obviously the text fields don't get the leading and letter spacing that the one in the library had. This is a problem, as I need those 2 properties. Anyone know a way around this?

  • What is "classFromLib()"? Is it a movieclip or a TLFTextField? Can you try setting textFormat = text.defaultTextFormat()? – Dominic Tancredi Nov 07 '11 at 02:42
  • sorry I shortcut my code a bit, assume that text is a valid TLFTextField child of the MovieClip created by new classFromLib(). I tried what you said but it didn't work, all of the properties in text.defaultTextFormat seem to be default properties, not the actual properties of the TLFTextField. Eg it had Times New Roman as the font, which is wrong. I did fix the issue with the 'leading' property however. When you set Leading in Flash CS5, you can make it pt or %. % seems to cause the value to get min int during getTextFormat, but using pt instead fixed it. – Ashley Muller Nov 07 '11 at 05:40

1 Answers1

0

You might need to get the TextLayerFormat from the TLTFTextfield instead:

Here's the documentation on the TextLayerFormat.

The other option is to get the content property, and use ElementFormat to get access that the formatting object that holds those properties

Dominic Tancredi
  • 41,134
  • 7
  • 34
  • 50