03.05.2013 Views

ActionScript 2.0 Language Reference - Adobe Help and Support

ActionScript 2.0 Language Reference - Adobe Help and Support

ActionScript 2.0 Language Reference - Adobe Help and Support

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

Example 2: The following example is similar to the first, except that it calls<br />

clearInterval() before setInterval(). This can help prevent unwanted loops <strong>and</strong> is<br />

especially important in event-based systems where the initiating script can be executed<br />

multiple times before any particular interval has been cleared.<br />

var intervalId:Number;<br />

var count:Number = 0;<br />

var maxCount:Number = 10;<br />

var duration:Number = 20;<br />

function executeCallback():Void {<br />

trace("executeCallback intervalId: " + intervalId + " count: " + count);<br />

if(count >= maxCount) {<br />

clearInterval(intervalId);<br />

}<br />

count++;<br />

}<br />

function beginInterval():Void {<br />

if(intervalId != null) {<br />

trace("clearInterval");<br />

clearInterval(intervalId);<br />

}<br />

intervalId = setInterval(this, "executeCallback", duration);<br />

}<br />

beginInterval();<br />

beginInterval();<br />

beginInterval();<br />

Example 3: The following example shows how to pass a custom argument to the function<br />

that is being called.<br />

var intervalId:Number;<br />

var count:Number = 0;<br />

var maxCount:Number = 10;<br />

var duration:Number = 20;<br />

var colors:Array = new Array("red",<br />

Global Functions 101

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!