FLASH MX: CREATING A QUIZ APPLICATION USING XML

HANDLING MULTIPLE QUIZES

Casale Media - the world's fastest growing online advertising network!


Suppose you want to allow user to select several quizes:

  • Trivia
  • Entertainment
  • Sport

You can create a folder and copy a separate swf and quiz.xml file for each folder depending on the category.  However, there's a more elegant way by using what is called the Query String.

With this method, instead of loading from test.xml, we can make Flash look for the filename in the query string. The code in Frame 1 needs to be changed to the following (notice the change from test.xml to _root.xmlFilename).
var myData=new XML();
myData.ignoreWhite=true;
myData.onLoad=onQuizData;
myData.load(_root.xmlFilename);
stop();	 // I'm telling Flash not to continue until the XML is loaded.

The xmlFilename then needs to be appended to the EMBED and OBJECT tag of the html page, like below:

<OBJECT classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000"
 codebase="http://download.macromedia.com/../flash/swflash.cab#version=6,0,0,0"
 WIDTH="550" HEIGHT="400" id="quiz4" ALIGN="CENTER">
 <PARAM NAME=movie VALUE="quiz.swf?xmlFilename=test2.xml">
 <PARAM NAME=quality VALUE=high>
 <PARAM NAME=bgcolor VALUE=#FFFFFF> 
 <embed src="quiz.swf?xmlFilename=test2.xml" quality="high" 
 bgcolor="#FFFFFF" WIDTH="550" HEIGHT="400" NAME="quiz4" 
 ALIGN TYPE="application/x-shockwave-flash" 
 PLUGINSPAGE="http://www.macromedia.com/go/getflashplayer">
</OBJECT>                	
								
              
You need to replace test2.xml with whatever filename you are using.

This post explains more about Query String: link.

CAUTION -- AGAIN!

  
Anyone who is proficient in computer has a potential to hack into the application and see all the answers.  To illustrate the risk, consider this:
You can type this into the browser and see the questions and answer for all the items on the quiz:
http://www.permadi.com/tutorial/flashMXQuiz/quiz.xml

We could add more security measures to avoid this.  For example, we can separate the questions from the answer; or we can force the application to get check the answer by comparing user answer through a server connection (using getURL or loadVariables, or XMLSocket).  

The point is: this application should not be used for serious use because we are not even trying to make it secure.


<<
MORE TUTORIALS>>

(C) 2002 F. Permadi