This article will demonstrate how to build a simple Flash quiz application using Classes. Each step, from concept to finished product, will be explained in detail. The finished application will run the user through a series of multiple choice questions. It will provide forward and back buttons to navigate to the previous or next question. When all of the questions have been answered, the application will compute the user's score.

To begin, here's a description of the concept. The application will consist of a fla file, a Document Class called QuizApp, and another class called QuizQuestion. And that's it! Two classes and a fla file! Each file will have it's own responsibilities, which we will define up front:

Quiz.fla: The fla file is not going to be responsible for very much at all. It will contain no code, and will serve simply as a container for the Document Class, and also its library will contain the components we will need. Since it's a multiple choice quiz, the RadioButton component will make an excellent choice for displaying the possible answers to each question. Also, rather than making customized buttons, we'll just use instances of the Button component., which we will make the Document Class of the fla file, will be responsible for posing the questions one at a time, by creating instances of QuizQuestion (and storing them in an Array). It will also create and position the previous, next, and finish buttons, and keep track of the current question. At the end it will compute and display the score. There will only be one instance of QuizApp. It will be the main application and perform most of the work., of which there will be many instances, conceptually will represent one question and series of possible answers. Each instance of QuizQuestion will store the question as a string, the multiple possible answers as an array of strings, the correct answer to each question as an integer, and the answer the user supplied as an integer. I'll show you how to build the QuizQuestion class, and how to make instances of it store all this information.

I hope you'll follow along and actually build this application. Or at least read the article and build the application using copy and paste. If you do, you'll learn many new things about classes and using objects made from those classes. The application is fairly simple (on purpose), but I think it does a good job of illustrating many important concepts. As always, I hope the result will be that you are inspired to take this knowledge and use it to build applications of your own.

The completed files are also included at the end of this article, at the bottom of the last page. Just download the attached ZIP file.

In these tutorials, I always strive to make sure that the end result is the creation of something that's actually useful. This Quiz application will be functional, but it's really just a starting point, as it (admittedly) could really use quite a bit more polish. Mostly, it's a teaching tool to further demonstrate classes and objects, and how they might be used to build a simple application. The idea is that even if you don't care to build a Quiz application, you can still use the concepts presented here as a springboard for an idea of your own.

Here's the application that we'll build: