0 Replies Latest reply on Nov 27, 2006 2:32 PM by Vuldranigh

    Dynamically populating an Array with XML

    Vuldranigh

      Greetings...I'm an actionscript/OOP newbie(more of a designer) and I'm designing my brother's website, and I think I bit off more than I could chew. I have constructed his site using Slides and I am trying to construct a cart(dataGrid) that is dynamically populated through XML via a list component. When I choose an Item from the list it populates text fields, which I would like to be able to add to the cart. When I use the following code:

      var nPrice:Number = txtPrice.text; //dynamically populated through XML
      var sSku:String = txtSku.text; //dynamically populated through XML
      var sItem:String = lstNames.getItemAt(lstNames.selectedIndex).name; //dynamically populated through XML
      var nQuantity:Number = txtQuantity.text; //dynamically populated through XML

      //define items
      var aItem:Array = new Array();
      aItem.push({sku:sSku, item:sItem, price:nPrice, quantity:nQuantity});
      var totalPrice:Number;
      btnAdd.onRelease = function() {
      aItem[0].quantity++;
      //update datagrid
      updateDatagrid();
      };
      //--------------------------------------- functions ----------------------------------------------//
      function updateDatagrid():Void {
      totalPrice = 0;
      var aBasket:Array = new Array();
      if (aItem[0].quantity>0) {
      aBasket.push({sku:aItem[0].sku, item:aItem[0].item, quantity:aItem[0].quantity, price:aItem[0].price, total:aItem[0].price*aItem[0].quantity});
      totalPrice += aItem[0].quantity*aItem[0].price;
      }
      _parent._parent.shopping_cart.dgShoppingCart.dataProvider = aBasket;
      _parent._parent.shopping_cart.dgShoppingCart.vScrollPolicy = "auto";
      txtTotal.text = totalPrice;
      }

      I am only able to add 1 item, and when I choose another item from the list to add, it replaces the initial item and messes up the totals. Is there a way to dynamically construct an Array every time I hit the Add button during runtime? Also, is there a fix for the user to enter a number into the Quantity text field that will not mess up the whole total? Anyone's help would greatly be appreciated for I have lost both hair and sleep over this issue for weeks. Thank you for any input!

      --Rams