Text and TextArea components in Flex can be wacky. Especially when you’re trying to autosize and measure the text in them.
One area I have always had problems with is measuring HTML text height. Let’s say you have a huge font at the top, then several breaks and a smaller font.
Flex just doesn’t know how to measure that correctly and you end up either cutting text off or scrolling.
Enter this blog post – http://idletogether.com/automatically-resize-texttextarea-based-on-content-autosize-in-flex/
This tells you exactly how to go about getting started when measuring html height. I say getting started, because chances are good you’ll have to tweak something to get it to work for your situation … such as when you have containers of widely varying widths, it seems to throw things off a bit… anyway, the code is below if you don’t want to make the jump.
1 2 3 4 5 6 7 8 9 |
var ta_height:uint = 25; field.validateNow(); for(var i:int=0; i < field .mx_internal::getTextField().numLines; i++) { ta_height += field.mx_internal::getTextField().getLineMetrics(i).height; } derivedHeight = ta_height; |
Aubrey says:
Oooooo measuring, yummy!
21st March 2010 at 11:13 am