【问题标题】:Event-Driven Actionscript事件驱动的动作脚本
【发布时间】:2012-12-14 16:04:09
【问题描述】:

我在执行 actionscript 项目时遇到问题。 我必须问用户一个问题 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
}

【问题讨论】:

  • 你问同样的问题 5 次?
  • 不,它是一个测验,当用户点击按钮时,问题必须显示出来,有 5 个问题
  • 我很困惑你写“当用户单击按钮时,必须验证答案”,现在“当用户单击按钮时必须显示问题”。事件驱动意味着您将为事件编写代码,您的侦听器“checkAnswer”是进行验证的地方。为什么要循环?
  • 我已经更新了代码片段,希望能告诉你我的意思
  • 好的,我想我现在明白了,你不需要循环,你需要一个全局变量让我们说 quizStatus 来维持测验的状态,一开始你用 0 加载它,每次您在处理程序“checkAnswer”中处理事件,您将检查状态并采取相应措施,当用户通过第二个问题时,您增加 quizStatus 变量。你明白我想告诉你的吗?我的英语很差。

标签: actionscript-3 flash events flash-builder


【解决方案1】:

是的,但以不同的方式进行(不使用 for 循环):

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

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

【讨论】:

    猜你喜欢
    • 2012-01-16
    • 1970-01-01
    • 2011-01-31
    • 2020-02-02
    • 2011-02-18
    • 2011-12-01
    • 1970-01-01
    • 1970-01-01
    • 2016-04-23
    相关资源
    最近更新 更多