138
Chapter 8: Working with Text
To format a text field with the TextFormat class:
1
In a new Flash document, create a text field on the Stage using the Text tool. Type some text
in the text field on the Stage, like “Bold, italic, 24 point text”.
2
In the Property inspector, type
myText_txt
in the Instance Name text box, select Dynamic
from the Text Type pop-up menu, and select Multiline from the Line Type pop-up menu.
3
In the Timeline, select the first frame in Layer 1 and open the Actions panel (Window >
Development Panels > Actions).
4
Enter the following code in the Actions panel to create a TextFormat object, and set its
bold
and
italic
properties to
true
, and its
size
property to 24.
// Create a TextFormat object
var txtfmt_fmt = new TextFormat();
// Specify paragraph and character formatting
txtfmt_fmt.bold = "true";
txtfmt_fmt.italic = "true";
txtfmt_fmt.size = "24"
5
Apply the TextFormat object to the text field you created in step 1 using
TextField.setTextFormat()
.
myText_txt.setTextFormat(txtfmt_fmt);
This version of
setTextFormat()
applies the specified formatting to the entire text field.
There are two other versions of this method that let you apply formatting to individual
characters or groups of characters. For example, the following code applies bold, italic, 24-
point formatting to the first four characters you entered in the text field.
myText_txt.setTextFormat(txtfmt_fmt, 0, 3);
For more information, see
TextField.setTextFormat()
on page 702
.
6
Select Control > Test Movie to test the movie.
Default properties of new text fields
Text fields created at runtime with
createTextField()
receive a default TextFormat object with
the following properties:
font = "Times New Roman"
size = 12
textColor = 0x000000
bold = false
italic = false
underline = false
url = ""
target = ""
align = "left"
leftMargin = 0
rightMargin = 0
indent = 0
leading = 0
bullet = false
tabStops = [] (empty array)
For a complete list of TextFormat methods and their descriptions, see the
TextFormat class
entry
in
Chapter 12, “ActionScript Dictionary,” on page 205
.
Содержание 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...