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

Featured Tutorials
|