MACROMEDIA FLASH 8-LEARNING ACTIONSCRIPT 2.0 IN FLASH Manual page 387

Learning actionscript 2.0 in flash
Table of Contents

Advertisement

Do not confuse a text field's instance name with its variable name, however. A text field's
variable name is a variable reference to the text contained by that text field; it is not a reference
to an object.
For example, if you assigned a text field the variable name
following code to set the contents of the text field:
var myTextVar:String = "This is what will appear in the text field";
However, you can't use the variable name
have to use the instance name, as shown in the following code:
// This won't work.
myTextVar.text = "A text field variable is not an object reference";
// For input text field with instance name "myField", this will work.
myField.text = "This sets the text property of the myField object";
Use the
TextField.text
targeting a version of Flash Player that doesn't support the TextField class. This reduces the
chances of a variable name conflict, which could result in unexpected behavior at runtime.
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.
Creating text fields at runtime
You can use the
createTextField()
field on the Stage at runtime. The new text field is attached to the timeline of the movie clip
that calls the method.
To dynamically create a text field using ActionScript:
1.
Select File > New and then select Flash Document to create a new FLA file.
2.
Type the following ActionScript on Frame 1 of the Timeline:
this.createTextField("test_txt", 10, 0, 0, 300, 100);
This code creates a 300 x 100-pixel text field named
and a depth (z-order) of 10.
myTextVar
property to control the contents of a text field, unless you're
method of the MovieClip class to create an empty text
, you can use the
myTextVar
to set the text field's
text
with a location of (0, 0)
test_txt
About text fields
property. You
387

Hide quick links:

Advertisement

Table of Contents
loading
Need help?

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?

This manual is also suitable for:

Flash 8

Table of Contents