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

setInterval
 
Specifies a JavaScript script and a time period. The script is executed every time the period elapses.
The return value of this method must be held in a JavaScript variable. Otherwise, the interval object is subject to garbage-collection, which would cause the clock to stop.
To terminate the periodic execution, pass the returned interval object to clearInterval.
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 clearInterval, setTimeOut and clearTimeOut.
Parameters
 
Returns
An interval object
Example
Create a simple color animation on a field called “Color” that changes every second.
	function DoIt() {
		var f = this.getField("Color");
		var nColor = (timeout.count++ % 10 / 10);
		// Various shades of red.
		var aColor = new Array("RGB", nColor, 0, 0);
		f.fillColor = aColor;
	}
	// save return value as a variable
	timeout = app.setInterval("DoIt()", 1000); 
	// Add a property to our timeout object so that DoIt() can keep 
	// a count going.
	timeout.count = 0;
See setTimeOut for an additional example.

 

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.165.html