ActionScript 3 TextField Fix

So I ran into this bug in Flash where I was setting a TextField’s htmlText property and the TextField was cutting off letters and causing strange line wrapping (even though its autoSize property was set to TextFieldAutoSize.LEFT). In order to fix this issue, I used this method Luke Sturgeon had developed:

function setHtmlText($textField:TextField, $text:String):void {
    $textField.autoSize = TextFieldAutoSize.LEFT;
    $textField.htmlText = $text;
    var h:Number = $textField.height;
    $textField.autoSize = TextFieldAutoSize.NONE;
    $textField.height = h + $textField.getTextFormat().leading;
}

It seems to work well and it also prevents the shifting of characters when you have any anchor tags within your HTML.

2 years ago on Monday, November 16th, 2009 at 6:09 PM