JavaScript > JavaScript for Acrobat API Reference > JavaScript API > app > app methods > setTimeOut

setTimeOut
 
Specifies a JavaScript script and a time period. The script is executed one time only, after the period elapses.
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.
To cancel the timeout event, pass the returned timeout object to clearTimeOut.
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.
See also clearTimeOut, setInterval, and clearInterval.
Parameters
 
Returns
A timeout object
Example
Create 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 function
	function runMarquee() {
		var f = this.getField("marquee");
		var cStr = f.value;
		// get field value
		var aStr = cStr.split("");        // Convert to an array
		aStr.push(aStr.shift());          // Move first char to last
		cStr = aStr.join("");             // Back to string again
		f.value = cStr;                   // Put new value in field
	}
	
	// Insert a mouse-up action into a "Go" button
	run = app.setInterval("runMarquee()", 100);
	// stop after a minute
	stoprun=app.setTimeOut("app.clearInterval(run)",6000); 
	
	// Insert a mouse-up action into a "Stop" button
	try {
		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