User Guide
228 Chapter 9: Working with Text
Creating a style sheet object
CSS are represented in ActionScript by the TextField.StyleSheet class. This class is available only
for SWF files that target Flash Player 7 or later. To create a style sheet object, call the
TextField.StyleSheet class’s constructor function:
var newStyle = new TextField.StyleSheet();
To add styles to a style sheet object, you can either load an external CSS file into the object or
define the styles in ActionScript. See “Loading external CSS files” on page 228 and “Creating new
styles with ActionScript” on page 229.
Loading external CSS files
You can define styles in an external CSS file and then load that file into a style sheet object. The
styles defined in the CSS file are added to the style sheet object. To load an external CSS file, you
use the
load() method of the TextField.StyleSheet class. To determine when the CSS file has
finished loading, use the style sheet object’s
onLoad event handler.
In the following example, you create and load an external CSS file and use the
TextField.StyleSheet.getStyleNames() method to retrieve the names of the loaded styles.
To load an external style sheet:
1.
In your preferred text or CSS editor, create a new file.
2.
Add the following style definitions to the file:
/* Filename: styles.css */
.bodyText {
font-family: Arial,Helvetica,sans-serif;
font-size: 12px;
}
.headline {
font-family: Arial,Helvetica,sans-serif;
font-size: 24px;
}
3.
Save the CSS file as styles.css.
4.
In Flash, create a FLA document.
5.
In the Timeline (Window > Timeline), select Layer 1.
6.
Open the Actions panel (Window > Development Panels > Actions).