getBounds for TextFields = getBitmapBounds() (2)
November 5th, 2009 by Mark Knol, under Actionscript, Code snippets.
I found out the getBounds()-function gives not exactly the right rectangle with a TextField. It always matches the border bounds, even if the borders are invisible. So I’ve created a more accurate function using getColorBoundsRect().
Click on the words. Switch between getRect() and getTextFieldBounds() by clicking on the buttons below to see the difference.
Tagged with bitmapdata, snippet, textfield. | Tiny URL http://tinyurl.com/ye22pkk

















[...] Dit blogartikel was vermeld op Twitter door Ben en Paul Johnson, mknol. mknol heeft gezegd: done! Getbounds for textfields. http://tinyurl.com/ykg9hot [...]
Hi Mark, getBounds gets inherited from DisplayObject, so it can be expected it returns the border bounds, the methods wasn’t designed for text.
Although your solutions seems to produce a fine result, it is kind of overengineered converting the textfield to a bitmapdata object. Have you tried looking into TextLineMetrics? (http://livedocs.adobe.com/flash/9.0/ActionScriptLangRefV3/flash/text/TextLineMetrics.html)
That in combination with numLines, getLineText and getCharBounds suffices to get al the info you need to find the exact borders