• Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers
Exit
0

Repeated calculation with different parameters upon MouseUp Button action

New Here ,
Oct 31, 2017 Oct 31, 2017

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!

TOPICS
Acrobat SDK and JavaScript

Views

550

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines

correct answers 1 Correct answer

Community Expert , Nov 04, 2017 Nov 04, 2017

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

...

Votes

Translate

Translate
Community Expert ,
Nov 04, 2017 Nov 04, 2017

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

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Nov 04, 2017 Nov 04, 2017

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)??

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Nov 05, 2017 Nov 05, 2017

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".

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Nov 05, 2017 Nov 05, 2017

Copy link to clipboard

Copied

where can I read about this "global" object? I failed to find anything

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Nov 05, 2017 Nov 05, 2017

Copy link to clipboard

Copied

LATEST

Look at the Acrobat JavaScript Reference.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines