createTextField (MovieClip.createTextField method)

public createTextField(instanceName:String, depth:Number, x:Number, y:Number, width:Number, height:Number) : TextField

Creates a new, empty text field as a child of the movie clip on which you call this method. You can use the createTextField() method to create text fields while a SWF file plays. The depth parameter determines the new text field's depth level (z-order position) in the movie clip. Each depth level can contain only one object. If you create a new text field on a depth that already has a text field, the new text field replaces the existing text field. To avoid overwriting existing text fields, use MovieClip.getInstanceAtDepth() method to determine whether a specific depth is already occupied, or the MovieClip.getNextHighestDepth() method to determine the highest unoccupied depth. 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
selectable = true
wordWrap = false
mouseWheelEnabled = true
condenseWhite = false
restrict = null
variable = null
maxChars = null
styleSheet = undefined
tabInded = undefined

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

font = "Times New Roman" // "Times" on Mac OS
size = 12
color = 0x000000
bold = false
italic = false
underline = false
url = ""
target = ""
align = "left"
leftMargin = 0
rightMargin = 0
indent = 0
leading = 0
blockIndent = 0
bullet = false
display = block
tabStops = [] // (empty array)

You can extend the methods and event handlers of the MovieClip class by creating a subclass.

Availability: ActionScript 1.0; Flash Player 6 - In Flash Player 8, this method returns a reference to the TextField object created, instead of void.

Parameters

instanceName:String - A string that identifies the instance name of the new text field.

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

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

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

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

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

Returns

TextField - Flash Player 8 returns a reference to the TextField object that is created. Flash Player versions earlier than 8 return void.

Example

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

this.createTextField("my_txt", 1, 100, 100, 300, 100);
my_txt.multiline = true;
my_txt.wordWrap = true;
var my_fmt:TextFormat = new TextFormat();
my_fmt.color = 0xFF0000;
my_fmt.underline = true;
my_txt.text = "This is my first test field object text.";
my_txt.setTextFormat(my_fmt);

For another example, see the Flash Samples page at www.adobe.com/go/learn_fl_samples. Download and decompress the Samples zip file and go to the ActionScript2.0\Animation folder to access the animation.fla file.

See also

getInstanceAtDepth (MovieClip.getInstanceAtDepth method), getNextHighestDepth (MovieClip.getNextHighestDepth method), TextFormat


Flash CS3


 

Send me an e-mail when comments are added to this page | Comment Report

Current page: http://livedocs.adobe.com/flash/9.0/main/00001902.html