User Guide
setInterval() 733
If you work with setInterval() within classes, you need to be sure to use the this keyword
when you call the function. The
setInterval() function does not have access to class members
if you do not use the keyword. This is illustrated in the following example. For a FLA file with a
button called
deleteUser_btn, add the following ActionScript to Frame 1:
var me:User = new User("Gary");
this.deleteUser_btn.onRelease = function() {
trace("Goodbye, "+me.username);
delete me;
};
Then create a FLA in the same directory called User.as. Enter the following ActionScript:
class User {
var intervalID:Number;
var username:String;
function User(param_username:String) {
trace("Welcome, "+param_username);
this.username = param_username;
this.intervalID = setInterval(this, "traceUsername", 1000, this.username);
}
function traceUsername(str:String) {
trace(this.username+" is "+getTimer()/1000+" seconds old, happy
birthday.");
}
}
See also
clearInterval(), updateAfterEvent()