Learn Actionscript - AHFX

Advanced Actionscript 

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 that is a very easy way to drop information from your flash shopping cart into a nice looking table. However, it does come with a mighty overhead (about 40KB). We will now look at making our own output for our shopping cart.

First create an empty movie clip by pressing Ctrl-F8. Name the movie clip empty_mc, and check export for actionscript. Close this clip.

Next create another movie clip and name this one display_mc and also check export for actionscript.On this clip create 4 dynamic text boxes and give them instance names of desc, quantity, price, and total. Also create a button and name it update_btn.

We will create a new display_mc for every item in our cart. Return to the main stage and change the code to look like this:

import com.ahfx.Product;
import com.ahfx.Shopping;
var myProduct = new Product();
myProduct.setDesc("Teddy Bear");
var myOtherProduct = new Product();
myOtherProduct.setDesc("Cool Sunglasses");
var shop_cart = new Shopping();
function displayCart(){
//Create main movie clip to hold shopping cart output
   empty_mc = attachMovie("empty_mc","empty_mc2",150);
//Create movie clip to hold shopping cart output headings
   temp_mc = empty_mc.attachMovie("display_mc","headings_mc",1001);
   temp_mc.total.text = "Total";
   temp_mc.desc.text = "Description";
   temp_mc.quantity.text = "Quantity";
   temp_mc.price.text = "Price";
   temp_mc.update_btn._visible = false;
   delete temp_mc;
//Loop through items in shopping cart
      var newProd:Product = shop_cart.getElement(i);
//Attach display for each item in shopping cart
      temp_mc = empty_mc.attachMovie("display_mc","display_mc"+i,i+100);
//Shift dispay downward 16 pixels
      temp_mc._y = (i + 1) * 16;
//Place values from product in shopping cart in the text fields
//Position holder of product in shopping cart
      temp_mc.pos = i;
//button action to update quantities
      temp_mc.update_btn.onPress = function() {
         var tempProduct:Product = shop_cart.getElement(this._parent.pos);
         if (this._parent.quantity.text == "0"){
         else {
   delete newProd;
//Create movie clip to hold shopping cart Grand Total output
   temp_mc = empty_mc.attachMovie("display_mc","total_mc",1000);
   temp_mc._y = (shop_cart.size() +1) * 16;
   temp_mc.total.text = shop_cart.getTotal();
   temp_mc.desc.text = "Grand Total";
   delete temp_mc;

Continue to page 4

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