Hi Guys,
I’m looking for a little assistance here if someone can spare the time to guide me a little with a problem.
I was working from a tutorial about creating a flash quiz that uses XML to hold the data to feed into flash. The site is http://www.permadi.com/tutorial/flashMXQuiz/index.html
The quiz looks pretty cool and works beautifully. However one thing struck me is that the quiz generates the same preset questions each time a user takes the quiz.
Is there a way of making the quiz generate random questions and respective answers without repeating them instead of the preset format it uses? If so, could someone be good enough to highlight the changes that need to be made in the existing code from that site to make this work randomly.
The XML part looks pretty straight forward and easily adaptable to include a lot more questions and answers.
Your knowledge and time would be greatly appreciated.
Reiver
here is the code In Frame 1 (actions layer)
function QuizItem(question)
{
this.question=question;
this.answers=new Array();
this.numOfAnswers=0;
this.correctAnswer=0;
this.getQuestion=function()
{
return this.question;
}
this.addAnswer=function(answer, isCorrectAnswer)
{
this.answers[this.numOfAnswers]=answer;
if (isCorrectAnswer)
this.correctAnswer=this.numOfAnswers;
this.numOfAnswers++;
}
this.getAnswer=function(answerNumberToGet)
{
return this.answers[answerNumberToGet];
}
this.getCorrectAnswerNumber=function()
{
return this.correctAnswer;
}
this.checkAnswerNumber=function(userAnswerNumber)
{
if (userAnswerNumber==this.getCorrectAnswerNumber())
gotoAndPlay(“Correct”);
else
gotoAndPlay(“Wrong”);
}
}
function onQuizData(success)
{
var quizNode=this.firstChild;
var quizTitleNode=quizNode.firstChild;
title=quizTitleNode.firstChild.nodeValue;
var i=0;
// <items> follows <title>
var itemsNode=quizNode.childNodes[1];
while (itemsNode.childNodes*)
{
var itemNode=itemsNode.childNodes*;
// <item> consists of <question> and one or more <answer>
// <question> always comes before <answer>s (node 0 of <item>)
var questionNode=itemNode.childNodes[0];
quizItems*=new QuizItem(questionNode.firstChild.nodeValue);
var a=1;
// <answer> follows <question>
var answerNode=itemNode.childNodes[a++];
while (answerNode)
{
var isCorrectAnswer=false;
if (answerNode.attributes.correct==“y”)
isCorrectAnswer=true;
quizItems*.addAnswer(answerNode.firstChild.nodeValue, isCorrectAnswer);
// goto the next <answer>
answerNode=itemNode.childNodes[a++];
}
i++;
}
gotoAndPlay(_currentFrame+1);
}
var quizItems=new Array();
var myData=new XML();
myData.ignoreWhite=true;
myData.onLoad=onQuizData;
myData.load(“quiz.xml”);
stop();
here is the code in frame 18 (actions layer)
var currentQuestionNumber=1;
var numOfQuestionsAnsweredCorrectly=0;
var numOfQuestionsAnsweredIncorrectly=0;
gotoAndStop(“ShowQuiz”);
and finally the code from frame 28 (actions layer)
if (currentQuestionNumber>quizItems.length)
gotoAndStop(“SummaryScreen”);
var currentQuizItem=quizItems[currentQuestionNumber-1];
var hasAnswered=false;
question=currentQuizItem.getQuestion();
for (var i=1; i<=4; i++)
{
_root[“answer”+i]=currentQuizItem.getAnswer(i-1);
}
stop();