Now we are going to take our new Actionscript 2.0 class and use it in a Flash application. Make sure that you have saved the final version of your actionscript and close down Flash. Open it back up and this time start a new Flash Application. Create a keyframe and enter the following code:
import com.ahfx.Product;
import com.ahfx.Shopping;
var myProduct = new Product();
myProduct.setQuantity(3);
myProduct.setPrice(2.99);
myProduct.setDesc("Teddy Bear");
var myOtherProduct = new Product();
myOtherProduct.setQuantity(1);
myOtherProduct.setPrice(12.99);
myOtherProduct.setDesc("Cool Sunglasses");
var shop_cart = new Shopping();
shop_cart.addElement(myProduct);
shop_cart.addElement(myOtherProduct);
trace(shop_cart.getTotal());
First we import our two classes Product and Shopping. This could also have been accomplished by import com.ahfx.*; It would just import all of the classes in that package. We create the same two Products that we created in the Basic Tutorial. We create a Shopping cart to hold the products and add the products to the cart using addElement(). Finally we trace to find the total of all the Products in the Cart. The output is as follows:
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!