2012-12-29 58 views
1

我遇到了動作項目的問題。 我必須問用戶一個問題5次,用戶必須回答,當用戶單擊按鈕時,答案必須經過驗證。事件驅動的動作腳本

有沒有辦法讓一個for循環等待點擊事件?

我在想什麼的是這樣的:

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 
} 
+0

你問同樣的5倍? – HMarioD

+0

不,它的一個測驗,並且當用戶點擊按鈕時出現問題,有5個問題 –

+0

我很困惑你寫的是「當用戶點擊一個按鈕時,答案必須被驗證」,現在「當用戶點擊按鈕時,問題必須顯示「。事件驅動意味着您將爲事件編寫代碼,您的監聽器「checkAnswer」是進行驗證的地方。爲什麼你想要一個循環? – HMarioD

回答

2

是的,但(沒有使用循環)做它用不同的方式:

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

nextQuestionButton.addEventListener(MouseEvent.CLICK, nextQuestion); 
function nextQuestion(e:MouseEvent){ 
    trace(questionsAnswered); 
    questionsAnswered++; 
    // Logic here 
}