EasyManua.ls Logo

MACROMEDIA FLASH 8-LEARNING ACTIONSCRIPT 2.0 IN FLASH - Page 435

MACROMEDIA FLASH 8-LEARNING ACTIONSCRIPT 2.0 IN FLASH
830 pages
Print Icon
To Next Page IconTo Next Page
To Next Page IconTo Next Page
To Previous Page IconTo Previous Page
To Previous Page IconTo Previous Page
Loading...
Formatting text with Cascading Style Sheet styles 435
This code creates a new style sheet object named styles 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.
7. To create the XML text to assign to the text field, open a text editor and enter the following
text into a new document:
<story><title>Flash now has FlashType</title><mainBody><byline>San
Francisco, CA</byline>--Macromedia Inc. announced today a new version
of Flash that features the new FlashType rendering technology. For
more information, visit the <a href="http://
www.macromedia.com">Macromedia Flash website</a></mainBody></story>
8.
Save the text file as story.xml.
9. In Flash, add the following code in the Actions panel, following the code in step 6.
This code loads the story.xml document, assigns the style sheet object to the text fields
styleSheet property, and assigns the XML text to the text field:
var my_xml:XML = new XML();
my_xml.ignoreWhite = true;
my_xml.onLoad = function(success:Boolean):Void {
if (success) {
news_txt.styleSheet = styles;
news_txt.text = my_xml;
} else {
trace("Error loading XML.");
}
};
my_xml.load("story.xml");
10.
Save the file as news_xml.fla in the same folder as story.xml.
11. Run the SWF file (Control > Test Movie) to see the styles automatically applied to the text
in the text field.
NOTE
If you copy and paste this text string, make sure that you remove any line breaks that
might have been added to the text string. Select Hidden Characters from the pop-up
menu in the Actions panel to see and remove any extra line breaks.
NOTE
You are loading XML data from an external file in this ActionScript. For
information on loading external data, see Chapter 15, “Working with Images,
Sound, and Video.”

Table of Contents

Related product manuals