Flash - setTextFormat crashes on TLFTextField

1.3k Views Asked by At

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?

1

There are 1 best solutions below

0
On

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