Creating Text Fields At Runtime; Using The Textformat Class - MACROMEDIA FLASH MX 2004 - ACTIONSCRIPT Reference Manual

Actionscript reference guide
Hide thumbs Also See for FLASH MX 2004 - ACTIONSCRIPT:
Table of Contents

Advertisement

Creating text fields at runtime

You can use the
createTextField()
on the Stage at runtime. The new text field is attached to the Timeline of the movie clip that calls
the method. The
movieClip.createTextField(instanceName, depth, x, y, width, height)
For example, the following code creates a 300 x 100 pixel text field named
(0,0) and a depth (z-order) of 10.
_root.createTextField("test_txt", 10, 0, 0, 300, 100);
You use the instance name specified in the
properties of the TextField class. For example, the following code creates a new text field named
, and then modifies its properties to make it a multiline, word-wrapping text field that
test_txt
expands to fit inserted text. Lastly, it assigns some text to the text field's
_root.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
createTextField()
the Timeline during authoring.
For more information, see
TextField.removeTextField()

Using the TextFormat class

You can use the ActionScript TextFormat class to set formatting properties of a text field. The
TextFormat class incorporates character and paragraph formatting information. Character
formatting information describes the appearance of individual characters: font name, point size,
color, and an associated URL. Paragraph formatting information describes the appearance of a
paragraph: left margin, right margin, indentation of the first line, and left, right, or
center alignment.
To use the TextFormat class, you first create a TextFormat object and set its character and
paragraph formatting styles. You then apply the TextFormat object to a text field using the
TextField.setTextFormat()
The
setTextFormat()
groups of characters, or to the entire body of text in a text field. Newly inserted text, however—
such as that entered by a user or inserted with ActionScript—does not assume the formatting
specified by a
setTextFormat()
use
TextField.setNewTextFormat()
TextField.setTextFormat()
on page
701.
method of the MovieClip class to create an empty text field
createTextField()
TextField.removeTextField()
. The
removeTextField()
MovieClip.createTextField()
on page
or
TextField.setNewTextFormat()
method changes the text format applied to individual characters, to
call. To specify the default formatting for newly inserted text,
on page 702
method uses the following syntax:
createTextField()
method to remove a text field created with
method does not work on a text field placed by
698.
. For more information, see
and
TextField.setNewTextFormat()
test_txt
call to access the methods and
property.
text
on page 494
and
methods.
Using the TextFormat class
at point
137

Advertisement

Table of Contents
loading
Need help?

Need help?

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

Questions and answers

Table of Contents