To create the XML text to assign to the text field, add the following code to the Actions panel:
7
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>";
Last, add the following code to apply the style sheet object to the text field's
8
property and assign the XML text to the text field.
news_txt.styleSheet = xml_styles;
news_txt.text = storyText;
Save the file as news_xml.fla.
9
Run the movie (Control > Test Movie) to see the styles automatically applied to the text in
10
the field.
Using HTML-formatted text
Flash Player supports a subset of standard HTML tags such as
style text in any dynamic or input text field. Text fields in Flash Player 7 and later also support the
tag, which lets you embed JPEG files, SWF files, and movie clips in a text field. Flash
<img>
Player automatically wraps text around images embedded in text fields in much the same way 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
Flash Player also supports the
styles of the TextFormat class to HTML-enabled text fields. For more information, see
TextFormat class" on page
Overview of using HTML-formatted text
To use HTML in a text field, you must enable the text field's HTML formatting either by
selecting the Render Text as HTML option in the Property inspector, or by setting the text field's
property to
html
For example, the following code enables HTML formatting for a text field named
and then assigns some HTML to the text field.
headline_txt.html = true;
headline_txt.htmlText = "<font face='Times New Roman' size='24'>This is how
you assign HTML text to a text field.</font>";
Attributes of HTML tags must be enclosed in double or single quotation marks. Attribute values
without quotation marks may produce unexpected results, such as improper rendering of text.
For example, the following HTML snippet will not be rendered properly by Flash Player because
the value assigned to the
textField.htmlText = "<p align=left>This is left-aligned text</p>";
If you enclose attribute values in double quotation marks, you must "escape" the quotation marks
(
). For example, either of the following are acceptable:
\"
textField.htmlText = "<p align='left'>This uses single quotes</p>";
textField.htmlText = "<p align=\"left\">This uses escaped double quotes</p>";
It's not necessary to escape double quotation marks if you're loading text from an external file; it's
only necessary if you're assigning a string of text in ActionScript.
<textformat>
137.
. To insert HTML into a text field, use the
true
attribute (
align
<p>
tag, which lets you apply paragraph formatting
) is not enclosed in quotation marks:
left
styleSheet
and
that you can use to
<li>
152.
"Using the
TextField.htmlText
headline_txt
Using HTML-formatted text
property.
,
147
Need help?
Do you have a question about the FLASH MX 2004 - ACTIONSCRIPT and is the answer not in the manual?