You could then populate a text field associated with that style sheet with the following XML-
formatted text:
<sectionHeading>This is a section</sectionHeading>
<mainBody>This is some main body text,
with one <emphasized>emphatic</emphasized> word.
</mainBody>
An example of using styles with XML
In this section, you'll create the same FLA file that you created earlier (see
styles with HTML" on page
style sheet using ActionScript, rather than importing styles from a CSS file.
To format XML with a style sheet:
In Flash, create a FLA file.
1
Using the Text tool, create a text field approximately 400 pixels wide and 300 pixels high.
2
Open the Property inspector (Window > Properties) and select the text field.
3
In the Property inspector, select Dynamic Text from the Text Type menu, select Multiline from
4
the Line Type menu, select the Render Text as HTML option, and type
Instance Name text box.
On Layer 1 in the Timeline (Window > Timeline), select the first frame.
5
To create the style sheet object, open the Actions panel (Window > Development Panels >
6
Actions) and add the following code to the Actions panel:
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
method. The styles exactly match those you created in an external CSS file earlier
setStyle()
in this chapter.
146
Chapter 8: Working with Text
144) but with XML-formatted text. In this example, you'll create the
that defines styles by using the
xml_styles
"An example of using
in the
news_txt
Need help?
Do you have a question about the FLASH MX 2004 - ACTIONSCRIPT and is the answer not in the manual?
Questions and answers