Working with Text > Controlling text with ActionScript > Preserving rich text formatting |  |

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 must use ActionScript to apply HTML tags to text fields, either as part of the value of a text field variable, or as the value of the `htmlText` property of the TextField object.

The following HTML tags are supported in 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 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 button in the Property inspector.
| In the Actions panel, set the `html` property of the TextField object to `true`.
4 | Set the text field variable to a value that includes HTML tags.
| For example, the following code assigns a value to a text field with the variable name `txt`. The text renders in bold if you check the Render text as HTML box in the Property inspector, or if the `html` property is set to true:
    txt = "<B>Chris<B>";
| In the following example, the variable name of the text field is also `txt`. Because the value of the `html` property of the TextField object is set to `true`, you can use the variable name to render the text field in bold without selecting the Render Text as HTML button in the Property inspector:
    instName.html = true;
    txt = "<B>Chris</B>";

To use the text field instance name to preserve rich text formatting:

1 | Do one of the following:
| Use the Text tool to drag a text field on the Stage. Assign the text field an instance name in the Property inspector.
| Use ActionScript to create a text field dynamically with the `createTextField` method. 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 button 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>";