About manipulating text fields
You can manipulate text fields that you create in a FLA file in several ways. You can
manipulate a text field as long as you assign an instance name in the Property inspector, or
you can assign one with code if you use code to create the field. The following simple example
creates a text field, assigns text to it, and changes the border property of the field:
this.createTextField("pigeon_txt", this.getNextHighestDepth(), 100, 100,
200, 20);
pigeon_txt.text = "I like seeds";
pigeon_txt.border = true;
For a complete list of properties in the TextField class, see the ActionScript 2.0 Language
Reference.
For examples of how to manipulate text fields, see the following sections:
"Changing a text field's position" on page 389
"Changing a text field's dimensions at runtime" on page 390
You can find sample source files that demonstrate how to work with text fields using
ActionScript. The source files are called textfieldsA.fla and textfieldsB.fla, and you can find
them in the Samples folder on your hard disk:
In Windows, browse to boot drive\Program Files\Macromedia\Flash 8\Samples and
Tutorials\Samples\ActionScript\TextFields.
On the Macintosh, browse to Macintosh HD/Applications/Macromedia Flash 8/Samples
and Tutorials/Samples/ActionScript/TextFields.
Changing a text field's position
You can change a text field's position on the Stage at runtime. You need to set new values for
the text field's
and
_x
To reposition a text field by using ActionScript:
1.
Create a new FLA file and save it as positionText.fla.
2.
Add the following ActionScript to Frame 1 of the Timeline:
this.createTextField("my_txt", 10, 0, 0, 300, 200);
my_txt.border = true;
my_txt.text = "Hello world";
my_txt._x = (Stage.width - my_txt._width) / 2;
my_txt._y = (Stage.height - my_txt._height) / 2;
3.
Save the Flash document and select Control > Test Movie to see the text field centered on
the Stage.
properties, as shown in the following example.
_y
About text fields
389
Need help?
Do you have a question about the FLASH 8-LEARNING ACTIONSCRIPT 2.0 IN FLASH and is the answer not in the manual?