Copy link to clipboard
Copied
Hi im pretty new to action script and have been playing around with bits of code for a little project i am doing at university
i basically have a AS3 maths game with three different levels on it with questions on it.
The first level i used radio buttons these used to answer the 3 questions, once these are clicked it is linked to a score if its correct you get 10 points.
Heres my problem.... level 2 i have 3 combo boxes to enter the answers to the questions on the stage but i want to make it so when all the questions have been answered you click a button to check if you are right and get a score out of 30.
level 3 i have the input text field where you type the answers in and want to do the same where you enter the answers click a button to see if you are right and get a score.
but all the code i am typing in is not working PLEASE HELP as its driving me crazy haha.
Copy link to clipboard
Copied
"but all the code i am typing in is not working"
google: quiz as3 tutorial and work through one of the results
If you have specifically a problem of tracking the amount of questions that have already been answered,
you must create some variable that functions as a counter thta increments a certain value.
//at the beginning of your quiz
var counter:int = 0;
var rightAnswers:int = 0;
const QUESTIONS:int = 30;
//whenever a user clicks on one of your radio buttons
counter ++;
if(checkAnswer ()){
rightAnswers++;
}
if(counter == QUESTIONS){
showScore();
}
function showScore():void{
trace("you have answered " + rightAnswers+" of " + QUESTIONS);
}
function checkAnswer():Boolean{
//depending on how you store values in your application you have to programm a routine
// that either returns true or false
}
Copy link to clipboard
Copied
I have the radio buttons questions working so heres the code i tried for the comboboxes and the text fie
//text box
import flash.text
import flash.events.MouseEvent;
// starting out with a score of 0
var myscore = 0; score.text = myscore+"";
// creating a new instance of the textGroup Class
var mygroup1:text = new text("text1");
answer1_txt.group = answer3_txt.group = answer3_txt.group =mygroup1;
answers.addEventListener(MouseEvent.CLICK, quizHandler1)
function quizHandler1(event:MouseEvent):void{
if(mygroup1.selection.label=="45"){myscore+=10; nextFrame();
}
}
//combobox
import fl.controls.ComboBox;
import flash.events.MouseEvent;
// starting out with a score of 0
var myscore = 0; score.text = myscore+"";
// creating a new instance of the ComboBoxGroup Class
var mygroup1:ComboBox = new ComboBox("Combo1");
answers.addEventListener(MouseEvent.CLICK, quizHandler1)
function quizHandler1(event:MouseEvent):void{
if(mygroup1.selection.label=="45"){myscore+=10; nextFrame();
}
}
Copy link to clipboard
Copied
Is there a question?
Copy link to clipboard
Copied
yeah there is, three questions on one frame to answer so I'm trying to get a score for the three of them, I hate when code dosent work with this cause Ido rather show someone on person what's up Haha
Copy link to clipboard
Copied
This is the first screen as you can see i want the player too type the answers in the text box and then click the button to check the answers and get a score for them.
this level i want the user to select from the combo list then do the same process as the last screen click the button getting answers and a score.
hope someone can help !!
Copy link to clipboard
Copied
basically you want to store your solution inside an object, and compare the indexes of the comboboxes with it
//say the Comboxes right solutions have the indexes 0,1,2
var combosolutions:Array = [0,1,2];
//when clicking the check Answers button you go through all the seelctedIndexes of your comboboxes and compare them to the combosolutions
Copy link to clipboard
Copied
Cheers sorted
Find more inspiration, events, and resources on the new Adobe Community
Explore Now