Monday, 31 May 2010

TextLineMetrics...continued

This code works:

test_txt.addEventListener(Event.CHANGE,getLonger);
function getLonger(evnt:Event):void {
var met:TextLineMetrics = test_txt.getLineMetrics(0);
trace(met.height);
trace(met.ascent);
trace(met.descent);
trace(met.leading);
trace(' ');
if(test_txt.textHeight > test_txt.height){
test_txt.height = test_txt.textHeight + 6;
}
}

So, why would 6 be the magic number? I tried this in font size 18, 24, and 96, and different font faces as well. (By the way, in my previous efforts, the first line wasn't scrolling up because of using '+=', actually, it was because there wasn't enough added. So this can happen with '=' as well, if the textfield height isn't large enough.)

Anyway, if you have a look at this diagram:


(from http://help.adobe.com/en_US/AS3LCR/Flash_10.0/flash/text/TextLineMetrics.html)

You can see a '2-pixel gutter' at the top and bottom of the text field, that gives 4 extra pixels, and there is the 'leading' value as well. I have traced out the 'leading' value in different faces and sizes, it is always 2.

So my theory is, that you need to take account of the gutters, and the leading for the next line. So for safety's sake, I will use '4 + met.leading';

UPDATE: You can set 'leading' in the properties panel, if you mouse over the second option in 'Spacing', it says 'Line spacing' - Mine was set to 2.0, but if I change it to, for example 5, the met.leading traces out 5.

No comments:

Post a Comment

Please enter your message here...