• Create BookmarkCreate Bookmark
  • Create Note or TagCreate Note or Tag
  • PrintPrint
Share this Page URL

Hour 15. ActionScripting Applications fo... > Task: Use a Variable to Get the User...

Task: Use a Variable to Get the User's Name

This task involves letting the user input data (his or her name), and it also shows how you can monitor the user's input. Here are the steps:

In a new file, open the Properties panel and select the Text tool. Set the drop-down list for Text type to “Input Text” (the default is “Static Text”). Also, press in the Show Border Around Text button (as in Figure 15.8). Click once to create a block of text and type something like, “Please enter your name.” The little square at the bottom right of the text can be used to change the margins of the text box. One thing that's interesting about Input Text (and Dynamic Text) is that you can create a text block with nothing in it.

Figure 15.8. An Input Text block into which the user will type his or her name.

With the text block selected (using either your I-beam cursor in the field or the Arrow tool, select the entire block), set the Var: field in the Properties panel to read “username” (see Figure 15.8).

Put a stop Action in Frame 1.

Create a button and put an instance next to the text block you just created. Put a play Action on the button instance. The default mouse event, Release, is fine; however, in the event the user clicks Enter on the keyboard, this should effectively press the button too. Therefore, select the first line in the button script and click the check box labeled Key Press (in the parameter area). Make sure the I-beam cursor is blinking in the field next to Key Press and go ahead and press your Enter key (for Macintosh users, press your Return key). Notice that Flash fills in the key press option.

At frame 10, insert a blank keyframe (press F7) and create another text field. This one should be Dynamic Text (so the user can't edit it) and be associated with the variable message.

Now you're going to put a couple Actions in the keyframe on frame 10. Select the keyframe and then open the Actions panel. The first thing you'll do is to use the set variable Action (found under Actions, Variables) to populate the text field—or, more specifically, change the value of that variable. Insert a set variable Action while frame 10 is selected. Now you can specify the parameters.

The Variable field requires that you input the name of the variable. Type message into the Variable field.

The Value field is where you specify what goes into the variable. You're going to make it read “Welcome blank,” where “blank” is whatever name the user types into the field on frame 1. This is going to require you to build the string dynamically. Select the Expression check box to the right of the Value field, because you want Flash to evaluate what is typed (not automatically place quote marks around anything you type). You don't want Flash to use literally what is typed verbatim because you can't possibly know what the user's going to type. With Expression checked, in the Value field, type "Welcome " + username. The plus sign concatenates (or connects) these two items. The first part is simply the string “Welcome “ (notice the extra space). Because it's in quotes, Flash will display it exactly as typed. The second part refers to the variable username. Because this is not typed between the quotes, Flash will use the value of the variable, not its name.

Add another stop Action at frame 10. Using Test Movie, see how it works.

Populate is a popular term for the process of filling in data. It can be a manual process that you follow while editing or it can be done at runtime with scripting.



Not a subscriber?

Start A Free Trial

  • Creative Edge
  • Create BookmarkCreate Bookmark
  • Create Note or TagCreate Note or Tag
  • PrintPrint