Expand my Community achievements bar.

Is there some object in Designer to calculate the passed time (like C# Timer)?

Avatar

Former Community Member
I would like to know if there is some object in Adobe Designer that allows me to execute an operation periodically, like for example the Timer object in C Sharp.



For example, is it possible to retard the execution of a code sentence for a certain time?




Thanks in advance!

Dan
4 Replies

Avatar

Former Community Member
You can use the app.setTimeOut() method to supply some code some amount of time in the future - for example:



app.setTimeOut("app.alert('hello')", 1000);



This would pop up an alert one second after this line of code was executed.

--

SteveX

Adobe Systems

Avatar

Former Community Member
Would it be possible to execute more than one sentence in the same time-out?



For example:

> var a = 0;



> app.setTimeOut("app.alert('hello');a++;", 1000);



Could I pass a block of code to it instead of an only line? that's the question.




Regards and thank you SteveX,

Dan

Avatar

Former Community Member
In ECMAScript you'd have had the option of using an anonymous inner function like:





setTimeout(function(){

// do anything

}, 1000);




Obviously it's impossible in Adobe JavaScript. I figure, you have to define a separate function to call. Like:





function doAnything(param){

// do anything

}

var a = 0;

app.setTimeOut("doAnything(a);", 1000);




Unfortunately, this way you can only pass parameters of simple types in functions used within setTimeOut() -- no object types! At least that's the way ECMAScript deals with setTimeout...



Steve

Avatar

Former Community Member
Note that script executed via the app.setTimeOut method is executed at the Acrobat Document level which means that unless you've already defined the
doAnything(param) function inside the PDF in Acrobat, you'll get a scripting error when the time-out occurs.



This (big) limitation also means that you can't have a function defined inside an XFA script object, for example, executed when the time-out occurs.



With regards to Danmaster's question about executing more than a single statement, I don't think it would be a problem. The JavaScript Engine in Acrobat will evaluate the string passed to app.setTimeOut as JavaScript so all the rules would apply. Therefore, something like "var a = 0; a++;" should define "a"
in the Acrobat Document Object scope and increment it by one.



Stefan

Adobe Systems