4 Replies Latest reply on Apr 20, 2009 10:58 AM by Handycam

    Why is my value not getting through?

    Handycam Level 1

      I have a loop in my main app that creates a series of components:

       

      private function createSteps():void{

      var numSteps:uint = dataXML.length;

      var recipeStep:CyorStep;

              for (var i:uint=0;i<numSteps;i++){

              this["step"+i].label= (i+1) +". "+ dataXML[i]..stepTitle;

      this["step"+i]..itemChoicesList = dataXML[i]..item;

      this["step"+i].stepTitle.text = dataXML[i].stepTitle;

      this["step"+i].stepPanel.title = dataXML[i]..prompt;

      this["step"+i].stepCaption.text = dataXML[i]..bodyText;

      this["step"+i].minChoices = dataXML[i]..min;

      this["step"+i].maxChoices = dataXML[i]..max;

      this["step"+i].stepNumber = i;

      if (i == (numSteps-1)){

      this["step"+i].nextBtn.label = "FINISH";

      this["step"+i].nextBtn.addEventListener(MouseEvent.MOUSE_UP,showRecipe);

      } else if (i==0) {

      this["step"+i].prevBtn.visible = false;

      }

      this["step"+i].addEventListener("GO_PREVIOUS",prevStep);

      this["step"+i].addEventListener("GO_NEXT",nextStep);

      this["step"+i].addEventListener("ITEM_CHOSEN",updateItems); 

      this["step"+i].addEventListener("STEP_COMPLETE",processStatus); 

              }

       

            }

       

      It works fine, except for the minChoices and maxChoices variables.  In the component, I have created to uint variables to hold these values:

       

      public var minChoices:uint;

      public var maxChoices:uint;

       

      However, no matter what values are in dataXML, these variables are always 0.

       

      It makes no sense to me.  I have traced the values in this function, and dataXML[i]..min/dataXML[i]..max are both reading correctly.

       

      I have also tried "dataXML[i]..min as uint" and uint(dataXML[i]..min), makes no difference.  What am I missing here?

        • 1. Re: Why is my value not getting through?
          m_hartnett Level 3

          Try doing this

           

          new Number(dataXML[i]..min) to see if that works.

          • 2. Re: Why is my value not getting through?
            Handycam Level 1

            No, doesn't so it.  And it's not my loop, either, since if I do it explicitly it still fails, see:

             

                  private function createStepsNew():void {

                  step0.label = "1."+ dataXML.getItemAt(0)..stepTitle;

                  step0.stepTitle.text = dataXML.getItemAt(0)..stepTitle;

                  step0.itemChoicesList = dataXML.getItemAt(0)..item;

                  step0.minChoices = dataXML.getItemAt(0)..minChoices as Number;

                  var maximum:Number = new Number(dataXML.getItemAt(0)..maxChoices);

                  trace("xml says max is "+dataXML.getItemAt(0)..maxChoices);

                  step0.maxChoices = maximum;

                  }

             

            The trace statement above correctly prints out the "maxChoices" from the xml (I renamed it), but the trace statement in the component still says 0.

             

            All the other variables and text properties above work fine.

            • 3. Re: Why is my value not getting through?
              Handycam Level 1

              I think the problem might be in that my init() function is set to creationComplete, and when the components are created these values are not yet populated.

               

              When I test it with a different event, like a button event, it works. Is there something later that creation complete I should be using?

              • 4. Re: Why is my value not getting through?
                m_hartnett Level 3

                You can try using the callLater method and calling a method that would process your XML.  Use the callLater method in your creationComplete event.

                 

                You can also try using the updateComplete event.  This can be a little dangerous/tricky because this event is called anytime the ui needs refreshing.  I have used this event and used a flag property to see if I need to process any aditional code.  Meaning that the first time I processed the XML data, I would set the flag to true(meaning the xml data is processed) so the next time updateComplete is called I can check the flag and see if it is set to true which means that I could skip the processing.