Now let's say that we want to modify the quantity of an item in our Shopping cart. We will use the getElement method for this.
var myProduct = new Product();
var myOtherProduct = new Product();
var shop_cart = new Shopping();
var tempProduct:Product = shop_cart.getElement(1);
Our customer has decided to buy another pair of sunglasses (because they are so cool). We use the getElement() method to return the sunglasses. Notice that this is a zero based Shopping Cart. The first item is 0, the second is 1, etc. After we get the Product out of the cart, we can modify its quanity to 2. This outputs the following:
We can see that the total cost of all the items in the Shopping cart has increased to 34.95.
This ends the intermediate Actionscript 2.0 lesson. Although this has been a simple walkthrough, this is a solid base that we wish to build upon. The Shopping cart still needs a remove method for taking things out of the cart and other enhancing methods. If you continue to the advanced page, you will learn how to take the shopping cart you have created and display it in a DataGrid object.
SUPPORT THIS SITE If this tutorial helped you, show your support and send me something from my wish list. Click on an item below and then choose Adam Hayes (Gift Registry Address) for the Ship to Address. It is that easy!