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 Shopping Cart

I want to explore the getTotal() method in detail.

   function getTotal():Number{
      var total = 0;
      var i;
      for(i=0;i<elementCount;i++){
         var tempProduct:Product = cart[i];
         total += tempProduct.getTotal();
      }
      return total;
   }

This method will return the total of all of the products in the cart. We first create a local variable named total. We also create a local variable named i for use in our for loop.

The for loop will examine each of the Products in the Shopping cart. We create a temporary Product named tempProduct and cast it to a Product.(When we get the item out of the cart, the computer does not know what type of object it is. We must tell it that it is a Product. This is done by the :Product).

Once we have gotten the Product out of the cart, we get its total using the Product getTotal() method. This total is added to our local variable total. (total += tempProduct.getTotal(); is the same as total = total + tempProduct.getTotal(); )

The size() method just returns the number of elements in the array. The getElement just returns the object at that position.

Continue to page 3
 

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.

Premium Financing
Premium Financing with Premium Financial Advisors


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