Can someone pls help.
Script suppose to write correct and incorrect answers and
then display in summary, but not working.
Below is main script and script for summary.
main script:
function QuizItem(question)
{
this.question=question;
this.answers=new Array();
//reset stats
this.numOfAnswers=0;
this.correctAnswer=0;
//returns question of this item
this.getQuestion=function()
{
return this.question;
}
// add answer to multiple choice items
this.addAnswer=function(answer, isCorrectAnswer)
{
this.answers[this.numOfAnswers]=answer;
if (isCorrectAnswer)
this.correctAnswer=this.numOfAnswers;
this.numOfAnswers++;
}
// this function returns the n-th answer
this.getAnswer=function(answerNumberToGet)
{
return this.answers[answerNumberToGet];
}
// returns index of corret answer
this.getCorrectAnswerNumber=function()
{
return this.correctAnswer;
}
// checks if the passed number is the correct answer index
this.checkAnswerNumber=function(userAnswerNumber)
{
if (userAnswerNumber==this.getCorrectAnswerNumber())
gotoAndPlay("Correct");
//Correct_Incorrect.text = "Correct";
else
gotoAndPlay("Incorrect");
//Correct_Incorrect.text = "Incorrect";
}
this.getNumOfAnswers=function()
{
return this.answers.length;
}
}
//this function parses the XML data into our data structure
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];
// go thru every item and convert it into our data structure
while (itemsNode.childNodes
)
{
var itemNode=itemsNode.childNodes;
// <item> consists of <question> and one or more
<answer>
// <question> always comes before <answer>s
// (Ie: <question> is the node 0 of <item>
var questionNode=itemNode.childNodes[0];
quizItems
=new QuizItem(questionNode.firstChild.nodeValue);
var a=1;
//Go thru every answer and add to data structure
// <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++;
}
//decoding complete, start now
gotoAndStop("Start");
}
var quizItems=new Array();
var myData=new XML();
myData.ignoreWhite=true;
myData.onLoad=onQuizData;
myData.load("quiz.xml");
stop(); //continue when xml is loaded
summary script:
userScore=(numOfQuestionsAnsweredCorrectly*100)/(numOfQuestionsAnsweredIncorrectly+numOfQuestionsAnsweredCorrectly);
stop();
thanks,
alex