PDA

View Full Version : htmlText, incorrect textHeight, and extra space



nate451
May 11th, 2009, 12:57 PM
I've developed a relatively simple calendar app in Flash that reads an XML file and displays text based on what day it is. A different bit of text displays in the same text box. Since the text is of varying lengths, I wrote a function to resize the text to be large enough or small enough to fit the box. Here's my function:



// Generic function for increasing text size to fill its container
function AutoTextResize(textElement, maxHeight):void {
textElement.autoSize = TextFieldAutoSize.LEFT;
var textProperties:TextFormat;
var autoTextFormat:TextFormat;

while ( textElement.textHeight < maxHeight ) {
textProperties = textElement.getTextFormat();
autoTextFormat = new TextFormat();
autoTextFormat.size = (textProperties.size + 1);
textElement.setTextFormat(autoTextFormat);
}

// Now that the text size is one greater than necessary, decrease it by one
textProperties = textElement.getTextFormat();
autoTextFormat = new TextFormat();
autoTextFormat.size = (textProperties.size + (-1));
textElement.setTextFormat(autoTextFormat);

trace('Text Height: ' + textElement.textHeight);
trace('Height: ' + textElement.height);
}
The basic idea is: up the text size until it's large enough that the textHeight is larger than the height you pass in (maxHeight), then go back to the size before the one that was too large. This function works great. The textHeight is smaller than the height of the text box.

I have just one bug, and it's utterly confounding me. The text is selectable (which is important: I want users to be able to copy/paste it), and on many of the days (about half), if you select (highlight) the text and drag it to the end, the text shifts up, as if there's blank extra space or a blank extra line at the end. It's as if the field has scrolled to the bottom, even though there's nothing there to scroll to. You can get back to the top by highlighting and dragging toward the beginning.

http://www.kirupa.com/forum/attachment.php?attachmentid=49888&d=1242057355
http://www.kirupa.com/forum/attachment.php?attachmentid=49889&d=1242057363

It behaves as if the textHeight is LARGER than the height of the box, despite the values it outputs in the traces.

I've tried a lot of searching on this problem and can't find anyone that's describing what I'm talking about. If someone could help me with this problem or even help me describe it more accurately, I'd be very grateful.

nate451
May 11th, 2009, 01:10 PM
I should note that it needs to be htmlText rather than plain text because some entries contain links.

nate451
May 11th, 2009, 03:04 PM
I finally found someone else describing the same problem:

http://board.flashkit.com/board/showthread.php?t=771091

I also found, just before reading this, that I could eliminate my problem by setting leading to zero. In this example, this workaround should work, but it is a frustrating limitation not to be able to specify a leading value. Anyone have greater insight into this issue?

kunjan
May 19th, 2009, 04:07 AM
Hello,

can you please place your xml file here ?
so I can understand more....

Regards,
Kunjan.

kunjan
May 19th, 2009, 05:47 AM
Hello,

can you please place your xml file here ?
so can understand more....

Regards,
Kunjan.