Learn Actionscript - AHFX

Intermediate Actionscript - Flash Shopping Cart 

ahfx actionscript learning actionscript

AHFX Actionscript Home
Basic Actionscript
Intermediate Actionscript
Advanced Actionscript
About AHFX
Contact AHFX
Great Actionscript Links
 
 
 
 

Actionscript 2.0 Flash Implementation

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:

21.96

Continue to page 4


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!
 

 

Featured Tutorials

Flash Shopping Cart Tutorial
Create a custom Flash Shopping Cart that will add, update, and show products.

Flash MX 2004 Custom Actions
Take your custom classes to the next level and have Flash treat them as built in classes.

Pass Variables to Flash
Quick and dirty way of passing variables to your flash animations.

Affordable Web Design and Hosting
Find out how you can cut your overhead by hosting with AHFX.net

Affordable Custom Art
Get your pictures custom framed. Amazing Prices. Outstanding Quality.


 
AH Digital FX Studios
Disclaimer | Site Map | Idaho Web Design