4 Replies Latest reply on Nov 10, 2011 6:54 AM by Greg Kramida

    Bindable XML children - strange behavior

    Greg Kramida Level 1

      Hi people, I've run into a strange problem and I'm completely puzzled over it.

      I hope someone is able to help me with it.

       

      Here's my situation:

      I have an mxml module, which we can call "BaseModule", that contains a [Bindable] protected XML variable, let's call it "selectedBeer" for reference. It is instantiated with null on module creation, but populated with XML if some specific ui feature is clicked. In this XML, there are two child XML nodes relevant to my problem - let's call them Price and AlcoholContent.

       

      Now, I have another module, call it "BeerChoosingModule", that extends "BaseModule". It has, among other things, two spark NumericStepper components. Here's how their mxml looks:

       

       

      ...
      <s:HGroup verticalAlign="middle">
                <s:Label text="Selected blah's X:" />
                <s:NumericStepper snapInterval="0.01" stepSize="20" id="desiredPriceEditor" change="changeSelection(event)" minimum="0" maximum="99999" width="120"
                          valueParseFunction="this.PandACFormatter.parseNumber" valueFormatFunction="this.PandACFormatter.format" maxChars="10"
                          value="{this.selectedBeer== null ? 0 : this.PandACFormatter.parseNumber(this.selectedBeer.Price)}"/>
      </s:HGroup>
      <s:HGroup verticalAlign="middle">
                <s:Label text="Selected blah's Y:" />
                <s:NumericStepper snapInterval="0.01" stepSize="20" id="desiredAlcoholContentEditor" change="changeSelection(event)" minimum="0" maximum="99999" width="120"
                          valueParseFunction="this.PandACFormatter.parseNumber" valueFormatFunction="this.PandACFormatter.format" maxChars="10"
                          value="{this.selectedBeer== null ? 0 : this.PandACFormatter.parseNumber(this.selectedBeer.AlcoholContent)}"/>
      </s:HGroup>
      ...
      
      
      

       

      Wherever AlcoholContent and Price get used, they get used together and in exactly the same way (i.e. if they are converted into a string for something, they both are, using exactly the same syntax, etc.)

      Now, the inexplicable behaviour seems to occur at the binding. If I try to change the value of the desiredPriceEditor in the UI as the application is running, I am able to change it just fine, and then the changeSelection(event) function works, assigns a new value to selectedBeer.Price manually, and everything's hunkey-dory. However, if I try to change the value for of the desiredAlcoholContentEditor, as soon as the UI tries to apply the change, it gets reverted back to the original this.PandACFormatter.parseNumber(this.selectedBeer.AlcoholContent).

       

      Any ideas on what's going wrong here?

        • 1. Re: Bindable XML children - strange behavior
          Flex harUI Adobe Employee

          If the XML changes in a way that forces the binding to refresh then it will undo other changes.

          1 person found this helpful
          • 2. Re: Bindable XML children - strange behavior
            Greg Kramida Level 1

            Thanks for the reply.

            Yes, it would. However, in the situation I described, the if the XML would change, it would change for both the Price and AlcoholContent nodes at the same time. Nothing like this happens for the Price node. Now, in the changeSelection(event) function what I'm doing is something like:

             

            selectedBeer.Price = desiredPriceEditor.value.toString()

            selectedBeer.AlcoholContent = desiredAlcoholContentEditor.value.toString()

             

            Could it be that because I'm changing the Price node first, the binding is triggered for the entire selectedBeer object, so the desiredAlcoholContentEditor.value property gets reset to this.PandACFormatter.parseNumber(this.selectedBeer.AlcoholContent) value before the second line from the code above even gets to execute?


            • 3. Re: Bindable XML children - strange behavior
              Flex harUI Adobe Employee

              Yes, could be.  If you put a breakpoint on parseNumber, you should be able to see how often it gets called and why.

              • 4. Re: Bindable XML children - strange behavior
                Greg Kramida Level 1

                That's exactly what was happening. I really went around the problem right as soon as it happened by manually assiging the values on module load and on changes of the NumericSteppers, but I was really thrown off by this behaviour. I guess the XML object is an IPropertyEventDispatcher, and it automatically generated a PropertyChangeEvent when one of its properties was assigned.

                 

                In any case, your answer prompted me to study the IEventDispatcher class and the IPropertyEventDispatcher, which in turn helped me improve the design of my program by making one of the objects shared between the modules an IPropertyEventDispatcher.

                 

                Thanks