开发者

Flash AS2 Quiz with individual points for each answer

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 n开发者_Go百科ormal, 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!


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.


You need to have an array storing all the user answers. At the beginning of each frame, retreive the user answers and put the user selection back by gotoAndStop (2) of your heart button.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜