When using non-zero line spacing, the autoSize property is not functioning as expected, causing text fields to scroll that shouldn't. Also, when using device fonts, the sizes of the TextFields are wrong in the Flash IDE.
I have a TextField whose height is supposed to be dynamic, depending the width of the TextField. wordWrap is true, the text is left aligned, and the autoSize value is flash.text.TextFieldAutoSize.LEFT.
When the TextField's width is adjusted, the height increases or decreases as expected, but when I scroll the mouse wheel over the TextField, it allows a single line to scroll out of view. This should not be happening. The autoSize property should ensure the TextField is large enough to neither require nor allow scrolling.
Has anyone else encountered this issue or know how to fix it?
Update: Been a problem since at least 2006! > http://blog.nthsense.net/?p=46
http://www.kirupa.com/forum/showthread.php?288955-Disabling-textfield-scrolling Bug is caused by using a line height ("line spacing" in Flash) larger than zero, for example 1.0pt. It looks like when I reduce the line spacing of the text field to zero, the issue goes away. There doesn't seem to be anything wrong with how autoSize is calculating the required height of the text (i.e. it is exactly textHeight + 4 pixel gutter, and drawing the rectangle (2,2,textWidth,textHeight) aligns visually with the text), so it must have to do with how the TextField is deciding whether it needs to scroll or not, and that separate calculation is being thrown off by the non-zero line spacing. The additional non-zero spacing at the end of the last line could be making the TextField think it needs to scroll, even though it's hight is sufficient at "textHeight + 4". Apparently the problem manifests when using a non-zero leading value as well.
In fact, it has to be related to the leading value exactly, since the following code stops the textfield from scrolling.
//body is TextField
var tlm:TextLineMetrics = body.getLineMetrics(body.numLines - 1);
trace(tlm.leading); //traces "1" here. traces zero when line spacing is zero, and traces larger values with larger line spacing values
body.autoSize = flash.text.TextFieldAutoSize.NONE; //turn off autosize so the height can be set manually
body.height += tlm.leading; //increase height of textfield by leading value of last line to cause scrolling to be turned off.
Honestly, this is pretty unacceptable bug. First of all, scrolling should not be sensitive to trailing line spacing, because autoSize and textHeight do not include it. It need to be consistent, and I think textHeight and autoSize setting height = textHeight + 4 is correct. Vertical scrolling should use textHeight as it's guage for whether scrolling is necessary, but instead, it's obviously involving the leading values of the last line. At the very least, vertical scrolling should simply be disabled when autoSize is turned on and wordWrap is true, because the TextField should be big enough to fit all the text. The workaround of manually adjusting the height is also no good, since turning autoSize back on will immediately change the size back and trigger scrolling again. I also shouldn't have to set line spacing to zero just to use the autoSize feature, since the scrolling calculations are wrong in this way.