.shivanshi.
. Home . Share . Share Success . Join Us! .

ActionScript - Code Samples

SetInterval

Here are three different ways to use SetInterval.
Download setInterval.zip

//SetIntervalClass1.as
class SetIntervalClass1 {
	var id:Number;
	var INTERVAL:Number = 1000;
	function SetIntervalClass1() {
	}
	function someMethod() {
		id = setInterval(timerMethod, INTERVAL, this);
	}
	function timerMethod(ref:SetIntervalClass1) {
		ref.otherMethod();
	}
	function otherMethod() {
		trace("other method in SetIntervalClass1 is called...");
	}
}


// in fla
var s1 = new SetIntervalClass1();
s1.someMethod();             


//SetIntervalClass2.as
class SetIntervalClass2 {
	var id:Number;
	static var INTERVAL:Number = 1000;
	var ctr:Number = 1;
	function SetIntervalClass2() {
	}
	function someMethod() {
		id = setInterval(this, "timerMethod", SetIntervalClass2.INTERVAL);
	}
	function timerMethod() {
		otherMethod();
	}
	function otherMethod() {
		trace("other method in SetIntervalClass2 called...  "+ctr++);
	}
}


//  in fla
var s2 = new SetIntervalClass2();
s2.someMethod();            


//SetIntervalDelegate.as
class SetIntervalDelegate {
	private var INTERVAL:Number = 1000;
	private var timer;
	function SetIntervalUseDelegate() {
	}
	function someMethod() {
		timer = setInterval(mx.utils.Delegate.create(this, otherFunction), INTERVAL);
	}
	function otherFunction() {
		trace("other function in SetInervalDelegate is called...");
	}
}


//  in fla
var s = new SetIntervalDelegate();
s.someMethod();           
Add Favorite
| About Us | Site Map | Privacy Policy | Contact Us |
.shivanshi.