User Guide
230 Chapter 9: Working with Text
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 = styleSheetObj;
Note: Do not confuse the
TextField.styleSheet property with the TextField.StyleSheet class. The
capitalization indicates the difference.
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 properties 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 assigns it to the myTextArea
component instance:
//Creates a new style sheet object and sets styles for it
var styles = new TextField.StyleSheet();
styles.setStyle("html",
{fontFamily: 'Arial,Helvetica,sans-serif',
fontSize: '12px',
color: '#0000FF'}
);
styles.setStyle("body",
{color: '#00CCFF',
textDecoration: 'underline'}
);
styles.setStyle("td",
{fontFamily: 'Arial,Helvetica,sans-serif',
fontSize: '24px',
color: '#006600'}
);
//Assign the style sheet object to myTextArea component
//Set html property to true, set styleSheet property to the style sheet object
myTextArea.styleSheet = styles;