Textfield can support some html tag in flash, for example:

info.htmlText = “<b>Bold</b>, <i>italic</i>, <u>underline</u>”;

the result effect:
Bold, italic, underline

However, when you use htmlText adding text one by one, the new added text will automatically newline. See below example:

info.htmlText = “<b>Bold</b>”;
info.htmlText += “, <i>italic</i>”;
info.htmlText += “, <u>underline</u>”;

the result effect:
Bold
, italic
, underline

How that happens? Let’s trace what is inside that textfield.
trace(info.htmlText);

It turns out that flash player automatically add <p> after each newly added words.

<TEXTFORMAT LEADING=”3″><P ALIGN=”LEFT”><FONT FACE=”Arial” SIZE=”14″ COLOR=”#000000″><B>Bold</B></FONT></P></TEXTFORMAT> <TEXTFORMAT LEADING=”3″><P ALIGN=”LEFT”><FONT FACE=”Arial” SIZE=”14″ COLOR=”#000000″>, <I>italic</I></FONT></P></TEXTFORMAT> <TEXTFORMAT LEADING=”3″><P ALIGN=”LEFT”><FONT FACE=”Arial” SIZE=”14″ COLOR=”#000000″>, <U>underline</U></FONT></P></TEXTFORMAT>

Hence, the correct way to gradually adding text using htmlText is to put the text in a variable and adding text to that variable one by one. In the end, assign the variable to htmlText

var tmpTxt = “<b>Bold</b>”;
tmpTxt += “, <i>italic</i>”;
tmpTxt += “, <u>underline</u>”;
info.htmlText = tmpTxt;

Spread the love