Creating Text Fields At Runtime - MACROMEDIA FLASH MX 2004-USING ACTIONSCRIPT IN FLASH Use Manual

Using actionscript in flash
Hide thumbs Also See for FLASH MX 2004-USING ACTIONSCRIPT IN FLASH:
Table of Contents

Advertisement

However, you can't use the variable name
to set the text field's
property. You
mytextVar
text
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";
In general, use the
property to control the contents of a text field, unless you're
TextField.text
targeting a version of Flash Player that doesn't support the TextField class. This will reduce the
chances of a variable name conflict, which could result in unexpected behavior at runtime.

Creating text fields at runtime

You can use the
method of the MovieClip class to create an empty text field
createTextField()
on the Stage at runtime. The new text field is attached to the Timeline of the movie clip that calls
the method. The
method uses the following syntax:
createTextField()
movieClip.createTextField(instanceName, depth, x, y, width, height)
For example, the following code creates a 30 x 100-pixel text field named
with a
test_txt
location of (0,0) and a depth (z-order) of 10:
this.createTextField("test_txt", 10, 0, 0, 300, 100);
You use the instance name specified in the
call to access the methods and
createTextField()
properties of the TextField class. For example, the following code creates a new text field named
, and modifies its properties to make it a multiline, word-wrapping text field that
test_txt
expands to fit inserted text. Then, it assigns some text to the text field's
property.
text
this.createTextField("test_txt", 10, 0, 0, 100, 50);
test_txt.multiline = true;
test_txt.wordWrap = true;
test_txt.autoSize = true;
test_txt.text = "Create new text fields with the MovieClip.createTextField
method.";
You can use the
method to remove a text field created with
TextField.removeTextField()
. The
method does not work on a text field placed by
createTextField()
removeTextField()
the Timeline during authoring.
For more information, see
and
MovieClip.createTextField()
in Flash ActionScript Language Reference.
TextField.removeTextField()
Note: Some TextField properties, such as _rotation, are not available when you create text fields
at runtime. You can rotate only embedded fonts.
Creating text fields at runtime
223

Advertisement

Table of Contents
loading
Need help?

Need help?

Do you have a question about the FLASH MX 2004-USING ACTIONSCRIPT IN FLASH and is the answer not in the manual?

This manual is also suitable for:

Flash mx 2004 - actionscript

Table of Contents