Copy link to clipboard
Copied
I need a repeated calculations with different array parameters upon the same button MouseUp activation.
i.e. when the user press-leave the mouse button I want the Javascript to take 2 values from an array, perform some calculations and send to TextFields. Upon next iteration (a user induced a MouseUp again) the code should move to the next 2 values within the array and so on.
What is the best way to implement it? Should I set any global variable (counter)?
Thanks a lot!
So let's say you have an array of numbers and each time the button is clicked you want to multiply two of them.
You could use a global variable, but then you need to make sure that that option is enabled in the preferences, so it might be better to just use a doc-level variable, or even a (hidden) text field, if you want to maintain the position even after the file is closed.
At the doc-level you can have this code:
var position = 0;
var nums = [13, 3, 63, 2, 76, 10];
As the MouseUp event of the butt
...Copy link to clipboard
Copied
So let's say you have an array of numbers and each time the button is clicked you want to multiply two of them.
You could use a global variable, but then you need to make sure that that option is enabled in the preferences, so it might be better to just use a doc-level variable, or even a (hidden) text field, if you want to maintain the position even after the file is closed.
At the doc-level you can have this code:
var position = 0;
var nums = [13, 3, 63, 2, 76, 10];
As the MouseUp event of the button you can use this code:
this.getField("Text1").value = nums[position] * nums[position+1];
position+=2;
if (position>=nums.length) position=0; // reset when reaching the end of the array
Copy link to clipboard
Copied
Thanks for the answer. I thought that every doc-lever var is global, but from your answer I see that you differentiate them... could you please elaborate (which option should be enabled)??
Copy link to clipboard
Copied
A "global" variable means something very specific in Acrobat, namely, a variable that was defined using the global object.
Such variables are accessible by all documents in the application, and can even be set up to be persistent beyond the current session, ie you could close Acrobat down and the next time you restart it the variable will still exists, with its last value.
A doc-level variable is accessible to all scripts that are located within that document, but it's not "global".
Copy link to clipboard
Copied
where can I read about this "global" object? I failed to find anything
Copy link to clipboard
Copied
Look at the Acrobat JavaScript Reference.