Creative Communities of the World Forums

The peer to peer support community for media production professionals.

  • Posted by Scott Mcgee on May 30, 2018 at 9:41 am

    I have an array of Icon buttons that work fine, but I can’t seem to get an array of .onClick’s to work with them.

    Array of Iconbuttons:

    var c = new Array();
    for(var i = 0; i <= 11 ; i++ ){
    c[i] = groupTwo.add (‘iconbutton’, undefined, undefined, {name:’Blue’, style: ‘toolbutton’});
    c[i].size = [30,20];
    c[i].fillBrush = c[i].graphics.newBrush(c[i].graphics.BrushType.SOLID_COLOR,scolor1[i]);
    c[i].onDraw = customDraw;
    function customDraw()
    { with( this ) {
    graphics.drawOSControl();
    graphics.rectPath(0,0,size[0],size[1]);
    graphics.fillPath(fillBrush);
    if( text ) graphics.drawString(text,textPen,(size[0]-graphics.measureString (text,graphics.font,size[0])[0])/2,3,graphics.font);
    }}
    }

    The onClick function at the moment is as follows

    for(var i = 0; i <= 1 ; i++ ){ c[i].onClick = function(){ { // create an undo group app.beginUndoGroup("AddEffect"); var curItem = app.project.activeItem; var selectedLayers = curItem.selectedLayers; try{ var curRem = curItem.selectedLayers[0].effect.property("Fill").remove(); var curLayer = curItem.selectedLayers[0].Effects.addProperty("ADBE Fill")("Color").setValue(scolor1[i]) }catch(err){ var curLayer = curItem.selectedLayers[0].Effects.addProperty("ADBE Fill")("Color").setValue(scolor1[i]); } // close the undo group app.endUndoGroup(); } } }

    I can’t seem to get the seem to get the colour to work by picking the colour from the array, but it works fine for the button.

    I assume that once the buttons been clicked it’s ignoring the for expression, but I’ve tried incorporating the colour outside and it’s going for the highest number available in my array not based on the button I’ve clicked.

    Scott Mcgee replied 8 years, 2 months ago 1 Member · 1 Reply
  • 1 Reply
  • Scott Mcgee

    May 31, 2018 at 8:34 am

    Mainly because I found a work around, but if anyone can suggest a tidier way to write this.

    I discovered another forum page that used this.

    b[0].myParameter = 0;
    b[1].myParameter = 1;

    for(var i = 0; i <= 1 ; i++ ){
    b[i].onClick = function() {
    app.beginUndoGroup(“AddEffect”);
    var curItem = app.project.activeItem;
    var selectedLayers = curItem.selectedLayers;

    try{
    var curRem = curItem.selectedLayers[0].effect.property(“Fill”).remove();
    var curLayer = curItem.selectedLayers[0].Effects.addProperty(“ADBE Fill”)(“Color”).setValue(pcolor[this.myParameter])
    }catch(err){
    var curLayer = curItem.selectedLayers[0].Effects.addProperty(“ADBE Fill”)(“Color”).setValue(pcolor[this.myParameter]);
    }

    app.endUndoGroup();
    }
    }

    This works how I want it to, but I still have to write

    b[0].myParameter = 0;
    b[1].myParameter = 1;
    b[2].myParameter = 2;

    bar putting this into a for loop itself I’ve saved over 350+ lines, but I want to try and save an additional 23 if I can, but I guess I’m just nit picking.

    If anyone has a suggestion. I’d be grateful.

We use anonymous cookies to give you the best experience we can.
Our Privacy policy | GDPR Policy