I have a text field that gets populated dynamically. If the populated text doesn’t fit in the text field, the text gets resized. HTML tags work correctly in the dynamically populated text, but only if the text doesn’t get resized. HTML tags are completed ignored in resized text. Any ideas?
Code for the text field:
import flash.text.TextFormat;
import flash.text.Font;
//
function setDesc(str:String):void{
var fmtD:TextFormat;
var cfmtD:TextFormat = this.desc_txt.getTextFormat()==null ? this.desc_text.defaultTextFormat : this.desc_txt.getTextFormat();
var sizeD:int = 22;
desc_txt.htmlText = str;
while(sizeD>10 && sizeD<23 && desc_txt.textHeight>255){
sizeD--;
fmtD = new TextFormat(descFont.fontName,sizeD,0x000000,false, false,false);
desc_txt.htmlText = str;
desc_txt.setTextFormat(fmtD);
}
}
Code to populate the text field:
function openDialog(e:MouseEvent){
dialog_window.doOpen();
switch(e.currentTarget.name){
case "btn_structure":
dialog_window.setTitle("Business Structure:");
dialog_window.setDesc("This topic discusses the <b>basic</b> structure of the business area.");
break;
case "btn_services":
dialog_window.setTitle("Services Provided:");
dialog_window.setDesc("This topic provides <i>information</i> about the services offered by the Client Billing Services unit.");
break;
}
}
Try changing the last two lines inside the while loop to:
You can read more about working with html tags and the as3 TextFormat class here
EDIT:
I just set up this simple example using bits of your code and both the text formatting (font type and size) and html tags (bold and italics) are working flawlessly: