Hello and thank you for your time. I have an as3 code which randomly picks 5 frames out of 7, no repeats.
var mygroup1:RadioButtonGroup = new RadioButtonGroup("group1");
q1a1.group = q1a2.group = q1a3.group = q1a4.group = q1a5.group = mygroup1;
var number_array:Array = [8158,8159,8160,8161,8162,8163,8164];
var final_array:Array = [];
var count_selected:int = 5;
var i:int;
for(i = 0; i < count_selected; i++)
{
if(number_array.length == 0)
break;
else
final_array.push(number_array.splice(Math.floor(Math.random() * number_array.length), 1)[0]);
}
var index = 0;
var currentQuestion:int = final_array[index];
var answers:Object = {
8158: 'B) 12',
8159: 'F) All of the above',
8160: 'A) True',
8161: 'B) False',
8162: 'C) 4',
8163: 'F) D and E',
8164: 'B) B'
};
var getAnswer = mygroup1.selection.label; //Getting the selection from RadioButtonGroup
submitBtn.addEventListener(MouseEvent.CLICK, onSubmitClicked);
function onSubmitClicked(e:MouseEvent):void {
var answer:String = getAnswer();
if (answer === answers[currentQuestion])
awardScore(currentQuestion);
++index;
currentQuestion = final_array[index];
gotoAndStop(final_array[index]);
}
and when you click on the "startBtn", it takes you to the first randomly generated frame(final_array[0]) and it's all great to start the process randomly.
Each of the next 7 frames has a submit button(b1,b2...b7) which keeps track of the score and submits the answer and also should go to the next randomly picked frame but only 5 times, following the remaining generated frames....gotoAndStop(final_array[1])...(final_array[2])....(final_array[3])....(final_array[4]).
b1.addEventListener(MouseEvent.CLICK, quizHandler1)
function quizHandler1(event:MouseEvent):void{
if(mygroup1.selection.label=="B) 12") {
count = count + 20;
scoreresult.text = (count).toString();
gotoAndStop(final_array[1]);
}
else{
gotoAndStop(final_array[1]);
}
}
My problem is...Since the user will only go to 5 randomly picked frames out of 7, how can I make sure all the buttons in all 7 frames will listen and follow the gotoAndStop(final_array[]); statement in the order of 5? Because at the end, 2 frames will be left out, and those two frames will change randomly in every roll. I hope I could explain my dilemma. Thank you again.
To do a quiz like yours, I think that you don't need to duplicate all content on every frame. You can put your questions in MovieClips ( or one MovieClip with many frames ) and then you can add it to your stage, and for your check box you can create it once and every time you can change just their values and labels. For buttons, you need only one button which will validate and check the current question and the go to the next one.
Take a look on this example :
This code gives you something like this :
You can also see it working here.
Of course this is just a simple example, you can improve and adapt it to your needs.
Hope that can help.
Sounds like you just need a single submit button that goes to the next frame. That way you don't have to worry about the order.
Some sample code to give you an idea how it might work
The idea is to have all that logic in a single click handler, once clicked it will grab the users answer and check if it is correct, if it is then it goes on to the next question.