这是我的问题的编辑。这里有相当多的代码,但问题区域低于第二组三行注释。为了防止问题出在哪里我完全错了,我把剩下的都放进去了。使用“if”语句,我可以在运行中正常显示,但不能在调试中显示。如果我摆脱条件它在调试中运行良好,但不是在常规运行。这些错误仅在测验的第一次运行时发生。在任何一种模式下运行都很好我接受第二次测验。任何帮助或建议表示赞赏。感谢...
// ** this function is called from another component that passes in the array of qnums
// ** and then function clears data from previous quizzes. Component starts in the
// ** "loadingState **//
public function startQuiz(qNums:Array):void
{
quizNumbers = qNums;
// ** deleted the reset functions for readability ** //
showQuestion();
}
// ** calls the questions from sql ** //
protected function showQuestion():void{
getQuestionByNumberResult.token = quizService.getQuestionByNumber(quizNumbers[i]);
}
// ** result handler from the sql call and randomizes answers and feedbacks ** //
protected function getQuestionByNumberResult_resultHandler(event:ResultEvent):void
{
// ** deleted the logic that builds the arrays and randomizes them ** //
ranAnswerArray = Randomizer.qsAndFbcks(answersArray, tempArray);
ranFeebbackArray = Randomizer.qsAndFbcks(feedbackArray, tempArray);
// ** This seems to be where the problem is. With the "if" statement it runs fine in a ** //
// ** regular run, but doesn't display the first question in debug mode. Without the "if" and I just ** // // ** call the showTheQuestion() function it is the problem is reversed ; it runs fine in debug, ** //
// ** but doesn't show the first question in a regular run. ** //
if (currentState != "quizingState"){
currentState="quizingState";
addEventListener(StateChangeEvent.CURRENT_STATE_CHANGE, quizStateChange);}
else{ showTheQuestion();}
//showTheQuestion();
}
// ** function called from state change listener ** //
protected function quizStateChange(event:StateChangeEvent):void
{
showTheQuestion();
}
// ** this function tells the visual components what to display ** //
protected function showTheQuestion():void{
// ** deleted logic that says how many radios and labels should be visible ** //
questionText.text = data.question_txt;
zanswer01.text = ranAnswerArray[0];
zanswer02.text = ranAnswerArray[1];
zanswer03.text = ranAnswerArray[2];
zanswer04.text = ranAnswerArray[3];
}
]]>
</fx:Script>
<s:states>
<s:State name="quizingState"/>
<s:State name="loadingState"/>
<s:State name="finishedState"/>
</s:states>
// ** deleted the declarations block for readability. I left the display components just in case ** //
// ** something seemed wrong with them. ** //
<s:Label id="questionText" includeIn="quizingState" x="42" y="54" width="699" height="138" color="#5BAAFB"
fontFamily="Arial" fontSize="22" fontWeight="normal"
text=""/>
<s:Form includeIn="quizingState" x="48" y="167" height="219">
<s:HGroup id="zhGroup01" verticalAlign="baseline">
<s:RadioButton groupName="selectedAnswer" value="0"/>
<s:Label id="zanswer01" text="" verticalAlign="middle"/>
</s:HGroup>
<s:HGroup id="zhGroup02" verticalAlign="baseline">
<s:RadioButton groupName="selectedAnswer" value="1"/>
<s:Label id="zanswer02" text=""/>
</s:HGroup>
<s:HGroup id="zhGroup03" verticalAlign="baseline">
<s:RadioButton id="zradio3" groupName="selectedAnswer" value="2"/>
<s:Label id="zanswer03" text=""/>
</s:HGroup>
<s:HGroup id="zhGroup04" verticalAlign="baseline">
<s:RadioButton id="zradio4" groupName="selectedAnswer" value="3"/>
<s:Label id="zanswer04" text=""/>
</s:HGroup>
</s:Form>
答案 0 :(得分:1)
状态更改后,您不应该立即运行showTheQuestion()
。您所在州的组件还没有时间进行初始化。我认为你不需要那个功能,因为州是显示“显示问题”的那个。
如果你真的需要它,你应该把它添加到其中一个状态组件的创建完成事件,或者可能是状态本身的enterState
事件。