A new feature of flashMX2004 is to load external CSS files and apply them to flash text. Now there is a new class (Class? Because the new ActionScript2 is a class-based scripting language): TextField. styleSheet class is the several methods of this class that allow us to format flash text like HTML-defined CSS, such as font size, color, and position. In the future, we need to change the style of flash text, so we only need to modify the external CSS file instead of the FLA file.
Before you start, make sure that you have installed flashMX2004 and have some knowledge about HTML. This should be basically done. OK ~ Preparation ...... Start ~
First, create a CSS file. You can use DWMX2004 or another text editing tool:. textTitle {
Font-family: Verdana, Arial, Helvetica, sans-serif;
Font-size: 12px;
Font-weight: bold;
Color: #993300;
Text-align: center;
}
. TextContent {
Font-family: Arial, Helvetica, sans-serif;
Font-size: 12px;
Color: #000000;
}
Save the file with the name externalcss.css, create a new flash file, drag (or double-click) a TextArea component from the Components panel to the scenario,
And name the component "myText ":
The height and width of the TextArea component are determined based on the amount of your text and the HTML parameter is true:
Next, write AS. Select the first frame of the timeline and press the shortcut key "F9" to bring up the Action panel:
// Create a style table object
Var myCss = new TextField. StyleSheet ();
// CSS file location
Var cssURL = "externalCSS.css ";
// Define the content of the text box component.
Var textStr: String = "<p class = 'texttitle'> Xu Wei-one day </p>
<Span class = 'textcontent'>
From the morning to the night, the world keeps rotating. The winter is far away. Spring brings endless warmth.
I'm standing here quietly feeling the breeze with you
</Span> ";
// Load the external CSS file and determine whether the file is successfully loaded
MyCss. load (cssURL );
MyCss. onLoad = function (suc ){
If (suc ){
// If loading succeeds, set the content of the text box and apply the loaded CSS
MyText. styleSheet = myCss;
MyText. text = textStr;
}
};
I will not explain the above section AS, but the comments in it are clearly written. It should be noted that two HTML tags are used when defining text strings: <p> and <span>, the function is to define CSS for flash text, which is why I mentioned above that I need some HTML knowledge. OK ,save flash to the Directory of the externalcss.css file, Ctrl + Enter. Is the text effect the same as that defined in the CSS file? It's so easy.
You can also use the setStyle () method of the TextField. StyleSheet class to create CSS, or take the preceding surface as an example:
Var myCSS = new TextField. StyleSheet ();
MyCSS. setStyle ("textTitle ",
{Font-family: 'verdana, Arial, Helvetica, sans-serif ',
Font-size: '12px ',
Font-weight: 'Bold ',
Color: '#993300 ',
Text-align: 'center '}
);
MyCSS. setStyle ("textContent ",
{Font-family: 'Arial, Helvetica, sans-serif ',
Font-size: '12px ',
Color: '#000000 '}
);
Var textStr: String = "<p class = 'texttitle'> Xu Wei-one day </p>
<Span class = 'textcontent'>
From the morning to the night, the world keeps rotating. The winter is far away. Spring brings endless warmth.
I'm standing here quietly feeling the breeze with you
It woke me up and watched all the joys and sorrows close to the bright sunset. </span> ";
MyText. styleSheet = myCSS;
MyText. text = textStr;
This code is the same as loading an external CSS file.
Figure: [CSS1.0 attribute values supported by flash]