0

我正在 Actionscript 2.0 中进行测验。测验有 8 个问题。每个问题有四个答案,每个答案给出不同的分数。在每一帧上,他们都有两个问题要回答,然后继续下两个问题,依此类推。

我的问题是我需要为每个答案分配最终将被计算的点,并根据点数将用户发送到不同的消息(帧)。

到目前为止,我的代码如下:

// 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();

此代码负责每一页上答案的活动状态。下一个问题是当跨帧移动时,这些状态不会被记住而是被重置。

///////////////////////// 文件://////////////// //////////

http://www.danielwestrom.se/quiz/quiz.html - 现场演示

将项目文件的 .html 更改为 .zip

谢谢!

4

2 回答 2

1

这不是最佳实践,而是使用全局来存储这些结果。例如一个全局数组。

你也可以使用一个类来存储你所有的分数,但是由于你在 fla 中有代码,我只会使用一个全局的。

于 2009-11-17T19:55:54.440 回答
1

您需要有一个存储所有用户答案的​​数组。在每一帧的开始,检索用户的答案并通过你的心脏按钮的 gotoAndStop (2) 将用户选择放回去。

于 2011-10-15T16:10:34.607 回答