1

I'm having problems with an actionscript project. I have to ask the user a question 5 times, the user has to answer and when the user clicks a button, the answer has to be validated.

Is there a way to make a for-loop wait for a click event?

What i was thinking of was something like this :

for(teller = 0; teller < 5; teller++){
   //show new question
   //user answers , and when finished the user clicks the button
   buttonNext.addEventListener(MouseEvent.CLICK,checkAnswer);                               
   //it has to wait until the user clicks the button , and then begin all over again
}
5
  • You ask the same 5 times? Commented Dec 29, 2012 at 20:29
  • no, its a quiz, and the question has to show up when the user clicks the button, there are 5 questions Commented Dec 29, 2012 at 20:34
  • I'm confused you write "when the user clicks a button, the answer has to be validated" and now "question has to show up when the user clicks the button". Event driven mean you will write code for events, you listener "checkAnswer" is the place for do de validation. Why you want make a loop? Commented Dec 29, 2012 at 20:41
  • i've renewed the code fragment , hopefully that shows you what i mean Commented Dec 29, 2012 at 20:42
  • 1
    OK, I think I understand now, you don't need a loop, you need a global variable let say quizStatus to maintain the status the quiz, at the beginning you load it with 0 and each time you process the event in your handler "checkAnswer" you will check the status and act accordingly, when the user pass for the second question you increment the quizStatus variable. Do you understand what I'm trying do tell you? my english is very poor. Commented Dec 29, 2012 at 20:55

1 Answer 1

2

Yes, but do it in a different way (not using for loops):

var questionsAnswered = 0; //in class files put this higher up

nextQuestionButton.addEventListener(MouseEvent.CLICK, nextQuestion);
function nextQuestion(e:MouseEvent){
    trace(questionsAnswered);
    questionsAnswered++;
    // Logic here
}
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.