Looking for some Javascript help with buttons
Using Adobe Acrobat X Pro, I would like the user to be able to click repeatedly on a single button in order to turn on and off the visibility of different objects or buttons, and the following cycle to happen:
- With the first click, button one becomes visible.
- With the second click, button two also becomes visible.
- With the third click, both buttons are hidden.
- With the fourth click, button one becomes visible.
- With the fifth click, button two also becomes visible.
- With the sixth click, both buttons are hidden…
- …and the cycle continues.
I have the code (below) that nearly does the trick, but I don’t want colours changing and would like to amend the code to replace the colour coding with a variable. However I cannot get this to work, as I don’t really know the syntax for setting global variables. E.g. I want to set a “behind the scenes” variable such as A, B, C that changes to the next letter on each click (with C going to A). This variable can then be used to go through the above cycle accordingly.
[background: there are more states than 3, but simplified for purposes of posting. Also this will need to be done in around 100 places, which is why I want a neater “variable” solution than changing colours!]
if (color.equal(event.target.fillColor, color.red))
{button1.display = display.visible;
event.target.fillColor = color.yellow;}
else if (color.equal(event.target.fillColor, color.yellow))
{button2.display = display.visible;
event.target.fillColor = color.green;}
else {event.target.fillColor = color.red;
button1.display = display.hidden;
button2.display = display.hidden;}
