I have the following code in AS3:
var str:String = '<TEXTFORMAT LEADING="2"><P ALIGN="LEFT"><FONT FACE="Arial" SIZE="12" COLOR="#000000" LETTERSPACING="0" KERNING="0">Lo<FONT COLOR="#0000FF">re<FONT FACE="GG Superscript">m</FONT></FONT><FONT FACE="GG Superscript"> Ip</FONT><FONT COLOR="#990000"><FONT FACE="GG Superscript">su</FONT>m i</FONT>s simply dummy text </FONT></P></TEXTFORMAT>';
trace('BEFORE: '+str);
txt.htmlText = str;
trace('AFTER: '+txt.htmlText);
The problem I am facing is that the BEFORE and AFTER trace texts are very different. They are as follows:
BEFORE Trace
<TEXTFORMAT LEADING="2">
<P ALIGN="LEFT">
<FONT FACE="Arial" SIZE="12" COLOR="#000000" LETTERSPACING="0" KERNING="0">Lo
<FONT COLOR="#0000FF">re
<FONT FACE="GG Superscript">m</FONT>
</FONT>
<FONT FACE="GG Superscript"> Ip</FONT>
<FONT COLOR="#990000">
<FONT FACE="GG Superscript">su</FONT>
m i
</FONT>
s simply dummy text
</FONT>
</P>
</TEXTFORMAT>
AFTER Trace
<TEXTFORMAT LEADING="2">
<P ALIGN="LEFT">
<FONT FACE="Arial" SIZE="12" COLOR="#000000" LETTERSPACING="0" KERNING="0">Lo
<FONT COLOR="#0000FF">re
<FONT FACE="GG Superscript">m
<FONT COLOR="#000000"> Ip
<FONT COLOR="#990000">su
<FONT FACE="Arial">m i</FONT>
</FONT>
</FONT>
</FONT>
</FONT>s simply dummy text
</FONT>
</P>
</TEXTFORMAT>
It seems htmlText is rearranging the html tags. Even though the output is the same, I need the original html back since I am making a text editor and the AFTER htmlText is messing up my tag calculations. Any ideas what can be done here?
Thanks in advance.
Is there a project requirement for using
<FONT>tags for styling? Support for styling with basic HTML tags is very limited and buggy in Flash TextFields. I highly recommend using CSS to format your text using theflash.text.Stylesheetclass. You’ll find it’s much more reliable, and your code will be cleaner.Check out this tutorial for a clean implementation of CSS in TextFields.