User Guide
Controlling text with ActionScript 127
Each character in a text field may individually be assigned a TextFormat object. The TextFormat
object of the first character of a paragraph is examined to perform paragraph formatting for the
entire paragraph.
To format text dynamically:
1.
Select Window > Development Panels > Actions to open the Actions panel if it isn’t
already open.
2.
Do one of the following to create a text field:
■ Use the Text tool to create a text field on the Stage. Assign the text field an instance name in
the Property inspector.
■ For this example, enter the instance name myText.
■ Use the createTextField method of the MovieClip object. See “Creating text”
on page 108. For this example, enter the instance name myText as a parameter of the
createTextField method.
3.
Do one of the following to place text in the text field:
■ Enter text into the text field on the Stage.
■ Set the text property of the TextField object. See “Creating text” on page 108.
■ In the Actions toolbox, select the Built-in classes category, then select the Movie category,
and then select the TextFormat category. Finally, double-click
new TextFormat. For this
example, enter myformat in the Object parameter field.
The following code is displayed in the Script pane:
myformat = new TextFormat();
4.
In the Actions toolbox, select the Built-in Classes category, then select the Movie category, then
select the TextFormat category, and then select the Properties category. Finally, double-click
color. Repeat this step for the bullet and underline properties. The following code is
displayed in the Script pane:
myformat.color = 0xff0000;
myformat.bullet = true;
myformat.underline = true;
5.
In the Actions toolbox, select the Built-in Classes category, then select the Movie category, then
select the TextField category, and then select the Method category. Finally, double-click
setTextFormat. For this example, enter myText in the Object parameter field.
6.
In the Object field, enter the name of the TextFormat object you created in step 3, myformat.
The following code appears in the Script pane:
mytext.setTextFormat(myformat);
For more information, see “Using the TextFormat class” in Using ActionScript in Flash.
Using text field events to trigger scripts
You can use ActionScript to capture events that happen to text fields—for example, you can
determine whether a user has changed or scrolled the text. You can write ActionScript statements
that use these events to trigger scripts to run.