Formatting text with Cascading Style Sheet styles 427
Applying styles to a TextField object
To apply a style sheet object to a TextField object, you assign the style sheet object to the text
field’s
styleSheet property.
textObj_txt.styleSheet = styles;
When you assign a style sheet object to a TextField object, the following changes occur to the
text field’s normal behavior:
■ The text field’s text and htmlText properties, and any variable associated with the text
field, always contain the same value and behave identically.
■ The text field becomes read-only and cannot be edited by the user.
■ The setTextFormat() and replaceSel() methods of the TextField class no longer
function with the text field. The only way to change the field is by altering the text field’s
text or htmlText property or by changing the text field’s associated variable.
■ Any text assigned to the text field’s text property, htmlText property, or associated
variable is stored verbatim; anything written to one of these properties can be retrieved in
the text’s original form.
Applying a style sheet to a TextArea component
To apply a style sheet to a TextArea component, you create a style sheet object and assign it
HTML styles using the TextField.StyleSheet class. You then assign the style sheet to the
TextArea component’s
styleSheet property.
The following examples create a style sheet object,
styles, and assign it to the myTextArea
component instance.
Using a style sheet with a TextArea component:
1. Create a new Flash document and save it as textareastyle.fla.
2. Drag a TextArea component from the User Interface folder of the Components panel to
the Stage and give it an instance name of myTextArea.
NOTE
Do not confuse the TextField.styleSheet property with the TextField.StyleSheet class.
The capitalization indicates the difference.