
AHFX Actionscript Home
Basic Actionscript
Intermediate Actionscript
Advanced Actionscript
About AHFX
Contact AHFX
Great Actionscript Links
|
 |
Actionscript 2.0 Flash Implementation
If everything went well you will get a display of a heading row, two items, and grand total row. Now you can change the quantity textbox to a input box and make your update_btn active. After a little tweaking it looks like this:
Now if you change the quantity and hit update, you will get a new total for that item and a new grand total. You can also create "Add to Cart" buttons to add items into the cart. New output looks like this:
If you want to be able to remove an item from the cart you will need to change the Shopping Cart Actionscript 2.0 Class to look like this:
import com.ahfx.Product;
class com.ahfx.Shopping {
private var cart:Array;
private var elementCount:Number;
function Shopping(){
cart = new Array(20);
elementCount = 0;
}
function addElement(object){
cart[elementCount++] = object;
}
function getTotal():Number{
var total = 0;
var i;
for(i=0;i<elementCount;i++){
var tempProduct:Product = cart[i];
total += tempProduct.getTotal();
}
return total;
}
function size():Number{
return elementCount;
}
function getElement(index){
return cart[index];
}
function removeElementAt(index) {
if (index <= elementCount && index > -1){
delete cart[index];
for (var i = index+1; i<elementCount; i++) {
cart[i-1] = cart[i];
}
elementCount--;
}
}
}
|
Our new output is more attractive and it has reduced the file size to 1KB.
Continue to page 5
|
 |

Featured Tutorials
|