Getting text metric information
You can use the
for a text string that has specific formatting. For example, suppose you need to create, at runtime,
a new TextField object containing an arbitrary amount of text that is formatted with a 24-point,
bold, Arial font, and a 5-pixel indent. You need to determine how wide or high the new TextField
object must be to display all the text. The
such as ascent, descent, width, and height.
For more information, see
Reference.
Formatting text with Cascading Style Sheets
Cascading Style Sheets (CSS) are a way to text styles that can be applied to HTML or XML
documents. A style sheet is a collection of formatting rules that specify how to format HTML or
XML elements. Each rule associates a style name, or selector, with one or more style properties and
their values. For example, the following style defines a selector named
.bodyText { text-align: left}
You can create styles that redefine built-in HTML formatting tags used by Flash Player (such as
and
), create style classes that can be applied to specific HTML elements using the
<p>
<li>
tag's
<span>
class
You use the TextField.StyleSheet class to work with text style sheets. Although the TextField class
can be used with Flash Player 6, the TextField.StyleSheet class requires that SWF files target Flash
Player 7 or later. You can load styles from an external CSS file or create them natively using
ActionScript. To apply a style sheet to a text field that contains HTML- or XML-formatted text,
you use the
TextField.styleSheet
automatically to the tags defined in the HTML or XML document.
Using styles sheets involves the following three basic steps:
•
Create a style sheet object from the TextField.StyleSheet class (for more information see
"TextField.StyleSheet class" in Flash ActionScript Language Reference).
•
Add styles to the style sheet object, either by loading them from an external CSS file or by
creating new styles with ActionScript.
•
Assign the style sheet to a TextField object that contains XML- or HTML-formatted text.
For more information, see the following topics:
•
"Supported CSS properties" on page 227
•
"Creating a style sheet object" on page 228
•
"Loading external CSS files" on page 228
•
"Creating new styles with ActionScript" on page 229
•
"Applying styles to a TextField object" on page 230
•
"Applying a style sheet to a TextArea component" on page 230
•
"Combining styles" on page 231
226
Chapter 9: Working with Text
TextFormat.getTextExtent()
TextFormat.getTextExtent()
attribute or define new tags.
property. The styles defined in the style sheet are mapped
method to obtain detailed text measurements
method provides measurements
getTextExtent()
in Flash ActionScript Language
:
bodyText
<p>
or
Need help?
Do you have a question about the FLASH MX 2004-USING ACTIONSCRIPT IN FLASH and is the answer not in the manual?