0 Replies Latest reply on Jul 16, 2009 8:43 AM by released87

    TileList Question

    released87 Level 1

      Hi,

       

      I am building a shopping cart using the numeric stepper for the quantity. However, I am having some issues trying to get the stepper to work right.

       

       

       

       

       

       

       

       

       

       

       

       

       

       

       

       

      <mx:TileList

       

       

      id="list_cart" width="300" rowHeight="125" height="525" columnCount="1" columnWidth="275" rowCount="4" dataProvider="{cartData}" styleName="noBB"

      >

       

       

      <mx:itemRenderer>

       

       

      <mx:Component>

       

       

      <mx:Box verticalAlign="top"

      >

       

       

      <mx:Label truncateToFit="true" text="{data.name}" fontSize="12" fontWeight="bold" width="240"

      />

       

       

      <mx:Label text="SKU#: {data.number}" fontStyle="italic" width="240" textAlign="left"/>

       

       

      <mx:Label text="UNIT COST: ${data.cost}" fontWeight="bold" width="240" textAlign="left"/>

       

       

      <mx:HBox>

       

       

      <mx:Label text="Quantity"

      />

       

       

      <mx:NumericStepper width="60" id="input_quantity" maximum="1000" name="name_quantity" value="{data.quantity}" change="outerDocument.quantity(outerDocument.list_cart.selectedIndex, outerDocument.list_cart.selectedItem.id, input_quantity.parent.getChildByName('name_quantity'))" />

       

       

      <mx:Button label="Remove from cart" click="outerDocument.removeCart(outerDocument.list_cart.selectedIndex);" icon="@Embed(source='Icons/Small/Remove_Item.png')"

      />

       

       

      </mx:HBox>

       

       

      </mx:Box>

       

       

      </mx:Component>

       

       

      </mx:itemRenderer>

       

       

      </mx:TileList>

       

      public

       

       

      function addCart():void{

       

      var cartObject:Object= new Object();

       

      var cartList:XMLList= new XMLList(productsData);

      cartObject.name= cartList.name;

      cartObject.number= cartList.number;

      cartObject.cost= cartList.cost;

      cartObject.quantity= 1;

      cartID++;

      cartObject.id= cartID;

      cartData.addItem(cartObject);

      updateCart();

      Alert.show(cartID.toString());

      }

       

       

       

       

       

       

       

      public

       

      function quantity(cartID:int, selectedID:int, inputQuantity:Object):void {

      Alert.show(cartID+

      " "+selectedID+" "+inputQuantity);

       

      if(selectedID != -1){

       

      var cartObject:Object= new Object();

      cartObject.name= cartData.(id== selectedID).name;

      cartObject.number= cartData.(id== selectedID).number;

      cartObject.cost= cartData.(id== selectedID).cost;

       

      if(selectedID!= promoID){

      cartObject.quantity= inputQuantity.value;

      }

      cartData.setItemAt(cartObject, cartID);

      updateCart();

      }

      }

       

      When I change the stepper, it gives 'TypeError: Error #1009: Cannot access a property or method of a null object reference.', but only for the first item in the cart. Then the stepper will continue to increment all the way to it's limi. Yet it seems to work for items added after the first item. Do components within a tilelist have unique identifier like selectedItem.input_quantity or is it all the same?