User Guide

236 Chapter 9: Working with Text
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 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></story>
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 file.
8.
Save the text file as myStory.xml.
9.
In Flash, add the following code in the Actions panel, following the code in step 6. This code
loads the myStory.xml document, assigns the style sheet object to the text field’s
styleSheet
property, and assigns the XML text to the text field:
var myXML:XML = new XML();
myXML.ignoreWhite = true;
myXML.load("myStory.xml");
myXML.onLoad = function(success) {
if(success){
storyText = myXML;
news_txt.styleSheet = xmlStyles;
news_txt.text = storyText;
}else{
trace("Error loading XML.");
}
};
Note: You are loading XML data from an external file in this ActionScript. For information on
loading external data, see Chapter 12, “Working with External Media,” on page 295.
10.
Save the file as news_xml.fla in the same folder as myStory.txt.
11.
Run the movie (Control > Test Movie) to see the styles automatically applied to the text in
the text field.
Using HTML-formatted text
Flash Player supports a subset of standard HTML tags such as <p> and <li> that you can use to
style text in any dynamic or input text field. Text fields in Flash Player 7 and later also support the
<img> tag, which lets you embed JPEG files, SWF files, and movie clips in a text field. Flash
Player automatically wraps text around images embedded in text fields in much the same way that
a web browser wraps text around embedded images in an HTML page. For more information, see
“Embedding images, SWF files, and movie clips in text fields” on page 242.
Flash Player also supports the
<textformat> tag, which lets you apply paragraph formatting
styles of the TextFormat class to HTML-enabled text fields. For more information, see “Using the
TextFormat class” on page 224.