Controlling text with ActionScript 185
To create a dynamic text field:
1. Select a frame, button, or movie clip that is to receive the action.
2. Select Window > Actions to open the Actions panel if it isn’t already open.
3. In the Actions toolbox, select the Built-in Classes category, then select the Movie category,
then select the MovieClip category, and then select the Methods category. Finally, double-
click the
createTextField() method.
4. Select the placeholder instanceName and enter an instance name or path for the movie clip
that will be the parent of the new text field. For this example, enter the alias _root because
the main Timeline is the parent.
5. Enter values for the following parameters:
■ Instance Name is the instance name of the new text field. For this example, enter
myText.
■ Depth is a number that specifies the stacking order. For this example, enter 1.
■ X is the x coordinate relative to the parent clip. For this example, enter 50.
■ Y is the y coordinate relative to the parent clip. For this example, enter 50.
The following code is displayed in the Script pane:
_root.createTextField("mytext",1,50,50,200,100);
6.
In the Actions toolbox, select the Built-in Classes category, then select the Movie category,
then select the TextField category, and then select the Properties category. Finally, double-
click the
text property to create a new line. For this example, replace the placeholder
instanceName with myText in the Object parameter field.
7. In the Value field, enter this is my first text field object text. The following text is displayed
in the Script pane:
mytext.text = "this is my first text field object text";
This example creates a text field with an instance name myText, a depth of 1, a width of
200, a height of 100, an x value of 50, and a y value of 50.
For a detailed description of the
createTextField method of the TextField object, see
TextField in ActionScript 2.0 Language Reference.
Setting text field properties dynamically
To use ActionScript to set the properties of a text field, you must assign the text field an
instance name. If you create the text field on the Stage with the Text tool, you can assign the
instance name in the Property inspector. If you create the text field dynamically, you can
assign an instance name as a parameter of the
createTextField method.