The Last Quiz

Here’s one final version of the multiple-choice quiz we started way back in Chapter 1. This updated version of the quiz dynamically generates all of the quiz’s questions and answers using movie clips, so our quiz is infinitely scalable and highly configurable. In fact, we’re not far off from making the entire quiz a Smart Clip that could be customized by non-programmers.

The code for the quiz is shown in Example 13.5 and available from the online Code Depot. Because the quiz is now completely dynamically generated, 99% of the code fits entirely on one frame; we no longer need to fill a timeline with questions. (All we’re missing is a preloader to ensure smooth playback over a network.) Note that we’ve used #include to import a block of code from an external text file. For more information on #include, see Part III, and see Section 16.7 in Chapter 16. As an exercise, try adding new questions to the quiz by creating new objects and placing them in the questions array.

Though the code for the final quiz is relatively short, it’s packed full of important techniques. With the exception of #include, we’ve seen all of them in isolation before, but this extended real-world example shows how they can all fit together. Study the comments carefully—when you understand this version of the quiz in its entirety you’ll be well-equipped to create advanced applications with ActionScript.

A longer explanation of the code in this quiz is available at:

http://www.moock.org/webdesign/lectures/ff2001sfWorkshop ...

Get ActionScript: The Definitive Guide now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.