Using setTimeOut, setInterval, or other means, to delay script execution
- February 20, 2020
- 1 reply
- 7150 views
I have previously posted my Big Picture objective. Here, I take a Big Step Back, to get a grip on this, in the simplest context I can think of [welcome advice from (try67)]. But I am hindered by perilous partial-understanding of scripting [enough rope to...].
I've reviewed the JavaScriptTM for Acrobat® API Reference. I've scoured online references/suggestions/examples. I've created a slew of test documents. Almost without exception, they function 'dead in the water.' I am missing some things basic, and fundamental.
I sense I get hung up on [despite awareness of need for precision]
- distinguishing Acrobat-oriented JavaScript from HTML/browser-oriented use
- syntax precision -- e.g. case sensitivity, quotation-marks-or-not, ...
- app-level [Acrobat] vs. document-level vs. page-level management
I've considered setTimeOut, and setInterval, all sorts of ways. Here's what seems the simplest case [courtesy Thom Parker, 2008]. Upon a Button Event:
app.alert("Hello World", 3);
This works, as seen in the attachment.
But then, on a separate Buttion, I try to trigger the Alert as a parameter of setTimeOut:
// Utilize setTimeout ( expression, timeout );
//where expression is the JavaScript code to run after timeout milliseconds have elapsed.
//
setTimeout (app.alert("Hello World", 3), 2000 );
This fails, as seen in the attachment.
I can readily imagine that an entirely different approach is called for. But I am at a loss for insight/instinct as to whether this demands a defined routine/function/variables/declarations, etc., in what order, etc. I bet a number of you can see, at a glance, where I'm way off base.
Commentary most appreciated.
