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.
NOT
E
In the previous code snippet,
this.getStyleNames()
refers to the
styles
object you
constructed in the first line of ActionScript.
Summary of Contents for FLASH 8-LEARNING ACTIONSCRIPT 2.0 IN FLASH
Page 1: ...Learning ActionScript 2 0 in Flash...
Page 8: ...8 Contents...
Page 18: ...18 Introduction...
Page 30: ...30 What s New in Flash 8 ActionScript...
Page 66: ...66 Writing and Editing ActionScript 2 0...
Page 328: ...328 Interfaces...
Page 350: ...350 Handling Events...
Page 590: ...590 Creating Interaction with ActionScript...
Page 710: ...710 Understanding Security...
Page 730: ...730 Debugging Applications...
Page 780: ...780 Deprecated Flash 4 operators...
Page 830: ...830 Index...