Formatting text with Cascading Style Sheets
139
Getting text metric information
You can use the
TextFormat.getTextExtent()
method to obtain detailed text measurements
for a text string with specific formatting applied. 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 of the text. The
getTextExtent()
method provides
measurements such as ascent, descent, width, and height.
For more information, see
TextFormat.getTextExtent()
on page 719
.
Formatting text with Cascading Style Sheets
Cascading Style Sheets are a mechanism for creating 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
.
bodyText { text-align: left}
You can create styles that redefine built-in HTML formatting tags used by Flash Player (such as
<p>
and
<li>
), create style “classes” that can be applied to specific HTML elements using the
<p>
or
<span>
tag’s
class
attribute, or define new tags.
You use the TextField.StyleSheet class to work with text style sheets. 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
property.
The styles defined in the style sheet are mapped automatically to the tags defined in the HTML
or XML document.
Using styles sheets involves three basic steps:
•
Create a style sheet object from the TextField.StyleSheet class. See
“Creating a style sheet
object” on page 140
.
•
Add styles to the style sheet object, either by importing them from an external CSS file or by
defining them with ActionScript. See
“Loading external CSS files” on page 141
and
“Creating
new styles with ActionScript” on page 142
.
•
Assign the style sheet object to a text field that contains XML- or HTML-formatted text. See
“Applying styles to a TextField object” on page 142
,
“An example of using styles with HTML”
on page 144
, and
“An example of using styles with XML” on page 146
.
Содержание FLASH MX 2004 - ACTIONSCRIPT
Страница 1: ...ActionScript Reference Guide...
Страница 8: ...8 Contents...
Страница 12: ......
Страница 24: ...24 Chapter 1 What s New in Flash MX 2004 ActionScript...
Страница 54: ...54 Chapter 2 ActionScript Basics...
Страница 80: ...80 Chapter 3 Writing and Debugging Scripts...
Страница 82: ......
Страница 110: ...110 Chapter 5 Creating Interaction with ActionScript...
Страница 112: ......
Страница 120: ...120 Chapter 6 Using the Built In Classes...
Страница 176: ......
Страница 192: ...192 Chapter 10 Working with External Data...
Страница 202: ...202 Chapter 11 Working with External Media...
Страница 204: ......
Страница 782: ...782 Chapter 12 ActionScript Dictionary...
Страница 793: ...Other keys 793 221 222 Key Key code...
Страница 794: ...794 Appendix C Keyboard Keys and Key Code Values...
Страница 798: ...798 Appendix D Writing Scripts for Earlier Versions of Flash Player...
Страница 806: ...806 Appendix E Object Oriented Programming with ActionScript 1...
Страница 816: ...816 Index...