Skip to main content
Known Participant
September 1, 2020
Question

Button onClick, not functioning

  • September 1, 2020
  • 2 replies
  • 825 views

Greetings.

 

I have a button defined as such

 

var execBtn = appWindow.add('button',undefined,'Export');

 

I then click on it thusly:

 

execBtn.onClick = function(){

someFunction();

 

}

 

The code in someFunction() runs fine outside of the button but will not execute when wrapped within the button. I triple checked that variables passed to someFunction were either global or defined within the scope of the button click itself. Not sure why it will not run. Is there some other way to do this like onButtonDown or something?

 

I appreciate the community's time and any assistance you can provide.

 

This topic has been closed for replies.

2 replies

Community Expert
September 2, 2020

Try using addEventListener method instead of onClick. Something like the following

execBtn.addEventListener("click", function(){

       someFunction()

})

-Manan

 

-Manan
Known Participant
September 2, 2020

This is also a great idea. Thank you!

Legend
September 1, 2020

Use try catch.

For tests use this

execBtn.onClick = function()
   {
    try {
        alert(1);
        someFunction();
        alert(2);
        }
    catch(e) { alert(e); }
    }

 

Known Participant
September 1, 2020

Thank you very much! I was wondering how I could do a "console.log()" type debug to catch where it was going wrong. Thanks again!

Legend
September 2, 2020
Hmm ..
Do not know what to say.
Try to use
$ .write ()
But for this, the script must be run from the ExtendScript Toolkit

I don't use it.