User-Input Text Fields
User-input text fields differ from dynamic text fields only in that they may be edited by the user while the movie is playing. That is, a user can type into a user-input text field to change its value. ActionScript can then retrieve and manipulate the user-entered value. User-input text fields are useful for guest books, order forms, password-entry fields, or anywhere you request information from the user.
Creating a User-Input Text Field
To create a user-input text field, follow the same steps described earlier under Section 18.1.1, but choose Input Text instead of Dynamic Text from the Text Type menu.
Changing the Content of an Input Text Field
Like dynamic text fields, user-input text fields may be changed at any time simply by setting the value of the named text field with an assignment statement:
myInputText = "Type your name here";
Because user-input text fields are normally used to accept data rather than display data, we don’t usually set their contents except to provide a default value for the user’s input.
Retrieving and Using the Value of an Input Text Field
You can retrieve the value of a text field by
simply referring to it by name in a script. For example, to display
the value of an input text field called myInput,
use:
trace(myInput);
Because data entered by the user into a user-input text field is always a string datatype, we should convert it explicitly before using it in a non-string context, as demonstrated in this simple calculator example that totals ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access