EasyManua.ls Logo

MACROMEDIA FLASH 8-ACTIONSCRIPT 2.0 LANGUAGE - Page 98

MACROMEDIA FLASH 8-ACTIONSCRIPT 2.0 LANGUAGE
1378 pages
Print Icon
To Next Page IconTo Next Page
To Next Page IconTo Next Page
To Previous Page IconTo Previous Page
To Previous Page IconTo Previous Page
Loading...
98 ActionScript language elements
Example 2: The following example is similar to the first, except that it calls
clearInterval() before setInterval(). This can help prevent unwanted loops and is
especially important in event-based systems where the initiating script can be executed
multiple times before any particular interval has been cleared.
var intervalId:Number;
var count:Number = 0;
var maxCount:Number = 10;
var duration:Number = 20;
function executeCallback():Void {
trace("executeCallback intervalId: " + intervalId + " count: " + count);
if(count >= maxCount) {
clearInterval(intervalId);
}
count++;
}
function beginInterval():Void {
if(intervalId != null) {
trace("clearInterval");
clearInterval(intervalId);
}
intervalId = setInterval(this, "executeCallback", duration);
}
beginInterval();
beginInterval();
beginInterval();
Example 3: The following example shows how to pass a custom argument to the function
that is being called.
var intervalId:Number;
var count:Number = 0;
var maxCount:Number = 10;
var duration:Number = 20;
var colors:Array = new Array("red",
"blue",
"yellow",
"purple",
"green",
"orange",
"salmon",
"pink",
"lilac",

Table of Contents

Related product manuals