The return value of this method must be held in a JavaScript variable. Otherwise, the timeout object is subject to garbage-collection, which would cause the clock to stop.Note: Beginning with Acrobat 7.05, an interval is automatically terminated when the document whose script called setInterval is closed (assuming it was not previously terminated).Opening and closing the document JavaScripts dialog box causes the JavaScript interpreter to re-read the document JavaScripts and consequently to re-initialize any document-level variables. Resetting document-level variables in this way after JavaScript expressions have been registered to be evaluated by setInterval or setTimeOut may cause JavaScript errors if those scripts use document-level variables.
A timeout objectCreate a simple running marquee. Assume there is a text field named “marquee”. The default value of this field is “Adobe Acrobat version 8.0 will soon be here!”.// Document-level JavaScript functionfunction runMarquee() {var f = this.getField("marquee");var cStr = f.value;// get field valuevar aStr = cStr.split(""); // Convert to an arrayaStr.push(aStr.shift()); // Move first char to lastcStr = aStr.join(""); // Back to string againf.value = cStr; // Put new value in field}// Insert a mouse-up action into a "Go" buttonrun = app.setInterval("runMarquee()", 100);// stop after a minutestoprun=app.setTimeOut("app.clearInterval(run)",6000);// Insert a mouse-up action into a "Stop" buttontry {app.clearInterval(run);app.clearTimeOut(stoprun);} catch (e){}The Stop button code is protected with a try/catch construct. If the user clicks the Stop button without having first clicked Go, run and stoprun will be undefined and the Stop code will throw an exception. When the exception is thrown, the catch code is executed. In this example, the code does nothing if the user clicks Stop first.
Send me an e-mail when comments are added to this page | Comment Report
Current page: http://livedocs.adobe.com/acrobat_sdk/9/Acrobat9_HTMLHelp/JS_API_AcroJS.88.166.html