Flash MX Text fields have instance names and variable names
Macromedia Flash 5 ActionScript does not include the ability to directly change a text field's properties. Text fields can be connected to variables names, allowing them to display dynamic content. In Flash 5, there are no text 'objects' and the Flash 5 ActionScript does not allow you to control any aspect of the text field other than the contents of the variable associated with the text field. Flash MX adds a number of objects and methods for managing text fields:
- 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. Use the removeTextField method to remove a text field created with createTextField.
- Use the TextField object to control the appearance of the text field on stage. TextField is used to control the alpha, borders, and font embedding, as well as the string content of the field.
For a complete list of properties, see the ActionScript Dictionary. - Use the TextFormat object for formatting the characters inside the text field.
Because of these new objects and methods, the Properties inspector in Flash MX has both an 'instance name' and a 'variable' field when a dynamic or input text field is selected. This can confuse users of earlier versions of Flash about when it's appropriate to use each field.
Generally the Var: field is used to display the contents of a variable inside the text field. The value of the Var: field is displayed as the text on the stage in the text field. Changing the content of the variable updates the text field. The Instance Name field is used to control a text field via ActionScript. Because the text field has an instance name it can be targeted and changed by ActionScript.
There are a few cases where either an instance name or a variable name can be used to achieve the same result:
- Setting the text of a field using a variable name:
- Create a dynamic text field on stage.
- Assign a variable name to the field in the Properties inspector:
- In ActionScript, assign a text string to the variable:
textResult = "Your score is" + finalScore
- Setting the text of a field using an instance name:
- Create a dynamic text field on stage.
- Assign an instance name to the field in the Properties inspector:
- In ActionScript, use the Textfield.text property of the Textfield object to assign a text string to the field:
myText.text = "Your score is " + finalScore
This content requires Flash
To view this content, JavaScript must be enabled, and you need the latest version of the Adobe Flash Player.
Download the free Flash Player now!
