About text layout and formatting
419
The preceding ActionScript code can be separated into five sections. The first section
defines a new text format object that specifies two properties,
size
and
font
. The
font
property refers to the linkage identifier of the font symbol currently in the document
library. The second, third, and fourth sections of code each create a new dynamic text field
on the Stage and set some common properties:
antiAliasType
(which must be set to
advanced
),
embedFonts
(set to
true
),
multiline
, and
wordWrap
. Each section also
applies the text format object created in an earlier section, and sets the grid fit type to
normal
,
pixel
, or
subpixel
. The fifth, and final, section creates a LoadVars instance,
which loads the contents of an external text file into each of the text fields that you created
with code.
9.
Save the document and select Control > Test movie to test the SWF file.
Each text field should be initialized with the value “
loading
...”. After the external text file
is successfully loaded, each text field displays some formatted sample text using a different
grid-fit type.
Using the TextFormat class
You can use the TextFormat class to set the formatting properties of a text field. The
TextFormat class incorporates character and paragraph formatting information. Character
formatting information describes the appearance of individual characters: font name, point
size, color, and an associated URL. Paragraph formatting information describes the
appearance of a paragraph: left margin, right margin, indentation of the first line, and left,
right, or center alignment.
To use the TextFormat class, you first create a TextFormat object and set its character and
paragraph formatting styles. You then apply the TextFormat object to a text field using the
TextField.setTextFormat()
or
TextField.setNewTextFormat()
method.
The
setTextFormat()
method changes the text format that is applied to individual
characters, to groups of characters, or to the entire body of text in a text field. Newly inserted
text, however—such as text entered by a user or inserted with ActionScript—does not assume
the formatting specified by a
setTextFormat()
call. To specify the default formatting for
newly inserted text, use
TextField.setNewTextFormat()
. For more information, see
setTextFormat (TextField.setTextFormat method) and setNewTextFormat
(TextField.setNewTextFormat method) in the
ActionScript 2.0 Language Reference.
TI
P
The FlashType rendering technology uses grid fitting only at 0º rotation.
Summary of Contents for FLASH 8-LEARNING ACTIONSCRIPT 2.0 IN FLASH
Page 1: ...Learning ActionScript 2 0 in Flash...
Page 8: ...8 Contents...
Page 18: ...18 Introduction...
Page 30: ...30 What s New in Flash 8 ActionScript...
Page 66: ...66 Writing and Editing ActionScript 2 0...
Page 328: ...328 Interfaces...
Page 350: ...350 Handling Events...
Page 590: ...590 Creating Interaction with ActionScript...
Page 710: ...710 Understanding Security...
Page 730: ...730 Debugging Applications...
Page 780: ...780 Deprecated Flash 4 operators...
Page 830: ...830 Index...