A Flash Developer Resource Site

Results 1 to 4 of 4

Thread: [RESOLVED] [MX04] delete btn in datafield

  1. #1
    Member
    Join Date
    Jan 2008
    Posts
    84

    resolved [RESOLVED] [MX04] delete btn in datafield

    I have got a button in a datagrid using cellrendering. but I can't seem to modify it into my datagrid cart. Here is the code want I am doing wrong.
    Any help will be great.

    PHP Code:
    //DELETE BUTTON
    import mx.controls.DataGrid;
    import mx.controls.gridclasses.DataGridColumn;

    // Create DataGrid columns
    var col = new DataGridColumn("TheButton");
    col.headerText "Delete";
    col.width 50;
    col.cellRenderer "ButtonCellRenderer";  // Assign custom cell renderer
    grid_dg.addColumn(col);

    var 
    dp:Array = new Array();
    grid_dg.dataProvider.addItem({TheButton:{label:"x"}});

    //BASKET

    var lvSend:LoadVars = new LoadVars();//do not change
    lvSend.business "chelnov63@hotmail.com"//your paypal email address here 
    lvSend.currency_code "GBP"//the currency you would like to use

    book "bag1";
    purse "purse1"

    //define items, their prices, quantity in basket and there associated movieclips
    var aItem:Array = new Array();
        
    aItem[book] = {price:15quantity:0size:10pic:pic};
        
    aItem[purse] = {price:25quantity:0size:30pic:pic};
        
        
    //-----------------------DO NOT CHANGE UNLESS FAMILIAR WITH ACTIONSCRIPT--------------------//    
        
        
    var totalPrice:Number;

    //define drag and drop functionality
    for (var i in aItem) {
        var 
    currentProduct:String i;
        
    aItem[i].item currentProduct;
        
        
    add1btn.onRelease = function() {
            
    aItem[book].quantity++;
            
    //update datagrid
            
    updateDatagrid();
        }
        
    add2btn.onRelease = function() {
            
    aItem[purse].quantity++;
            
    //update datagrid
            
    updateDatagrid();
        }
    }
    deleteall.onRelease = function() {
        
    aItem[currentProduct].quantity++;
        
    basketInfo.dataProvider.removeAll();
    }
    deleteone.onRelease = function() {
        
    basketInfo.dataProvider.removeItemAt(basketInfo.selectedIndex)
    }

    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].item;
                
    lvSend["amount_"+j] = aItem[i].price;
                
    lvSend["quantity_"+j] = aItem[i].quantity;
                
    lvSend["size_"+j] = aItem[i].size;
                
    j++;
                }
                
        }
        
    lvSend.send("https://www.paypal.com/cgi-bin/webscr""_self""POST");
    }


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

    function updateDatagrid():Void{
        
    totalPrice 0;
        var 
    aBasket:Array = new Array();
        for (var 
    i in aItem) {
        if(
    aItem[i].quantity ){
           
    aBasket.push({ProductaItem[i].itemSizeaItem[i].sizeQuantityaItem[i].quantityPriceaItem[i].price aItem[i].quantityPicaItem[i].pic});
           
    totalPrice += aItem[i].quantity aItem[i].price;
        }
    }

        
    grid_dg.dataProvider aBasket;
        
    grid_dg.vScrollPolicy "auto";
        
    tTotal.text totalPrice;

    Last edited by shaunfreeman; 05-23-2008 at 06:06 AM.

  2. #2
    Member
    Join Date
    Jan 2008
    Posts
    84
    Changed some code, turned some of the code off.
    Ok almost got it but column says [ object, object ]
    I think I need to use .cellRenderer = "ButtonCellRenderer"; but how?

    PHP Code:
    //deletebtn
    import mx.controls.DataGrid;
    import mx.controls.gridclasses.DataGridColumn;

    // Create DataGrid columns
    //var col = new DataGridColumn("TheButton");
    //col.headerText = "Delete";
    //col.width = 50;
    //col.cellRenderer = "ButtonCellRenderer";  // Assign custom cell renderer
    //grid_dg.addColumn(col);

    //var dp:Array = new Array();
    //grid_dg.dataProvider.addItem({TheButton:{label:"x"}});
    button = {TheButton:{label:"x"}}
    //basket

    var lvSend:LoadVars = new LoadVars();//do not change
    lvSend.business "chelnov63@hotmail.com"//your paypal email address here 
    lvSend.currency_code "GBP"//the currency you would like to use

    book "bag1";
    purse "purse1"

    //define items, their prices, quantity in basket and there associated movieclips
    var aItem:Array = new Array();
        
    aItem[book] = {price:15quantity:0size:10pic:picdel:button};
        
    aItem[purse] = {price:25quantity:0size:30pic:picdel:button};
        
        
    //-----------------------DO NOT CHANGE UNLESS FAMILIAR WITH ACTIONSCRIPT--------------------//    
        
        
    var totalPrice:Number;

    //define drag and drop functionality
    for (var i in aItem) {
        var 
    currentProduct:String i;
        
    aItem[i].item currentProduct;
        
        
    add1btn.onRelease = function() {
            
    aItem[book].quantity++;
            
    //update datagrid
            
    updateDatagrid();
        }
        
    add2btn.onRelease = function() {
            
    aItem[purse].quantity++;
            
    //update datagrid
            
    updateDatagrid();
        }
    }
    deleteall.onRelease = function() {
        
    aItem[currentProduct].quantity++;
        
    basketInfo.dataProvider.removeAll();
    }
    deleteone.onRelease = function() {
        
    basketInfo.dataProvider.removeItemAt(basketInfo.selectedIndex)
    }

    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].item;
                
    lvSend["amount_"+j] = aItem[i].price;
                
    lvSend["quantity_"+j] = aItem[i].quantity;
                
    lvSend["size_"+j] = aItem[i].size;
                
    j++;
                }
                
        }
        
    lvSend.send("https://www.paypal.com/cgi-bin/webscr""_self""POST");
    }


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

    function updateDatagrid():Void{
        
    totalPrice 0;
        var 
    aBasket:Array = new Array();
        for (var 
    i in aItem) {
        if(
    aItem[i].quantity ){
           
    aBasket.push({ProductaItem[i].itemSizeaItem[i].sizeQuantityaItem[i].quantityPriceaItem[i].price aItem[i].quantityPicaItem[i].picDeleteaItem[i].del});
           
    totalPrice += aItem[i].quantity aItem[i].price;
        }
    }

        
    grid_dg.dataProvider aBasket;
        
    grid_dg.vScrollPolicy "auto";
        
    tTotal.text totalPrice;


  3. #3
    Member
    Join Date
    Jan 2008
    Posts
    84
    Ok forget about that. going to use this instead

    PHP Code:
    var dgListener:Object = new Object();
    dgListener.cellPress = function(evt:Object) {
        var 
    num:Number evt.target.selectedIndex;
        var 
    cell:String evt.columnIndex+", "+evt.itemIndex;
        
    tmp evt.target.columns[evt.columnIndex].columnName;
        
    trace(+evt.target.getItemAt(evt.itemIndex)[tmp]);
        
    //delete x
        
    xbutton = +evt.target.getItemAt(evt.itemIndex)[tmp];
        if (
    xbutton == "x") {
            
    trace("action1");
            
    grid_dg.dataProvider.removeItemAt(grid_dg.selectedIndex)
        }
        if (
    xbutton == "+") {
            
    trace("action2");
            
    trace(grid_dg.selectedIndex.quantity);
        }
    };
    grid_dg.addEventListener("cellPress"dgListener); 
    action 1 sort of works (the array does not reset,clear)

    action 2 does not work
    I am trying to get the value of the quantity and add 1 to it. But can't seem to target quantity.

  4. #4
    Member
    Join Date
    Jan 2008
    Posts
    84
    close thread
    Last edited by shaunfreeman; 05-25-2008 at 10:52 AM.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  




Click Here to Expand Forum to Full Width

HTML5 Development Center