开发者

Won't display data in run, or won't display data in debug.

This is the edit to my question. There is quite a bit of code here, but the problem area is below the second set of three line comments. I stuck the rest in just in case I'm completely wrong about where the problem is. With the "if" statement I can display fine in a run, but not in debug. If I get rid of the conditional it runs fine in debug, but not in a regular run. These errors only occur on the first run of the quiz. In either mode it runs fine fi I take a second quiz. Any help or suggestions are appreciated. Thanks...

    // ** 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开发者_如何学C: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>


You shouldn't run showTheQuestion() right after a state change. Your components in the state haven't had time to initialize just yet. I would argue that you don't need that function since the state is the one that show "show the question".

If you really need it, you should add it to a creation complete event on one of the state components, or maybe the enterState event on the state itself.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜