I apologize in advance for my extreme lack of experience. If anyone can help me a) add a button to a button collection and/or b) create the proper syntax for an event listener, I would greatly appreciate it.
I’m trying to activate a button within my PDF to run a function in my JSX file. I’ve searched for days and all event types seem to fail when using addEventListener().
First, I tried adding an event listener to a button named “Respond” in the Buttons and Form panel of my InDesign file:
var myDoc = app.activeDocument;
var submitButton = myDoc.buttons.itemByName(“Respond”); // the button in my InDesign file is named “Respond”
submitButton.addEventListener(“onclick”, myFunction); // tried every event type I could find (mouseup, MOUSE_UP, onClick, etc)
Note: I realized “buttons” is a collection of buttons and lacks the method “addEventListener” but every attempt to add it as a new button failed, where adding a button group actually succeeded.
Second, I tried creating a button from scratch. The button gets created and styled, but using “buttons.add()” again. Tried various methods to add a button with “button.add()”, always getting the error “Object doesn’t support property or method ‘button'”
var buttonGroup = myDoc.pages[myStartPage].buttons.add();
var buttonTextFrame = myDoc.pages[myStartPage].textFrames.add();
buttonTextFrame.contents = “Submit”;
var buttonText = buttonTextFrame.paragraphs[0];
buttonText.appliedFont = app.fonts.item(“DIN Next LT Pro”);
buttonText.fontStyle = “Bold”;
buttonText.pointSize = 11;
buttonText.fillColor = myDoc.colors.item(“Paper”);
buttonText.justification = Justification.centerAlign;
buttonGroup.fillColor = myDoc.colors.item(“mhi-blue”);
buttonGroup.geometricBounds = [“134mm”,”141mm”,”142mm”,”167mm”];
buttonTextFrame.geometricBounds = [“136mm”,”141mm”,”142mm”,”167mm”];