Task: User Input Form

I l @ ve RuBoard

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.

  1. 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.

  2. 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.

  3. 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.

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

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

     on (release) {     clearForm(); } 
  6. The button on the right has this one:

     on (release) {     submitForm(); } 
  7. 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 = ""; } 
  8. 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);     } } 

As you can see, there is not much to getting input from the user. All you need to do is create the text input fields and link them to variables. Then, the variables are yours to use and manipulate.

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