-
Array .onClick
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.