Copy link to clipboard
Copied
Hopefully an easy one.
If I let my script open
var aseFile = File.openDialog()
var data = app.parseSwatchFile(aseFile);
When my script opens. I can get the information I want from my ase file in my panel example below.
However if I use a button to load the ase file
btn.onClick = function(){
File.openDialog();
var data = app.parseSwatchFile(aseFile);
}
Then I get zippo.
I've tried using my functions, which essentially is what I'm using to fill the panel when I update my edittext, but event that doesn't work
btn.onClick = function(){
File.openDialog();
var data = app.parseSwatchFile(aseFile);
cleanUpGroup(grpContainer);
parseColor();
updatePanel(win);
apply();
}
You need to save selected file into a variable. Then check if user canceled or selected something. If nothing selected - abort, else do your magic.
P.S. Please use Inset/Edit code samples button that looks like this </> to post your code snippets - it makes so much easier to read your code.
btn.onClick = function() {
var aseFile = File.openDialog('Select *.ase file');
if (aseFile) {
var data = app.parseSwatchFile(aseFile);
cleanUpGroup(grpContainer);
parseColor();
updatePanel(win);
...
Copy link to clipboard
Copied
You need to save selected file into a variable. Then check if user canceled or selected something. If nothing selected - abort, else do your magic.
P.S. Please use Inset/Edit code samples button that looks like this </> to post your code snippets - it makes so much easier to read your code.
btn.onClick = function() {
var aseFile = File.openDialog('Select *.ase file');
if (aseFile) {
var data = app.parseSwatchFile(aseFile);
cleanUpGroup(grpContainer);
parseColor();
updatePanel(win);
apply();
}
}
Copy link to clipboard
Copied
Ah, that makes sense.
Big big thanks.
P.s shall do, I forget to do that. In creative cow I'm awful for doing it.
Also based on the other forum page. I promise my coding will improve and be less messy. Self teaching to get it to work Vs tidy and correct coding is something some friends get angry about. 😁
Copy link to clipboard
Copied
I'm still struggling with this. I can get this to work by adding the onClick feature in the function. But want to make sure that this is the right way of doing this.
If I have the btn2.onClick outside of the function, it doesn't pass the information, but going off the addColorButtons in the script you sent me in the other post, I'm guessing that it is.
var btn = win.add('button', undefined, 'Load Swatch');
var btn2 = win.add('button', undefined, 'Call Swatch');
btn.onClick = function() {
var aseFile = File.openDialog('Select *.ase file');
if (aseFile) {
var data = app.parseSwatchFile(aseFile);
var numColors = data.values.length;
var str = data.values[0].name;
}
btn2.onClick = function(){
alert(str);
}
}
Copy link to clipboard
Copied
Your str variable is scoped inside btn.onClick() function and is not accessible inside btn1.onClick() function. Please read about variable scopes in Javascript https://www.sitepoint.com/demystifying-javascript-variable-scope-hoisting/ to understand what's happening.
Find more inspiration, events, and resources on the new Adobe Community
Explore Now