1 Reply Latest reply on Jan 7, 2008 8:03 AM by VarioPegged

    Why are my values not "taking"?

    Handycam Level 1
      I've had this problem intermittently, and now it's back and I don't know why.

      I have 2 datagrids with drag and drop. The source is an XMLList, as in:

      <items>
      <item ln1="Feta" ln2="crumbled feta" sn="feta" minQy="0" maxQy=".5" qty=".5" units="cup" />
      <item ln1="Fontina" ln2="shredded Fontina" sn="fontina" minQy="0" maxQy=".5" qty=".5" units="cup" />
      ... etc ...
      </items>

      For the destination, I have created an ArrayCollection to receive the dropped items. One column is a numeric stepper:

      <mx:DataGridColumn dataField="@qty" headerText="Quantity" width="70" itemEditor="myComponents.NSEditor" itemRenderer="myComponents.NSEditor" editorDataField="newTotal"/>

      Which uses this component:
      <mx:Script>
      <![CDATA[
      public function get newTotal ():Number{
      return step.value;
      }
      ]]>
      </mx:Script>
      <mx:NumericStepper id="step" minimum="{XML(data).@minQy}" maximum="{XML(data).@maxQy}" stepSize=".25" value="{XML(data).@qty}" width="50"/>
      </mx:VBox>

      I check the totals in the list with:

      // adds up the quantities, returns sum
      public function getTotal(_arr:ArrayCollection) : Number {
      var _sum : Number = 0;
      var _length : Number = _arr.length;
      for(var i:Number=0; i<_length; i++) {
      var _item : Object = _arr.getItemAt( i );
      var _value : Number = _item["@qty"];
      _sum += _value;
      }
      return _sum;
      }

      The problem is, I drag a couple of items over, their default qty is 0.5 as indicated in the XML. But even if I change the steppers to 0.25, I'm still getting a total as if they're 0.5. Why is this?
        • 1. Re: Why are my values not &quot;taking&quot;?
          VarioPegged Level 2
          Make the getter newTotal bindable:

          [Bindable}
          public function get newTotal():Number{ ... }

          You may get either an error or warning telling you that you have to have a setter for newTotal as well. If you do, just add the setter, even though it won't do anything.

          Another approach would be to have a public variable in your NS component:

          [Bindable]
          public var changedQuantity:Number
          ...
          <mx:NumericStepper id="step" minimum="{XML(data).@minQy}" maximum="{XML(data).@maxQy}" stepSize=".25" value="{XML(data).@qty}" width="50" change="changedQuantity=step.value" />
          ...
          and then
          <mx:DataGridColumn dataField="@qty" headerText="Quantity" width="70" itemEditor="myComponents.NSEditor" itemRenderer="myComponents.NSEditor" editorDataField="changedQuantity"/>

          TS