MovieClip.createTextField


MovieClip.createTextField

Availability
Flash Player 6.

Usage
myMovieClip .createTextField ( instanceName , depth , x , y , width , height )

Parameters
instanceName A string that identifies the instance name of the new text field.

depth A positive integer that specifies the depth of the new text field.

x An integer that specifies the x coordinate of the new text field.

y An integer that specifies the y coordinate of the new text field.

width A positive integer that specifies the width of the new text field.

height A positive integer that specifies the height of the new text field.

Returns
Nothing.

Description
Method; creates a new, empty text field as a child of the movie clip specified by the MovieClip parameter. You can use the createTextField method to create text fields while a movie plays. The text field is positioned at ( x , y ) with dimensions width by height . The x and y parameters are relative to the container movie clip; these parameters correspond to the _x and _y properties of the text field. The width and height parameters correspond to the _width and _height properties of the text field.

The default properties of a text field are as follows:

type = "dynamic"
border = false
background = false
password = false
multiline = false
html = false
embedFonts = false
variable = null
maxChars = null

A text field created with createTextField receives the following default TextFormat object:

font = "Times New Roman"
size = 12
textColor = 0x000000
bold = false
italic = false
underline = false
url = ""
target = ""
align = "left"
leftMargin = 0
rightMargin = 0
indent = 0
leading = 0
bullet = false
tabStops = [] (empty array)

Example
The following example creates a text field with a width of 300, a height of 100, an x coordinate of 100, a y coordinate of 100, no border, red, and underlined text.

_root.createTextField("mytext",1,100,100,300,100);
mytext.multiline = true;
mytext.wordWrap = true;
mytext.border = false;

myformat = new TextFormat();
myformat.color = 0xff0000;
myformat.bullet = false;
myformat.underline = true;

mytext.text = "this is my first test field object text";
mytext.setTextFormat(myformat);

See also
TextFormat (object)

Source:

http://www.adobe.com/support/flash/action_scripts/actionscript_dictionary/actionscript_dictionary513.html

Creating text fields at runtime


You can use the createTextField() method of the MovieClip class to create an empty text 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 test_txt with a location of (0, 0) and a depth (z-order) of 10.

  3. To access the methods and properties of the newly created text field, use the instance name specified in the first parameter of the createTextField() method.For example, the following code creates a new text field named test_txt, and modifies its properties to make it a multiline, word-wrapping text field that expands to fit inserted text. Then it assigns some text using the text field’s text property:
    test_txt.multiline = true;
    test_txt.wordWrap = true;
    test_txt.autoSize = "left";
    test_txt.text = "Create new text fields with the MovieClip.createTextField() method.";
  4. Select Control > Test Movie to see the text field.The text is created at runtime and appears on the Stage.

You can use the TextField.removeTextField() method to remove a text field created with createTextField(). The removeTextField() method does not work on a text field placed by the timeline during authoring.

For more information, see createTextField (MovieClip.createTextField method) and removeTextField (TextField.removeTextField method) in the ActionScript 2.0 Language Reference.

NOTE Some TextField properties, such as _rotation, are not available when you create text fields at runtime. You can rotate a text field only if it uses embedded fonts. See To embed a font symbol:.

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.

source:

http://livedocs.adobe.com/flash/8/main/wwhelp/wwhimpl/common/html/wwhelp.htm?context=LiveDocs_Parts&file=00001419.html