You can use the createTextField
method of the MovieClip object to create a new, empty text field as a child of the movie clip that calls the method. You can use the removeTextField
method to remove a text field created with createTextField
; it will not work on a text field placed by the Timeline.
When you create a text field, you can use the TextField object to set properties of the text field. If you don't set the properties, the new text field receives a set of default properties. The default properties of the new text field are as follows:
type = "dynamic" border = false background = false password = false multiline = false html = false embedFonts = false variable = null maxChars = null
Once you create a text field, you can use the TextFormat object to format the text. You must create a new TextFormat object and then pass it as a parameter to the setTextFormat
method of the TextField object. A text field created with the createTextField
method 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)
To create a dynamic text field:
createTextField
method.Instance Name
is the instance name of the new text field. For this example, enter myText.Depth
is a number that specifies the stacking order. For this example, enter 1.X
is the x coordinate relative to the parent clip. For this example, enter 50.Y
is the y coordinate relative to the parent clip. For this example, enter 50.The following code displays in the Script pane:
_root.createTextField("mytext",1,50,50,200,100);
text
. For this example, enter myText in the Object parameter field.mytext.text = "this is my first test field object text";
This example creates a text field with an instance name myText
, a depth of 1, a width of 200, a height of 100, an x value of 50, and a y value of 50.
For a detailed description of the createTextField
method of the TextField object, see its entry in the online ActionScript Dictionary in the Help menu.