User Guide

Using HTML-formatted text 237
For more information on HTML-formatted text, see the following topics:
“Overview of using HTML-formatted text” on page 237
“Supported HTML tags” on page 237
“Embedding images, SWF files, and movie clips in text fields” on page 242
Overview of using HTML-formatted text
To use HTML in a text field, you must enable the text fields HTML formatting either by
selecting the Render Text as HTML option in the Property inspector or by setting the text fields
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 can produce unexpected results, such as improper rendering of
text. For example, the following HTML snippet cannot 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
(
\"). Either of the following examples are acceptable:
textField.htmlText = "<p align='left'>This uses single quotes</p>";
textField.htmlText = "<p align=\"left\">This uses escaped double quotes</p>";
Its not necessary to escape double quotation marks if youre loading text from an external file; it’s
necessary only if youre assigning a string of text in ActionScript.
Supported HTML tags
This section lists the built-in HTML tags supported by Flash Player. You can also create new
styles and tags using CSS; see “Formatting text with Cascading Style Sheets” on page 226.
Anchor tag (<a>)
The
<a> tag creates a hypertext link and supports the following attributes:
href Specifies the URL of the page to load in the browser. The URL can be either absolute
or relative to the location of the SWF file that is loading the page. An example of an absolute
reference to a URL is
http://www.macromedia.com; an example of a relative reference is /
index.html
.
target Specifies the name of the target window where you load the page. Options include
_self, _blank, _parent and _top. The _self option specifies the current frame in the
current window,
_blank specifies a new window, _parent specifies the parent of the current
frame, and
_top specifies the top-level frame in the current window.