TextField.variable Property

ActionScript for Flash MX: The Definitive Guide, 2nd Edition
By Colin Moock
Chapter 18.  ActionScript Language Reference
TextField.variable Property Flash 6

associates a variable with the text property read/write
theField.variable

Description

The string variable property is a backward-compatibility feature that specifies a regular variable whose value will mirror the value of theField.text. This allows for direct Flash 5-style assignment of a value to a text field. The following example creates a text field object with an instance name of firstName_txt and associates it with the variable userName. Subsequent assignments to userName are displayed in firstName_txt and reflected by its text property.

this.createTextField("firstName_txt", 1, 0, 0, 200, 20); firstName_txt.variable = "userName"; // Displays "Colin" on screen userName = "Colin"; // Check the text property trace(firstName_txt.text);  // Displays: Colin

Conversely, assignments to firstName_txt.text are reflected by the variable userName:

firstName_txt.text = "Bruce"; trace(userName);  // Displays: Bruce

The variable reference can be constructed with dot notation, allowing variables on objects and other timelines to be used:

firstName_txt.variable = "_level0.someClip.someVariable";

When exporting to Flash 5 and prior versions, the variable property must be set in the Flash MX authoring tool, in the Property inspector under "Var:". When coding for Flash 6, the variable property should be avoided in favor of the text property.

Note that the variable property stores the name of the variable, not its value. It is used only to establish the link between a regular variable and theField.text:

trace(firstName_txt.variable);  // Displays: userName

See Also

TextField.htmlText, TextField.text



    ActionScript for Flash MX. The Definitive Guide
    ActionScript for Flash MX: The Definitive Guide, Second Edition
    ISBN: 059600396X
    EAN: 2147483647
    Year: 2002
    Pages: 780
    Authors: Colin Moock

    flylib.com © 2008-2017.
    If you may any questions please contact us: flylib@qtcs.net