Actionscript 3 - Quiz game help
Using Adobe Flash Professional CS5 on WIndows 10 Making a quiz for a school assignment, the quiz uses an array to store the questions and answers here is what I have right now.
import flash.events.MouseEvent;
back.buttonMode = true;
back.addEventListener(MouseEvent.MOUSE_DOWN, changeFrameThree);
function changeFrameThree (Event:MouseEvent):void{
gotoAndStop(1);
}
stop();
var nRNumber:Number = 0;
var aQuestions:Array = new Array(7);
var aCorrectAnswers:Array = new Array("3.5cm", "1.7m", "2.9km", "6.4L", "0.1L", "20g", "7.7kg", "50t")
var aUserAnswers:Array = new Array();
aQuestions[0] = "Convert 35mm to cm"
aQuestions[1] = "Convert 170cm to m"
aQuestions[2] = "Convert 2900m to km"
aQuestions[3] = "Convert 6400ml to L"
aQuestions[4] = "Convert 100ml to L"
aQuestions[5] = "Convert 20,000mg to g"
aQuestions[6] = "Convert 7700g to kg"
aQuestions[7] = "Convert 50,000kg to tonnes"
Question_txt.text = aQuestions[nRNumber];
submit_btn.addEventListener(MouseEvent.CLICK, quizlet);
function quizlet(e:MouseEvent):void
{
aUserAnswers.push(Answer_txt.text);
Answer_txt.text = "";
nRNumber++;
nRNumber = Math.ceil(Math.random()*7);
if(nRNumber < aQuestions.length)
{
Question_txt.text = aQuestions[nRNumber];
}
else
{
nextFrame();
}
}
The nRNumber = Math.ceil(Math.random()*7); makes it so that the questions appear randomly, however they keep repeating and never go to the next frame. I'm not good at coding and was wondering if someone could show me how to make it so that the questions appear randomly but don't repeat and move to the next frame when it has shown all the questions. I am willing to change any of the code but it has to be all kept in an array (part of the assignment). If u need any more info ask away
UPDATE:
I updated the code so it is now this, I made it so that after 7 questions it will switch to the next frame but it still repeats questions
import flash.events.MouseEvent;
back.buttonMode = true;
back.addEventListener(MouseEvent.MOUSE_DOWN, changeFrameThree);
function changeFrameThree (Event:MouseEvent):void{
gotoAndStop(1);
}
stop();
var nQNumber:Number = 0;
var nRNumber:Number = 0;
var aQuestions:Array = new Array(7);
var aCorrectAnswers:Array = new Array("3.5cm", "1.7m", "2.9km", "6.4L", "0.1L", "20g", "7.7kg", "50t")
var aUserAnswers:Array = new Array();
aQuestions[0] = "Convert 35mm to cm"
aQuestions[1] = "Convert 170cm to m"
aQuestions[2] = "Convert 2900m to km"
aQuestions[3] = "Convert 6400ml to L"
aQuestions[4] = "Convert 100ml to L"
aQuestions[5] = "Convert 20,000mg to g"
aQuestions[6] = "Convert 7700g to kg"
aQuestions[7] = "Convert 50,000kg to tonnes"
Question_txt.text = aQuestions[nRNumber];
submit_btn.addEventListener(MouseEvent.CLICK, quizlet);
function quizlet(e:MouseEvent):void
{
aUserAnswers.push(Answer_txt.text);
Answer_txt.text = "";
nQNumber++;
nRNumber = Math.ceil(Math.random()*7);
if(nQNumber < aQuestions.length)
{
Question_txt.text = aQuestions[nRNumber];
}
else
{
nextFrame();
}
}
