EasyManua.ls Logo

MACROMEDIA FLASH 8-LEARNING ACTIONSCRIPT 2.0 IN FLASH - Page 425

MACROMEDIA FLASH 8-LEARNING ACTIONSCRIPT 2.0 IN FLASH
830 pages
Print Icon
To Next Page IconTo Next Page
To Next Page IconTo Next Page
To Previous Page IconTo Previous Page
To Previous Page IconTo Previous Page
Loading...
Formatting text with Cascading Style Sheet styles 425
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:
.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 new FLA file.
5. In the Timeline (Window > Timeline), select Layer 1.
6. Open the Actions panel (Window > Actions).
7. Add the following code to the Actions panel:
var styles:TextField.StyleSheet = new TextField.StyleSheet();
styles.onLoad = function(success:Boolean):Void {
if (success) {
// display style names.
trace(this.getStyleNames());
} else {
trace("Error loading CSS file.");
}
};
styles.load("styles.css");
8.
Save the FLA file to the same directory that contains styles.css.
9. Test the Flash document (Control > Test Movie).
You should see the names of the two styles in the Output panel:
.bodyText,.headline
If you see “Error loading CSS file.” in the Output panel, make sure the FLA file and the
CSS file are in the same directory and that you typed the name of the CSS file correctly.
NOTE
In the previous code snippet, this.getStyleNames() refers to the styles object you
constructed in the first line of ActionScript.

Table of Contents

Related product manuals