views:

401

answers:

1

Hi guys!

I'm making a quiz in Actionscript 2.0. The quiz has 8 questions. Each question has four answers and each answer gives different points. On every frame their is two questions to answer and then move on to the next two and so on.

My problem is that I need to assign each answer with points that in the end will be calculated and depending on the number of points send the user to different messages (frames).

My code so far is as follows:

// create an array of all nav buttons in group
var groupinfo:Array = [q1a1, q1a2, q1a3, q1a4];

// create a variable to track the currently selected button
var activebtn:MovieClip;

// doRollOver: start the rollover action or process, 
// unless the button is currently selected
function doRollOver() {
   if (this != activebtn) {
      this.gotoAndPlay(2);
   }
}

// doRollOut: start the rollout action or process, 
// unless the button is currently selected
function doRollOut() {
   if (this != activebtn) {
      this.gotoAndPlay(1);
   } 
} 

// doClick: 1) return previously selected button to normal, 2) show visual 
// indication of selected button, 3) update activebtn
function doClick() {
   activebtn.gotoAndPlay(1);       // return previously selected to normal

   delete this.onEnterFrame;               // stop activity on selected mc

   activebtn = this;                      // update pointer to current selection
}

// assign functions to each event for each button in the group
function init() {
   for (var mc in groupinfo) {  
      groupinfo[mc].onRollOver = doRollOver;
      groupinfo[mc].onRollOut = doRollOut;
      groupinfo[mc].onRelease = doClick;
   }
}

init();

This code takes care of the active state for the answers on each page. The next problem is when moving across frames these states aren't remembered but resetted.

///////////////////////////// Files: /////////////////////////////

http://www.danielwestrom.se/quiz/quiz.html - Live demo

Change .html to .zip for project files

Thanks!

+1  A: 

It's not best-practices, but use a global to store those results. A global array for instance.

You could also use a class to store all of your scores, but as you have the code in the fla, I would just use a global.

Lieven Cardoen
And that is what I did. Thanks!
Daniel Weström