EasyManua.ls Logo

MACROMEDIA FLASH 8-LEARNING ACTIONSCRIPT 2.0 IN FLASH - Page 420

MACROMEDIA FLASH 8-LEARNING ACTIONSCRIPT 2.0 IN FLASH
830 pages
Print Icon
To Next Page IconTo Next Page
To Next Page IconTo Next Page
To Previous Page IconTo Previous Page
To Previous Page IconTo Previous Page
Loading...
420 Working with Text and Strings
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, such as 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. Select Frame 1 on the Timeline and open the Actions panel (Window > Actions).
4. Enter the following code in the Actions panel to create a TextFormat object, set the bold
and
italic properties to true, and set the size property to 24:
// Create a TextFormat object.
var txt_fmt:TextFormat = new TextFormat();
// Specify paragraph and character formatting.
txt_fmt.bold = true;
txt_fmt.italic = true;
txt_fmt.size = 24;
5.
Apply the TextFormat object to the text field you created in step 1 by using
TextField.setTextFormat():
myText_txt.setTextFormat(txt_fmt);
This version of setTextFormat() applies the specified formatting to the entire text field.
Two other versions of this method 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 three characters you entered in the text field:
myText_txt.setTextFormat(0, 3, txt_fmt);
For more information, see setTextFormat (TextField.setTextFormat method) in the
ActionScript 2.0 Language Reference.
6. Select Control > Test Movie to test the application.
For more information on using the TextFormat class, see the following topics:
“Default properties of new text fields” on page 421
“Formatting text with Cascading Style Sheet styles” on page 421

Table of Contents

Related product manuals