MACROMEDIA FLASH MX 2004 - ACTIONSCRIPT Reference Manual page 141

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

Advertisement

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
method of the TextField.StyleSheet class. To determine when the CSS file has
load()
finished loading, use the style sheet object's
In the following example, you'll create and load an external CSS file and use the
TextField.StyleSheet.getStyleNames()
To load an external style sheet:
In your preferred text or XML editor, create a file.
1
Add the following style definitions to the file:
2
// Filename: styles.css
bodyText {
font-family: Arial,Helvetica,sans-serif;
font-size: 12px;
}
headline {
font-family: Arial,Helvetica,sans-serif;
font-size: 24px;
}
Save the CSS file as styles.css.
3
In Flash, create a FLA document.
4
In the Timeline (Window > Timeline), select Layer 1.
5
Open the Actions panel (Window > Development Panels > Actions).
6
Add the following code to the Actions panel:
7
var css_styles = new TextField.StyleSheet();
css_styles.load("styles.css");
css_styles.onLoad = function(ok) {
if(ok) {
// display style names
trace(this.getStyleNames());
} else {
trace("Error loading CSS file.");
}
}
Save the file to the same directory that contains styles.css.
8
Test the movie (Control > Test Movie).
9
You should see the names of the two styles displayed in the Output panel:
body
headLine
If you see "Error loading CSS file" displayed 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.
As with all other ActionScript methods that load data over the network, the CSS file must reside
in the same domain as the SWF file that is loading the file. (See
data loading" on page
onLoad
190.)
event handler.
method to retrieve the names of the loaded styles.
"About allowing cross-domain
Formatting text with Cascading Style Sheets
141

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?

Subscribe to Our Youtube Channel

Table of Contents