TextField Nitpicking

TextField Nitpicking

So I’m making what it supposed to be a straightforward fix…I have to align 2 columns of 2 text fields on two movieclips that are next to each other. The tricky part is that each textfield can have a variable numbers of lines, so the layout rules are a little more complicated; I have to do a bit of on-the-fly runtime calculation.

What’s making this particularly aggravating is that the TextField class is one of messiest classes in all of Actionscript-dom. To be fair, text is a pretty complex thing to manage, so I should cut it some slack. But I’m going to bitch about it anyway :-)

Irritant #1: Awful documentation entry for TextField.textHeight.

The documentation for the TextField.textHeight property reads as this in its entirety:
        Usage
            TextField.textHeight

        Description
            Property; indicates the height of the text.
What kind of terrible documentation is this? Fortunately, Colin Moock describes this in more detail: it actually returns how high in pixels the content of the TextField is; “the text” as in TextField.text, as displayed in the TextField. In fact, this is the long-thought missing property I needed to calculate the number of lines in a TextField. This is important for implementing things like scrollbars with proportional thumbwheels. I had previously used an incredibly indirect way of determining the # of lines in a TextField by scrolling it to the beginning and end, and looking at the maxScroll property. Unfortunately, the maxScroll property is apparently only updated when a screen refresh occurs (as determined by the framerate of your movie, as far as I can tell), so it seemed somewhat unreliable in practice.

Irritant #2: TextFormat.getTextExtent() surprises!

Judging from the LiveDocs threads on the Macromedia site, this command is just plain buggy. You use this command to hopefully figure out how big a TextField needs to be based on a given TextFormat, string, and desired width. Surprise! It doesn’t work with whitespace or linefeeds! It’s not documented anywhere, except in Moock’s ActionScript for FlashMX: The The Definitive Guide. We have apparently avoided the other big bug with embedded fonts and cross-platform woes because we are using device fonts in our application (for Unicode support).

So between figuring out how to make TextFields behave reliably and feeling a little under the weather, it’s been one of those days. And hooray for Colin Moock. Again.

1 Comment

  1. David W. 19 years ago

    Here are two other huge irritants for TextField scripting:

    1. You can’t set a negative text leading with script. It won’t go less than 0.

    2. If you have the leading set (through the Flash GUI) to a negative value, then the textheight will always be off. You have to manually add the absolute value of the leading amount to the height of the text.
    ——-