0 Replies Latest reply on Oct 8, 2007 8:20 AM by Handycam

    ItemEditor validation question

    Handycam Level 1
      I have an app with a datagrid populate by items dragged into it. I have an object method that adds up the quantities of the dropped objects and displays an error in they exceed the amount defined in the object's properties. Works fine.

      However, now I need to include data checking on a PER ITEM level; that is, the XML entries for each grid item has its own min and max qty, not just the list as a total. Can anyone recommend a strategy for updating my old code to accomodate this?

      A typical entry is <item ln1="Bacon" minQy="1/2" maxQy="1" qty="1" units="lb." sn="bacon" />

      I create each list item with: private var _list2 : List = new List(0,1,.25,.25,"lbs","Meats") and then check the list with
      _errQty = _list2.checkTotal(app._chosen2);

      The list object:


      public class List extends Object {
      import mx.collections.*;
      include "DialogStrings.as";

      function List(_minC:Number,_maxC:Number,_minQ:Number,_maxQ:Number,_un:String,_ingName:String){
      _minChoices = _minC;
      _maxChoices = _maxC;
      _minQty = _minQ;
      _maxQty = _maxQ;
      _units = _un;
      _shortName = _ingName;


      private var _minChoices : Number;
      private var _maxChoices : Number;
      private var _maxQty : Number;
      private var _minQty : Number;
      private var _units : String;
      public var _shortName : String;

      // checks the total quantities, returns error string
      public function checkTotal(_arr:ArrayCollection) : String {
      var _errType:String = "";
      var _n:Number = getTotal(_arr)
      if (_n > _maxQty) {
      _errType = "over";
      else if (_n < _minQty){
      _errType = "under";
      } else {
      _errType = "";
      switch (_errType){
      case "over":
      return getMaxQtyError();
      case "under":
      return getMinQtyError();
      case "":
      return "";
      trace("Quantity OK");
      return "";
      trace("no matching error condition");
      // adds up the quantities, returns sum
      private 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;