Search code examples
javascriptacrobat

addField.setAction properties are not being retained...Possible causes?


I have some Javascript running in Acrobat XI that programmatically creates a series of buttons using the addField method. I need each button to run a specific lengthy Javascript routine upon MouseUp, but at the moment I can't seem to get any newly-created button to run even a trivially simple command.

Basically, when my code executes, everything works as intended with the exception of the .setAction property, which does not seem to be retained, leaving my newly created and formatted buttons without any functionality. I can go in after the fact and add the Javascript manually, of course, but in this case I need a programmatic solution.

Any ideas what I might be doing wrong here?

    var cScript = "app.beep(0);";  
    var newBTN = this.addField(wName,"button",thisPage,RotatedRect); 
    //"wName","thisPage" and "RotatedRect" are well-defined elsewhere

    newBTN.setAction=("MouseUp",cScript);
    newBTN.delay = true;
        newBTN.borderColor=color.red;
        newBTN.borderStyle=border.s;
    newBTN.delay=false;

This button is created as expected, and the formatting and name are as expected. The only problem is that the .setAction property does not seem to be saved at all. Nothing whatsoever happens when I click on the new button, and when I manually inspect the new button's properties, it has no action or javascript attached to it.

enter image description here


Solution

  • Turns out I was just being sloppy and not paying attention to syntax.

    Removing the "=" from the newBTN.setAction=("MouseUp",cScript);line has fixed the problem.