Categories
Featured jobs
» More ActionScript, Flash and Flex jobs.
» Advertise a job for free
Our network
Advertisement

 »  Home  »  Tutorials  »  Flash  »  Beginner  »  Create a Quiz Application Using AS3 Classes

Create a Quiz Application Using AS3 Classes

By Jody Hall | Published 02/1/2008 | Beginner | Rating:
Jody Hall
My interest in Flash started mostly because of a Jib-Jab cartoon ("This Land") in 2004. I'm the author of a feature I call "Mazoons," which are a combination of mazes and cartoons. In 2002, I even had a book published, "Super Silly Mazes." I'm not a professional programmer, but making my mazes interactive by programming them with Flash has become a hobby/obsession of mine in recent years. My efforts so far can be seen at http://www.mazoons.com/Flash_mazes.htm.  

View all articles by Jody Hall
The Initial Concept
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.

QuizApp.as, 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.

QuizQuestion.as, 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:



Spread The Word / Bookmark this content

Clesto Digg it! Reddit Furl del.icio.us Spurl Yahoo!

Comments
  • Comment #1 (Posted by Andrew - macklin.andrew at gmail.com)
    Rating
    I have been struggling for a while with getting a class to 'use' another class. Everything is either too complicated or lacks any content or practical sample. Mr Hall writes - and explains - very clearly and comprehensively; I did not 'get lost' at any stage doing this tutorial (and I generally loathe tutorials). I recommend this to anyone who is trying to get to grips with AS3 Classes.
     
  • Comment #2 (Posted by rich - flashbam at yahoo.com)
    Rating
    for anyone having trouble getting this tutorial working (getting bunch of errors), read this:

    http://www.actionscript.org/forums/showthread.php3?t=158139


     
Submit Comment



Search Entire Site
Add to Google
Advertisements
Article Options
Latest New Articles
Set up a simple IIS Server for Flash
by Peter McBride

Day 1 at FITC Toronto 2008
by Anthony Pace

Simple reflection effect with AS2
by Jean André Mas

ActionScript.org Meets Josh Tynjala (aka dr_zeus)
by ActionScript.org Staff

Rapidly Create Online Flash Movies to Help Users Market, Sell and Support Software and Hardware
by Sabrina F

mailing list
Enter your email address:
mailing list
Subscribe Unsubscribe
© 2000-2007 actionscript.org! All Rights Reserved.
Read our Privacy Statement and Terms of Use...
Our dedicated server is hosted and managed by WebScorpion Webhosting.