Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
0

change/update onClick

Participant ,
Feb 17, 2020 Feb 17, 2020
I want to change buttons.

I can change the text or shape. But I can't seem to add or remove a button. I'm reading a json/ase file. That creates buttons based on the name I define. This works fine on opening the app. However should I want to change it "if(colorData.name.indexOf(btn.text) > -1)"
 
var btnGrp = this.win.add('group', undefined, undefined, {alignment: 'fill'});
var btn = btnGrp.add('edittext', undefined, "DA ");
var apply = btnGrp.add('button', undefined, 'APPLY');
 
var aseFile = File("/Volumes/Server/Media/Brands/CA Brand Colours new.ase");
var data = app.parseSwatchFile(aseFile);
var numColors = data.values.length;
 
//Create Array from aseFile
var dataField = new Array();
for (var i=0; i<numColors; i++){ var colorData = data.values[i];
if(colorData.type == "RGB"){
if(colorData.name.indexOf(btn.text) > -1){
color = [colorData.r, colorData.g, colorData.b, 1];
dataField[dataField.length] = new Array(color,colorData.name); }
}
}
 
var b = new Array();
for(var i = 0; i < dataField.length ; i++ ){
b[i] = btnGrp.add('iconbutton', undefined, undefined, {name:'Blue', style: 'toolbutton'}); b[i].size = [30,this.defaultSize[1]];
b[i].fillBrush = b[i].graphics.newBrush(b[i].graphics.BrushType.SOLID_COLOR,dataField[i][0]);
b[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); }
}
}
 
apply.onClick = function(){
btn.text = "CAI ";
CHANGE MY BUTTON ARRAY;
};
 
Screenshot 2020-02-17 at 16.58.33.pngScreenshot 2020-02-17 at 17.00.09.png
Any ideas?
TOPICS
Error or problem , How to , Scripting , User interface or workspaces
200
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
no replies

Have something to add?

Join the conversation