Working with Text and HTML in Flash - Creating text fields at runtime
(Page 2 of 6 )
You can create an empty text field on the Stage at runtime using the createTextField()method of the MovieClip class. The new text field is attached to the Timeline of the movie clip that calls the method. The createTextField()method uses the following syntax:
movieClip.createTextField(instanceName, depth, x, y, width, height)
Example:
_root.createTextField("sample_txt", 1, 0, 0, 200, 150);
The above example creates a text field with instance name “sample_txt”, 200 pixels wide and 150 pixels high at location (0,0) and a depth of 1.
You use the instance name specified in the createTextField()call to access the methods and properties of the TextField class.
After creating the text as shown above, you can set some of its properties as shown below:
sample_txt.multiline = true;
sample_txt.wordWrap = true;
sample_txt.autoSize = true;
sample_txt.html = true;
sample_txt.background = true;
sample_txt.backgroundColor = “
0x003366”;
test_txt.text = "Sample text field created with
createTextFieldmethod
of movie clip class";
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.
The following are the default properties that will be applied when creating a text field using the createTextField() method of movie clip class:
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)
Note that the default font property on the Mac OS X is Times.
Next: Using TextFormat Class >>
More Flash Articles
More By Adi Reddy Mora