TextFormat.getTextExtent() is All Right in My Book

ActionScript 2.0

As of this writing, the Flash 8 ActionScript 2.0 Language Reference incorrectly states that the TextFormat.getTextExtent() method is deprecated.  It makes this gaffe twice:  in the method entry itself and in a separate “Deprecated Function summary” listing.  This occurs in both the onboard Help and the LiveDocs version.  On September 20, 2005 (nearly a year ago), Adobe editor Thais Derich acknowledged this error and stated that the documentation source has been updated, which is good news — but for whatever reason, this update still hasn’t been made available to the public (for example, shouldn’t the Update button in the Actions panel correct this?).

Don’t get me wrong, I’m not grouching.  ;)   The Language Reference is a lengthy document indeed, and the lion’s share is comprised of useful (and correct!) information.  But I figured I’d mention this, because the method comes in handy from time to time.  You may safely use this method in ActionScript 2.0 without feeling icky.

So, what does it do?  TextFormat.getTextExtent() allows you to determine the theoretical pixel dimensions of a string — as if that string were formatted in a given font, weight, size, and more.  In other words, it allows you to test for, say, the width of a text field in a certain styling without your having to create the text field first.

Thanks to my Adobe newsgroup compadre Marc Kassay for pointing this issue out to me.

Leave a Reply