Macromedia Studio 8 [Electronic resources] : Training from the Source

Jeffrey Bardzell, Shaowen Bardzell

نسخه متنی -صفحه : 240/ 193
نمايش فراداده

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.

1.

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 below the List component, 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.

[View full size image]

2.

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.

Note

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, as it did with the radio buttons .

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

3.

Click Frame 20 of the actions layer, and in the Actions panel, enter the following script after the existing code .

q3_button.onRelease = function() {
if (q3_list.selectedItem.data == undefined) {
Alert.show("Please make a selection before continuing.", "Error",
Alert.OK);
} else {
if (q3_list.selectedItem.data == "c") {
score++;
}
trace(q3_list.selectedItem.data);
trace("The current score is " + score);
gotoAndStop("q4_label");
}
};

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 and all instances of q2_combo to q3_list, as well as changing 999 to undefined, "b" to "c", and q3_label to q4_label.

[View full size image]

Install the Zinc trial version (Windows only) of Zinc on your computer by following these steps:

1.

Locate the file zinc_trial_setup.exe in the Software folder on the CD-ROM for this book and double-click the file to open it.

2.

Follow the installer's instructions to install Zinc.

3.

After installation, launch the application.

When launching Zinc for the first time, you get a pop-up window asking what type of application you want to create. The choices range from PC applications to Mac or Pocket PC applications. In this book, we'll cover only the PC desktop applications. Click Desktop Application.

You can control a variety of Zinc settings (see figure). The following is a brief overview of some of the most important available options and settings:

[View full size image]

Now that you know 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 that the Output window will display the final score. Next, 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.

[View full size image]

6.

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.

Note

When you're testing Flash movies in a browser, the Output window doesn't display. The Output displays only inside the Flash-authoring environment .