PDA

View Full Version : [AS2] updating datagrid


trendykarn
06-23-2009, 12:39 PM
hello,

I want to know how to update datagrid if it's data is coming from an array.
I am doing a shopping cart so when I press or drag and drop any object to basket(movieClip:mcBasket), function updateDataGrid runs.
but if I have to update quantity of an object how to do that.
I am trying to do this with a textBox and a update btn
take a look ::
stop();
var aItem:Array = new Array();

aItem["Doctor Blade"] = {instance:mcClapper, price:58, quantity:0};
aItem["Mag Roller"] = {instance:mcDrum, price:22, quantity:0};
aItem["Wiper Tab"] = {instance:(mcShield && mcShield2), price:13, quantity:0};
aItem["Short Bushing"] = {instance:mcFeather, price:2, quantity:0};
aItem["Long Bushing"] = {instance:mcBook, price:15, quantity:0};
aItem["Drive Gear"] = {instance:mcGear, price:15, quantity:0};
aItem["End Foam"] = {instance:mcFoam, price:15, quantity:0};
aItem["Drive Side End Plate"] = {instance:mcDrive, price:15, quantity:0};
aItem["Contact Side End Plate"] = {instance:mcContact, price:15, quantity:0};
aItem["Exit Port Plug"] = {instance:mcExit, price:15, quantity:0};
aItem["Mag Roller Sealing Blade"] = {instance:mcBlade, price:15, quantity:0};
aItem["Body"] = {instance:mcPrinter, price:15, quantity:0};




var totalPrice:Number;

//define drag and drop functionality
for (var i in aItem) {
var currentProduct:String = i;
aItem[i].instance.id = currentProduct;

aItem[i].instance.onPress = function() {
this.swapDepths(_root.getNextHighestDepth());
this.origX = this._x;
this.origY = this._y;
this.startDrag();
};

aItem[i].instance.onRelease = function() {
this.stopDrag();
//if (checkDropLocation(this)) {
//it has been added to basket so increase quantity in basket
aItem[this.id].quantity++;

//update datagrid
updateDatagrid();

//also send it back to its original position and fade it in
this._alpha = 0;
//reposition(this);
fadeIn(this);

//let user know it has been added to basket

//} else {
//not in basket so send it back to its original position
//reposition(this);
}
};

aItem[i].instance.onReleaseOutside = aItem[i].instance.onRelease;
//}


mcPaypal.onRelease = function():Void{
//send variables to paypal

//CONSTANTS
lvSend.cmd = "_cart";
lvSend.upload = "1";

var j:Number = 1;
for (var i in aItem) {
if(aItem[i].quantity > 0){
lvSend["item_name_"+j] = aItem[i].instance.id;
lvSend["amount_"+j] = aItem[i].price;
lvSend["quantity_"+j] = aItem[i].quantity;
j++;
}

}
lvSend.send("https://www.paypal.com/cgi-bin/webscr", "_self", "POST");
}



//--------------------------------------- functions ----------------------------------------------//

function checkDropLocation(movie:MovieClip):Boolean {
if (movie.hitTest(mcBasket)) {
return true;
}
return false;
}

function reposition(movie:MovieClip):Void{
movie._x = movie.origX;
movie._y = movie.origY;
}

function fadeIn(movie:MovieClip):Void{
movie.onEnterFrame = function():Void{
this._alpha +=10 ;
if(this._alpha == 100){
delete this.onEnterFrame;
}
}
}
function updatePerson():Void{
// Make sure an item is selected.
if (basketInfo.selectedItem !== null) {
aBasket.push({Quantity:firstInput.text}, basketInfo.selectedIndex);

}
}

function updateDatagrid():Void{
totalPrice = 0;
var aBasket:Array = new Array();
for (var i in aItem) {
if(aItem[i].quantity > 0 ){
aBasket.push({Product: aItem[i].instance.id, Quantity: aItem[i].quantity, Price: aItem[i].price * aItem[i].quantity });
totalPrice += aItem[i].quantity * aItem[i].price;
}
}

basketInfo.dataProvider = aBasket;
basketInfo.vScrollPolicy = "auto";
tTotal.text = totalPrice;
}var dgListener:Object = new Object();
dgListener.change = function(evt_obj:Object) {
clearInputs();
firstInput.text = basketInfo.selectedItem.Quantity;
};

// Add listener.
basketInfo.addEventListener("change", dgListener);



mcClapper.onRollOver = function()
{
envelope.caption.startDrag(true);
envelope.caption._visible = 1;
envelope.caption.label = "Doctor Blade";
}
mcClapper.onRollOut = function()
{
envelope.caption._visible = 0;
stopDrag ();
}
mcDrum.onRollOver = function()
{
envelope1.caption1.startDrag(true);
envelope1.caption1._visible = 1;
envelope1.caption1.label = "Mag Roller";
envelope1.caption1.descr.text = "Rs.1399";
}
mcDrum.onRollOut = function()
{
envelope1.caption1._visible = 0;
stopDrag ();
}
mcShield.onRollOver = function()
{
envelope6.caption6.startDrag(true);
envelope6.caption6._visible = 1;
envelope6.caption6.label = "Mag Roller Wiper Tab";
}
mcShield.onRollOut = function()
{
envelope6.caption6._visible = 0;
stopDrag ();
}
mcShield2.onRollOver = function()
{
envelope6.caption6.startDrag(true);
envelope6.caption6._visible = 1;
envelope6.caption6.label = "Mag Roller Wiper Tab";
}
mcShield2.onRollOut = function()
{
envelope6.caption6._visible = 0;
stopDrag ();
}
mcFeather.onRollOver = function()
{
envelope5.caption5.startDrag(true);
envelope5.caption5._visible = 1;
envelope5.caption5.label = "Mag Roller Short Bushing";
}
mcFeather.onRollOut = function()
{
envelope5.caption5._visible = 0;
stopDrag ();
}
mcBook.onRollOver = function()
{
envelope4.caption4.startDrag(true);
envelope4.caption4._visible = 1;
envelope4.caption4.label = "Mag Roller Long Bushing";
}
mcBook.onRollOut = function()
{
envelope4.caption4._visible = 0;
stopDrag ();
}
mcGear.onRollOver = function()
{
envelope2.caption2.startDrag(true);
envelope2.caption2._visible = 1;
envelope2.caption2.label = "Mag Roller Drive Gear";
}
mcGear.onRollOut = function()
{
envelope2.caption2._visible = 0;
stopDrag ();
}
mcFoam.onRollOver = function()
{
envelope3.caption3.startDrag(true);
envelope3.caption3._visible = 1;
envelope3.caption3.label = "Mag Roller End Foam";
}
mcFoam.onRollOut = function()
{
envelope3.caption3._visible = 0;
stopDrag ();
}
mcDrive.onRollOver = function()
{
envelope7.caption7.startDrag(true);
envelope7.caption7._visible = 1;
envelope7.caption7.label = "Drive Side End Plate";
}
mcDrive.onRollOut = function()
{
envelope7.caption7._visible = 0;
stopDrag ();
}
mcContact.onRollOver = function()
{
envelope8.caption3.startDrag(true);
envelope8.caption3._visible = 1;
envelope8.caption3.label = "Contact Side End Plate";
}
mcContact.onRollOut = function()
{
envelope8.caption3._visible = 0;
stopDrag ();
}
mcExit.onRollOver = function()
{
envelope9.caption3.startDrag(true);
envelope9.caption3._visible = 1;
envelope9.caption3.label = "Contact Side End Plate";
}
mcExit.onRollOut = function()
{
envelope9.caption3._visible = 0;
stopDrag ();
}
mcBlade.onRollOver = function()
{
envelope10.caption3.startDrag(true);
envelope10.caption3._visible = 1;
envelope10.caption3.label = "Contact Side End Plate";
}
mcBlade.onRollOut = function()
{
envelope10.caption3._visible = 0;
stopDrag ();
}
mcPrinter.onRollOver = function()
{
envelope11.caption3.startDrag(true);
envelope11.caption3._visible = 1;
envelope11.caption3.label = "Body";
envelope1.caption1.descr.text = aItem[i].price;
}
mcPrinter.onRollOut = function()
{
envelope11.caption3._visible = 0;
stopDrag ();
}

trendykarn
06-23-2009, 12:42 PM
Thanks to flashmatics for this wonderful cart
Bt I am in trouble with this