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

Hour 9. Getting Input from the User > Task: User Input Form

Task: User Input Form

Flash is a good alternative to plain HTML forms. For one thing, the text in Flash is smooth and scalable and can use any font you want to embed in the movie. When you have a form in a Flash movie, you can also manipulate the data easily.

Open the movie 09form-noscripts.fla. This movie looks like Figure 9.2.

Figure 9.2. This Flash input form uses text input fields to gather data.

Many static text areas are just decoration. The labels FIRST NAME:, MIDDLE INITIAL:, and so on, play no part in the ActionScript but are necessary so that the user knows what to type in what area.

Each of the input text areas needs to be linked to a variable. Click on each one and check to see its name. The name will appear in the Properties panel if it is open. The first input text field is named firstName, for instance.

Also notice that each input text field has a Maximum Characters setting, which is set to be whatever makes sense for that field. The user can type 64 characters for her last name, for example, but only 1 character for her middle initial.

Also check the input field type. Most are Single Line. The address field is Multiline No Wrap, whereas the comments field is Multiline.

The two buttons at the bottom of the screen need simple button scripts. The one on the left has this script:

on (release) {

The button on the right has this one:

on (release) {

The functions that the buttons call are located in the first frame of the main timeline. The clearForm function simply places an empty string in each variable linked to an input text field. Add this function:

function clearForm() {
    firstName = "";
    middleInitial = "";
    lastName = "";
    address = "";
    city = "";
    state = "";
    zip = "";
    phone = "";
    comments = "";

The submitForm function would normally check the data for format and then submit some or all of it to the server. You'll learn about server communication in Hour 18, “Sending Information to the Server.”

For now, the function tests to see whether the user entered any middle initial. If he did, it sends the user's full name, complete with a period after the initial, to the Output window. It does the same if the user did not use a middle initial, but with just the first and last name.

function submitForm() {
    if (middleInitial.length == 1) {
        trace("Name: "+firstName+" "+middleInitial+". "+lastName);
    }  else {
        trace("Name: "+firstName+" "+lastName);



Not a subscriber?

Start A Free Trial

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