MACROMEDIA FLASH MX 2004 - ACTIONSCRIPT Reference Manual page 142

Actionscript reference guide
Hide thumbs Also See for FLASH MX 2004 - ACTIONSCRIPT:
Table of Contents

Advertisement

Creating new styles with ActionScript
You can create new text styles with ActionScript by using the
TextField.StyleSheet class. This method takes two parameters: the name of the style and an object
that defines that style's properties.
For example, the following code creates a style sheet object named
that are identical to those you imported earlier (see
var styles = new TextField.StyleSheet();
styles.setStyle("bodyText",
{fontFamily: 'Arial,Helvetica,sans-serif',
fontSize: '12px'}
);
styles.setStyle("headline",
{fontFamily: 'Arial,Helvetica,sans-serif',
fontSize: '24px'}
);
Applying styles to a TextField object
To apply a style sheet object to a text field, you assign the style sheet object to the text field's
property.
styleSheet
textObj_txt.styleSheet = styleSheetObj;
Note: Be careful not to confuse the
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
always contain the same value and behave identically.
The text field becomes read-only and cannot be edited by the user.
The
setTextFormat()
with the text field. The only way to change the field is by altering the text field's
properties, or by changing the text field's associated variable.
htmlText
Any text assigned to the text field's
stored verbatim; anything written to one of these properties can be retrieved in the text's
original form.
Combining styles
CSS styles in Flash Player are additive; that is, when styles are nested, each level of nesting can
contribute additional style information, which is added together to result in the final formatting.
For example, here is some XML data assigned to a text field:
<sectionHeading>This is a section</sectionHeading>
<mainBody>This is some main body text, with one
<emphasized>emphatic</emphasized> word.</mainBody>
For the word emphatic in the above text, the
style. The
mainBody
style adds a font-weight rule to these rules. The word emphatic will be formatted using a
combination of the rules specified by
142
Chapter 8: Working with Text
TextField.styleSheet
and
properties, and any variable associated with the text field,
text
htmlText
and
replaceSel()
text
style contributes color, font-size, and decoration rules. The
mainBody
setStyle()
"Loading external CSS files" on page
property with the TextField.StyleSheet
methods of the TextField class no longer function
property,
property, or associated variable is
htmlText
style is nested within the
emphasized
and
.
emphasized
method of the
that defines two styles
styles
text
mainBody
emphasized
141).
or

Advertisement

Table of Contents
loading
Need help?

Need help?

Do you have a question about the FLASH MX 2004 - ACTIONSCRIPT and is the answer not in the manual?

Table of Contents