User Guide

Formatting text with Cascading Style Sheets 235
An example of using styles with XML
In this section, you can create a FLA file that has XML-formatted text. You’ll create a style sheet
using ActionScript, rather than importing styles from a CSS file as shown in An example of using
styles with HTML” on page 232
To format XML with a style sheet:
1.
In Flash, create a FLA file.
2.
Using the Text tool, create a text field approximately 400 pixels wide and 300 pixels high.
3.
Open the Property inspector (Window > Properties), and select the text field.
4.
In the Property inspector, select Dynamic Text from the Text Type menu, select Multiline from
the Line Type menu, select the Render Text as HTML option, and type
news_txt in the
Instance Name text box.
5.
On Layer 1 in the Timeline (Window > Timeline), select the first frame.
6.
To create the style sheet object, open the Actions panel (Window > Development Panels >
Actions), and add the following code to the Actions panel:
var xmlStyles = new TextField.StyleSheet();
xmlStyles.setStyle("mainBody", {
color:'#000000',
fontFamily:'Arial,Helvetica,sans-serif',
fontSize:'12',
display:'block'
});
xmlStyles.setStyle("title", {
color:'#000000',
fontFamily:'Arial,Helvetica,sans-serif',
fontSize:'18',
display:'block',
fontWeight:'bold'
});
xmlStyles.setStyle("byline", {
color:'#666600',
fontWeight:'bold',
fontStyle:'italic',
display:'inline'
});
xmlStyles.setStyle("a:link", {
color:'#FF0000'
});
xmlStyles.setStyle("a:hover", {
textDecoration:'underline'
});
This code creates a new style sheet object named xmlStyles that defines styles by using the
setStyle() method. The styles exactly match the ones you created in an external CSS file
earlier in this chapter.