Unlimited Plugins, WordPress themes, videos & courses! Unlimited asset downloads! From $16.50/m
  1. Code
  2. Apps

Create a Customizable Flash Quiz Application


We’re going to design a clean interface, created with the Flash Tools, which we’ll use along with ActionScript and XML to develop a Quiz application capable of loading images, text and sounds.

Step 1: Brief Overview

A clean interface created with the Flash Tools will be used along with ActionScript and XML to develop a Quiz application capable of loading images, text and sounds.

Step 2: Flash Document Settings

Open Flash and create a 480 pixels wide, 320 pixels tall document. Set the Frame rate to 24fps.

Step 3: Interface

The interface consists of simple graphics, MovieClips and TextFields. We'll look at how it was made in the following steps.

Step 4: Background

Select the Rectangle Primitive Tool (R) and create a #D9E6EF - #F6F9FF, 450x290px rectangle, change the corner radius to 12 and convert it to a MovieClip. Use the following filter to get the inner look:

Step 5: Title


Use a font that you like to create the application title, you can also add an icon to make it look even better. I opted for Aller Bold, freely available from FontSquirrel.com.

Step 6: Buttons

Using the same tool as for the background, create two 80x24px rectangles and fill them with #0086C6. Use the Text Tool (T) to add a label to them and convert them to Buttons. Set their instance names to playB and creditsB.

This will complete the Menu Screen; convert the elements in stage to a single MovieClip and name it menuScreen.

Step 7: Question Panel

Here we start building the Game Screen.

Reuse the background and title created in the previous steps and use the Rectangle Primitive Tool to create a 360x48px rectangle. Add a Dynamic TextField with the Text Tool and name it questionTF. Convert both to MovieClip and name it qPanel.

Step 8: Answer Panel

Repeat the process used before with four 140x38px rectangles, name them button1 to button4 and convert them all to a single MovieClip named aPanel. Name the text fields within the buttons oneTF, twoTF, threeTF, and fourTF, respectively.

Step 9: Credits Screen

The Credits Screen will show the year and copyright of the game.

It will be pretty simple to create as we already have all the elements used in it.

Convert the graphics to a MovieClip and name it CreditsScreen, remember to mark the Export for ActionScript box.

Step 10: Game Over

This screen will appear when the quiz is finished, it shows the final score percentage and the questions you answered right or wrong.

Use the Text Tool to add three Dynamic TextFields and name them scoreTF, caTF, and waTF. Convert the graphics to a MovieClip and name it GameOver, remember to mark the Export for ActionScript box.

Step 11: Tween Nano

We'll use a different tween engine from the default included in Flash, this increases performance as well as being easier to use.

You can download Tween Nano from its official website. See this guide to learn how to add the engine to your project.

Step 12: Soungle

We'll include the ability to add sound to the quiz; you can find the sound used in this example at Soungle.com using the keyword phone ring.

Step 13: XML

An XML file will be used to get all the quiz data, this includes questions, possible answers, correct anwers, images and sounds. Open your favorite XML editor and write the following code:

As you can read in the code, it is really easy to spot which part does what so there shouldn't be any problem here. Remember that we will build the engine to interpret this file, this means you can add/edit/remove any questions here as long as you follow this basic structure.

Step 14: Create a new ActionScript Class

Create a new (Cmd + N) ActionScript 3.0 Class and save it as Main.as in your class folder.

Step 15: Class Structure

Create your basic class structure to begin writing your code.

Step 16: Required Classes

These are the classes we'll need to import for our class to work; the import directive makes externally defined classes and packages available to your code.

Step 17: Variables

These are the variables we'll use, read the comments in the code to find out more about them, some of their names are self explanatory so there will be no comment there.

Step 18: Constructor

The constructor is a function that runs when an object is created from a class; this code is the first to execute when you make an instance of an object, or the first function to run in your project if in the Document Class.

It calls the necessary functions to start the game. Check those functions in the next steps.

Step 19: Load XML

This function uses the xmlLoader instance to load the file specified in the parameter. The listener added to the object will call the a function when the load is complete.

Step 20: Parse XML

The next code assigns the data loaded from the external file to the variable, this will allow us to use that data in any part of our class.

Step 21: Prepare Game

When the user clicks on the Start button the following code is executed:

This will tween the main screen to make it invisible by the user and then remove it, it also calls a function that will load the first question.

Step 22: MovieClip Button Mode

We can't access instance names of a TextField inside a button, but using MovieClips will remove the hand cursor that indicates that the element is interactive. The next code will make the hand cursor appear when hovering over any of the buttons.

Step 23: Change Question

This is the main function in this class, it performs most of the operations that will load and handle the loaded questions. Read through the next steps to see its behavior.

The arguments here determine the question to be loaded and the correct answer.

Step 24: Check Total Questions

These lines check if there is a next question; if there isn't, it calls the gameOver function.

Step 25: Set Possible Answers

If there is another question, the TextFields in the question panel are filled with the corresponding information.

Step 26: Set Correct Answer

The correct answer parameter is passed to a variable to determine when the button clicked was the correct one or not. At the moment we always use the fourth answer as the correct one.

Step 27: Tween Panels

When the questions and answers are set, the panels are shown.

Step 28: Update Question Counter

This line changes the value of the question counter in the bottom-right corner, it shows the current question and the questions left for the quiz to end.

Step 29: Check for Images

If the parameter image in the xml has a value, the image in the url is loaded.

Step 30: Display Image

Then is placed in stage and tweened to its position.

Step 31: Check for Sounds

If the parameter sound in the xml has a value, the file in the url is loaded.

Step 32: Play Sound

When the load in complete, the sound is played.

Step 33: Remove Menu

This is the function that will remove the menu screen from the display list and declare the variable as null to let it be cleared from memory.

Step 34: Show Credits

The following code calls the credits screen, it uses a variable to instantiate the MovieClip and then tween it to the stage.

Step 35: Remove Credits

This lines will tween out and destroy the credits screen when clicked.

Step 36: Check Answer

When the user clicks on an answer this function is executed. It will check whteher the selected answer is correct or not and increase the appropiate counter. Then a new question is loaded.

Step 37: Game Over

If there are no more questions to load, the game over function starts. It will display the game over screen add a listener to it to restart.

Step 38: Final Score

The final score will be shown in the game over screen, the next line sets it.

Step 39: Restart Function

The next funcion will reload the swf, restarting any variable and method.

Step 40: Set Main Class

Add the class name to the Class field in the Publish section of the Properties panel to associate the FLA with the Main document class. You can now run the Quiz.

Step 41: Shuffle the Answers

You may have noticed that the fourth answer is always the correct one. We can fix that by putting the answers into an array and then shuffling it, see this guide for more information. Change the appropriate code in changeQuestion() like so:


Try adding your custom questions and graphics, remember that you only need to modify the XML file to make another Quiz!

I hope you liked this tutorial, thank you for reading!

Looking for something to help kick start your next project?
Envato Market has a range of items for sale to help get you started.