Input Text

I l @ ve RuBoard

In Flash, users can also type in an input text field. You can have them enter a series of characters , and then you can access what they typed with ActionScript.

To allow the user to type, you'll need to create an input text field. This is done the same way as you would create any text in Flash. First, use the Text tool to draw a text area on the screen. Type something in it, such as input text so that it doesn't disappear if you use other tools.

Now, with this new text area selected, choose Window, Properties. You can also use the keyboard shortcut Command+F3 on Macs and Ctrl+F3 in Windows. You'll get a panel that looks like Figure 9.1.

Figure 9.1. The Properties panel allows you to see almost every property about a text area. The small triangle allows you to expand or contract the bottom portion.

graphics/09fig01.jpg

To make a text area an input text field, you'll need to change its type with the pop-up menu at the upper-left corner of the panel. In Figure 9.1, it is already set to Input Text.

You can use this panel to adjust the font and font settings used by this field. You can also change how the field lays out the text with the pop-up menu item set to Single Line in Figure 9.1. You can also set it to Multiline so that the user can type large amounts of wrapped text into a larger input field. Multiline No Wrap forces the user to press Return between lines. Password hides the letters the user types, using "*" instead of each character.

The third little button to the right of that pop-up menu is also handy. You can select it so that there is a border around the text field.

The most important setting to the ActionScript programmer is the Var property. You'll need to set this to the name of a variable that the input text represents. This means that the value of that variable will be the same as the contents of that input text. As the user changes it, the variable changes as well.

The example movie 09input.fla contains a simple input text field and a button. Test the movie, type some text into the input text field, and press the button. The contents of the input text will be sent to the Output window.

The code to do this is simple. First, the input text field is set so that it is linked to the variable myVariable . That is how Figure 9.1 is set as well. Then, this code on the button puts the contents of this variable to the Output window.

 on(release) {     trace(myVariable); } 

That's all it takes to get the value of a text input field. It is so easy that it hardly requires any new ActionScript knowledge at all. You just have to remember to set the Var property of the text input field. Also remember that this is a global variable that only exists on the level where the field is located. So if you place it in a movie clip, you will have to refer to the variable as part of the movie clip to access it from the root level.

I l @ ve RuBoard


Sams Teach Yourself Flash MX ActionScript in 24 Hours
Sams Teach Yourself Flash MX ActionScript in 24 Hours
ISBN: 0672323850
EAN: 2147483647
Year: 2002
Pages: 272

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