Flash CS3 Documentation |
|||
| Learning ActionScript 2.0 in Adobe Flash > Working with Text and Strings > About text fields > 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.
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.
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.";
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 |
For samples that demonstrate how to work with text fields using ActionScript, see the Flash Samples page at www.adobe.com/go/learn_fl_samples. Download the Samples zip file and navigate to the ActionScript 2.0/TextFields folder to access these samples:
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/00000882.html