Task: Simple Survey

I l @ ve RuBoard

Now let's use check boxes and radio buttons to make a simple application. Each frame of the movie 15survey.fla is a different question in a survey.

The first frame, shown in Figure 15.3, has a question that can be answered by a series of check boxes. Here's how to set it up:

Figure 15.3. This survey question can be answered using check boxes.

graphics/15fig03.gif

  1. Start with a blank movie.

  2. Make a check box button, like the one described earlier this hour . This should have two buttons, one on each frame, and the script described earlier. You can copy the check box movie clip from 15checkboxes.fla.

  3. Place five copies of the movie clip on the Stage. Name each one differently: Flash, Director, Fireworks, Freehand, and Dreamweaver.

  4. Create the title text and the static text to appear next to each check box. The result should look like Figure 15.3.

  5. Create a Next button as shown in Figure 15.3. In the example movie 15survey.fla, I have placed the buttons, text, and Next button on three separate layers to make it easier to edit them.

  6. A short script needs to be placed on the first frame of the movie. It creates an array to hold the results of the survey and also stops the movie on the first frame.

     results = new Array(); stop(); 
  7. The Next button needs to tally the results of the check boxes and store them in the results array.

     on (release) {     if (Flash.state) results.push("Flash");     if (Director.state) results.push("Director");     if (Fireworks.state) results.push("Fireworks");     if (Freehand.state) results.push("Freehand");     if (Dreamweaver.state) results.push("Dreamweaver");     nextFrame(); } 
  8. Now on to the second frame of the movie. This one uses radio buttons. The question asked has only one possible answer, so radio buttons are appropriate.

    Figure 15.4 shows frame 2 of the example movie. Insert a new frame after the first one. Do this for each layer if you are using more than one.

    Figure 15.4. This survey question uses radio buttons.

    graphics/15fig04.gif

    Copy the radio button from the 15radiobuttons.fla movie. Place three copies of it with the names Windows, Macintosh, and Linux.

  9. Add the title and static text to the frame as shown in Figure 15.4.

  10. Copy the Next button onto this frame as well but attach a different script to it. This one calls the getValue function in one of the radio buttons to determine which one is on.

     on (release) {     results.push(Windows.getValue());     nextFrame(); } 
  11. I'll leave it up to you to continue to add more questions to the survey. Each question should either use a series of check boxes or radio buttons. All the names of these elements should be unique.

    At the end of the survey, you can use trace to send the contents of results to the Output window. This will show the results of the survey.

In Hour 18, "Sending Information to the Server," you'll learn how to send this information back to your Web server to be recorded.

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