Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Quiz - How can i store the displayTotal var into a shared object??

Status
Not open for further replies.

dru312

Programmer
Nov 20, 2002
11
0
0
US
here is my code
_____________________

// stop the movie
stop();

//create the local Shared Object

// ### init main timeline variables
var displayTotal; // textfield for displaying user's final score
var totalCorrect = 0; // number of questions user answered correctly
var userAnswers = new Array(); // array containing the user's guesses
var currentQuestion = 0; // number of the question we're on

// ### the Question constructor
function Question (correctAnswer, questionText, answers) {
this.correctAnswer = correctAnswer;
this.questionText = questionText;
this.answers = answers;
}

// ### import the source file containing our array of question objects
#include "questionsArray.as"

// ### begin the quiz
makeQuestion(currentQuestion);

// ### function to render each question to the screen
function makeQuestion (currentQuestion) {
// clear the stage of the last question
questionClip.removeMovieClip();

// create and place the main question clip
attachMovie("questionTemplate", "questionClip", 0);
questionClip._x = 277;
questionClip._y = 205;
questionClip.qNum = currentQuestion + 1;
questionClip.qText = questionsArray[currentQuestion].questionText;

// create the individual answer clips in the question clip
for (var i = 0; i < questionsArray[currentQuestion].answers.length; i++) {
questionClip.attachMovie(&quot;answerTemplate&quot;,&quot;answer&quot; + i, i);
questionClip[&quot;answer&quot; + i]._y += 70 + (i * 15);
questionClip[&quot;answer&quot; + i]._x -= 100;
questionClip[&quot;answer&quot; + i].answerText = questionsArray[currentQuestion].answers;
}
}


// ### function to register the user's answers
function answer (choice) {
userAnswers.push(choice);

if (currentQuestion + 1 == questionsArray.length) {
questionClip.removeMovieClip();
gotoAndStop (&quot;quizEnd&quot;);
} else {
currentQuestion++;
makeQuestion(currentQuestion);
}
}


// function to tally the user's score
function gradeUser() {
// count how many questions the user answered correctly
for (var i = 0; i < questionsArray.length; i++) {
if(userAnswers == questionsArray.correctAnswer) {
totalCorrect++;
}
}

// show the user's score in an onscreen text field
displayTotal = totalCorrect + &quot;/&quot; + questionsArray.length;
}
 
I'm not sure what you're asking..do you want to know how to make a variable accessible between functions? If you're using Flash MX, try using the _global layer (_global.displayTotal).

Hope this helps...

Ben
 
I need to store the total score of this quiz so I can recall in in another swf with a shared object.
 
if you want the total in another swf surely localconnection rather than shared object....unless you want to allow the user to log off half way through and then log back on to finish.
 
I need them to be able to store the score locally so I can use the shared object to print their score as its changed, etc.
 
What would be the code to store the score (totalDisplay) into a sol?????
 
somrthing like

so2 = SharedObject.getLocal(&quot;user&quot;);

so2.data[&quot;correct&quot;] = totalcorrect;
 
This isnt working. I need to know where I would put this in my code. Also - since the variable is called displayTotal - would i also name the instance???

 
bill e-me at webmaster@styczendesign.com

I may have something for you to fix if you have a few min.

I will pay
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top