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

To improve the output, we will add another column, Total, format the column headings, and set the size of the columns.

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);

dataGrid.columnNames = ["desc" ,"price","quantity","Total"];
dataGrid.getColumnAt(3).labelFunction = function(item){
   return item.getTotal();
}
var temp = dataGrid.getColumnAt(0);
temp.headerText = "Description";
temp.width=125;
var temp = dataGrid.getColumnAt(1);
temp.headerText = "Price";
temp.width=75;
var temp = dataGrid.getColumnAt(2);
temp.headerText = "Quantity";
temp.width=75;

for(i=0;i<shop_cart.size();i++){
   var newProd:Product = shop_cart.getElement(i);
   dataGrid.addItem(newProd);
   delete newProd;
}

 

Line by line, this is what we have done. The columnNames() method arranges the columns in the order we want them to be in and adds a new column, Total. The function labelFunction generates the calculated field for Total.

The headerText relabels the Headers with full words instead of the variable shorthand versions. The width sets the width of the column. The output now looks like this:

 

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.


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