Stroep

Just a collection of random works – Mark Knol

Code snippetI 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.

ยป Download source

Tagged with , , . | Tiny URL http://tinyurl.com/ykg9hot

2 Responses to “getBounds for TextFields = getBitmapBounds()”

  1. luuk says:

    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 :)

Trackbacks

  1. [...] Dit blogartikel was vermeld op Twitter door Ben en Paul Johnson, mknol. mknol heeft gezegd: done! Getbounds for textfields. http://tinyurl.com/ykg9hot [...]

Leave a Reply