8.1. Referring to a Text Field via ActionScript

Problem

You want to refer to a text field via ActionScript.

Solution

Refer to author-time text fields by their instance names.

Discussion

Many of the recipes in this chapter require you to access a text field’s methods or properties. Sometimes text fields are created at runtime via ActionScript, but often you’ll want to adapt a recipe to work with your author-time content.

ActionScript refers to author-time text fields using the text field instance name, which must be set, as follows:

  1. Select the text field instance on the Stage.

  2. Open the Property inspector.

  3. Change the text field’s type from “Static Text” to “Dynamic Text” (change it to “Input Text” if you want to allow user input at runtime).

  4. Specify an instance name in the Property inspector (the instance name field appears once you complete Step 3).

See Also

To refer to a text field created at runtime, use the TextField instance returned by MovieClip.createTextField( ), as demonstrated in Recipe 8.2. For details on creating editable text fields, see Recipe 8.5.

Get Actionscript Cookbook now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.