Switching to toggle buttons in the code provided

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Atlante Avila

    Switching to toggle buttons in the code provided

    This AS2 code is a small shopping cart. What I'm trying to do here is change that when the add to cart button is clicked the items are added to the text fields in the shopping cart movie clip. But when it's clicked again, I want the items to be removed from the cart. i've tried changing the code on line 24 to
    Code:
    quantities[poz] -= itQ;
    and it works, but if you press the add to cart button again, it just keeps reducing the price. Any help will be appreciated!!!


    Code:
    currency_code = "USD";
    init = function(){
    	shoppingcart.items = "";
    	shoppingcart.amounts = "";
    	shoppingcart.quantities = "";
    	shoppingcart.total = "0 "+currency_code;
    	items = new Array();
    	amounts = new Array();
    	quantities = new Array();
    }
    addItem = function(itN,itA,itQ){
    	if(items.length > 0){
    		poz = -1;
    		for(i=0;i<items.length;i++){
    			if(items[i] == itN){
    				poz = i;
    			}
    		}
    		if(poz == -1){
    			items.push(itN);
    			amounts.push(itA);
    			quantities.push(itQ);
    		}else{
    			quantities[poz] += itQ;
    		}
    	}else{
    		items.push(itN);
    		amounts.push(itA);
    		quantities.push(itQ);
    	}
    	shoppingcart.items = "";
    	shoppingcart.amounts = "";
    	shoppingcart.quantities = "";
    	shoppingcart.total = 0;
    	for(i=0;i<items.length;i++){
    		shoppingcart.items += items[i]+"<br>";
    		shoppingcart.amounts += amounts[i]+" "+currency_code+"<br>";
    		shoppingcart.quantities += quantities[i]+"<br>";
    		shoppingcart.total += amounts[i] * quantities[i];
    	}
    	shoppingcart.total += " "+currency_code;
    }
    sendToPayPal = function(){
    	if(items.length > 0){
    		paypal = new LoadVars();
    		paypal.cmd = "_cart";
    		paypal.upload = "1";
    		paypal.no_note = "1";
    		paypal.business = "necromanthus@yahoo.com";
    		paypal.currency_code = currency_code;
    		for (n=0; n<items.length; n++) {
    			paypal["item_name_"+(n+1)] = items[n];
    			paypal["amount_"+(n+1)] = amounts[n];
    			paypal["quantity_"+(n+1)] = quantities[n];
    		}
    		paypal.send("https://www.paypal.com/cgi-bin/webscr", "_blank", "POST");
    	}
    }
    
    but1.onRelease=function(){
    	addItem("Intel Core 2 Duo E6850",270,1);
    }
    but2.onRelease=function(){
    	addItem("Intel Core 2 Quad Q6700",550,1);
    }
    but3.onRelease=function(){
    	addItem("Intel Core 2 Extreme QX6850",1000,1);
    }
    but4.onRelease=function(){
    	addItem("Wordpress Blog",750,1);
    }
    checkout.onRelease=function(){
    		sendToPayPal();
    }
    init();
    stop();
Working...