8.3. Accepting User Input
Problem
You want to accept user input at runtime.
Solution
Use a text input or text area component.
Alternatively, create an input text field in the same way as you create a dynamic text field (see Recipe 8.1), except that instead of selecting Dynamic Text from the text type menu, select Input Text. Additionally, in most cases you should make sure that input text fields have a border, so that the user can see where to insert text. Optionally, you can create an input text field using ActionScript by first creating a dynamic text field with createTextField( ) and then setting the object’s type property to input.
Discussion
Flash provides two ways of accepting text input from the user: components and dynamic text fields. Each has its own advantages and disadvantages, so you should learn about each to best determine which to use.
In the UI components that ship with Flash, you can find two components for accepting user input: TextInput and TextArea. The text input component provides you with a rather simple way to create an input control that looks like a standard HTML text input control. All you need to do is drag-and-drop an instance from the Components panel to the stage, and give it an instance name in the Property inspector. Although the text input component makes it very simple for you to create a way to accept text that the user enters, that is not a distinct advantage over the dynamic text field, because the latter is quite simple as well. However, the text ...
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