![]() ![]() | |
In this section, you'll create the same FLA file that you created earlier (see An example of using styles with HTML) but with XML-formatted text. In this example, you'll create the style sheet using ActionScript, rather than importing styles from a CSS file.
To format XML with a style sheet:news_txt in the Instance Name text box.
var xml_styles = new TextField.StyleSheet();
xml_styles.setStyle("mainBody", {
color:'#000000',
fontFamily:'Arial,Helvetica,sans-serif',
fontSize:'12',
display:'block'
});
xml_styles.setStyle("title", {
color:'#000000',
fontFamily:'Arial,Helvetica,sans-serif',
fontSize:'18',
display:'block',
fontWeight:'bold'
});
xml_styles.setStyle("byline", {
color:'#666666',
fontWeight:'bold',
fontStyle:'italic',
display:'inline'
});
xml_styles.setStyle("a:link", {
color:'#FF0000'
});
xml_styles.setStyle("a:hover", {
textDecoration:'underline'
});
This code creates a new style sheet object named xml_styles that defines styles by using the setStyle() method. The styles exactly match those you created in an external CSS file earlier in this chapter.
var storyText = "<title>Flash Player now supports CSS</title><mainBody><byline>San Francisco, CA</byline>--Macromedia Inc. announced today a new version of Flash Player that supports Cascading Style Sheets (CSS) text styles. For more information, visit the <a href=\"http://www.macromedia.com\">Macromedia Flash website</a></mainBody>";
styleSheet property and assign the XML text to the text field.
news_txt.styleSheet = xml_styles; news_txt.text = storyText;
![]() ![]() | |