User Guide
Preserving rich text formatting 121
Preserving rich text formatting
Flash lets you preserve rich text formatting in input and dynamic text fields. If you select the
Render Text as HTML formatting option in the Property inspector or set the
html property of
the TextField object to
true, Flash preserves basic text formatting (such as font, style, color, and
size) and hyperlinks in the text field by automatically applying the corresponding HTML tags
when you export the SWF file. You apply HTML tags to text fields as the value of the
htmlText
property of the TextField object. You must give the text field an instance name to use the
htmlText property.
If you will publish your Flash document as Flash Player 5 or earlier, you can use the text field
variable to apply HTML tags to text fields.
The following HTML tags are supported by the
htmlText property text fields: a, b, font color,
font face, font size, i, p, and u.
The following HTML attributes are supported in text fields:
leftmargin, rightmargin, align,
indent, and leading. To apply these attributes, use the TextFormat class or cascading style
sheets. For more information, see Chapter 9, “Working with Text,” in Using ActionScript in Flash
and “TextFormat class” or “TextField.StyleSheet class” in Flash ActionScript Language Reference.
To use the text field instance name to preserve rich text formatting:
1.
Do one of the following to assign an instance name to the text field:
■ Use the Text tool to create a text field on the Stage. Assign the text field an instance name in
the Property inspector.
■ Use the ActionScript createTextField method to create a text field dynamically. Assign
the text field an instance name as a parameter of the
createTextField method.
2.
Do one of the following:
■ Select the Render Text as HTML option in the Property inspector.
■ In the Actions panel, set the html property of the TextField object to true, as in
the following:
instanceName.html = true;
3.
In the Actions panel, set the htmlText property to a value that includes HTML tags.
For example, if you have a dynamic text field on the Stage with the instance name
instName,
the following code renders the text in bold:
instName.htmlText = "<b>Chris</b>";
To use the text field variable to preserve rich text formatting:
1.
Select a text field on the Stage.
2.
Assign the text field a variable name in the Property inspector.
3.
Do one of the following:
■ Select the Render Text as HTML option in the Property inspector.
■ In the Actions panel, set the html property of the TextField object to true.