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

Lesson 16. A Component-Based Flash Quiz > Adding and Scripting a List Component

Adding and Scripting a List Component

This task is nearly identical to the previous task, both in the process of creating the interface and in the script you'll use to make it all work.

Click Frame 20 of the forms layer. Drag an instance of the List component onto the stage and give it an instance name of q3_list. Drag an instance of the Button component onto the stage beneath the List component, and give it an instance name of q3_button and change its label to Next Question.

The interface of the third question is almost finished, but you still need to populate the List with labels and data.

Select the List instance. In the Parameters tab of the Property inspector, populate the Data with a, b, c, d, and e. Populate the Labels with Minos, She-Wolf, Geryon, Cerberus, and Plutus.

As with the ComboBox, the Labels are the text users will see onscreen, and the Data is what will be passed with the form when the Next Question button is clicked.


You don't need an empty choice with a data value of 999 for the List. If no item is selected, the data value will come back as undefined like it did with the radio buttons.

Now the interface is complete, and you only need the ActionScript to make it work.

Click Frame 20 of the actions layer, and in the Actions panel, enter the following script:

q3_button.onRelease = function() {
  if (q3_list.selectedItem.data == undefined) {
    error_mc._visible = true;
  } else {
    if (q3_list.selectedItem.data == "c") {
    trace("The current score is " + score);
error_mc.ok_button.onRelease = function() {
  error_mc._visible = false;

Again, you can copy and paste the script from Frame 10 into Frame 20 and customize it by changing all instances of q2_button to q3_button, q2_combo to q3_list, and changing 999 to undefined, “b” to “c”, and q3_label to q4_label.

You are almost ready to test the movie, since the last two questions and their scripts have been written. Before you test, though, make one further change, so you can see the final score and verify that the scoring is working correctly.

Click Frame 40 of the actions layer, and in the Actions panel, find the following comment: // Insert code here to send data to ColdFusion script. Just before this comment, insert a new line, as follows:

trace("The final score is " + score + " out of 5");

You'll send the code to ColdFusion in Lesson 17. By adding this trace() line, you'll get some kind of visual feedback when you press the Next button, so you know the scripts are all working.

Test the movie and take the quiz.

The correct answers are as follows:

  1. Suicides' souls are so poisoned that they cast away their bodies

  2. Phlegyas

  3. Geryon

  4. Literature is greater than theology

  5. A pit

Knowing the correct answers, go through the quiz and answer all the questions correctly to ensure that your final score is 5. When you click Finish, nothing will happen except the Output window will display the final score. Then go through the test again, deliberately missing a couple questions, and make sure the score is still correct. Finally, go back through the quiz and try to click the Next Question/Finish button on each screen without making a selection. On all five screens, you should be blocked by the error message.

Save and close dante_quiz.fla.

If you like you can test the movie as it currently stands inside the browser, so you can see your username while you answer the questions.



Not a subscriber?

Start A Free Trial

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