Overview of using HTML-formatted text

To use HTML in a text field, you must enable the text field's HTML formatting either by selecting the Render Text as HTML option in the Property inspector, or by setting the text field's html property to true. To insert HTML into a text field, use the TextField.htmlText property.

For example, the following code enables HTML formatting for a text field named headline_txt, and then assigns some HTML to the text field.

headline_txt.html = true;
headline_txt.htmlText = "<font face='Times New Roman' size='24'>This is how you assign HTML text to a text field.</font>";

Attributes of HTML tags must be enclosed in double or single quotation marks. Attribute values without quotation marks may produce unexpected results, such as improper rendering of text. For example, the following HTML snippet will not be rendered properly by Flash Player because the value assigned to the align attribute (left) is not enclosed in quotation marks:

textField.htmlText = "<p align=left>This is left-aligned text</p>";

If you enclose attribute values in double quotation marks, you must "escape" the quotation marks (\"). For example, either of the following are acceptable:

textField.htmlText = "<p align='left'>This uses single quotes</p>";
textField.htmlText = "<p align=\"left\">This uses escaped double quotes</p>";

It's not necessary to escape double quotation marks if you're loading text from an external file; it's only necessary if you're assigning a string of text in ActionScript.