MACROMEDIA FLASH 8-LEARNING ACTIONSCRIPT 2.0 IN FLASH Manual page 425

Learning actionscript 2.0 in flash
Table of Contents

Advertisement

In the following example, you create and load an external CSS file and use the
TextField.StyleSheet.getStyleNames()
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");
In the previous code snippet, this.getStyleNames() refers to the styles object you
constructed in the first line of ActionScript.
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.
method to retrieve the names of the
Formatting text with Cascading Style Sheet styles
425

Hide quick links:

Advertisement

Table of Contents
loading
Need help?

Need help?

Do you have a question about the FLASH 8-LEARNING ACTIONSCRIPT 2.0 IN FLASH and is the answer not in the manual?

This manual is also suitable for:

Flash 8

Table of Contents