MY first AS 2.0 problem

Hi
I’ve recreated the problem as a simple example to demonstrate it best.
It’s bizarre. Here’s the class:


class MyClass 
{
	// For setInterval:
	public var _intervalID:Number;

	public function MyClass()
	{
		init();
	}
	public function init():Void
	{
		trace("init");
		_intervalID = setInterval(this, "update", 20);
	}
	public function update():Void
	{
		trace("update");
	}
}

If i try to create an instance of the class inside an event handler, the setInterval function within the class never executes. The trace statement should repeatedly display “update” in the output panel.


box.onPress = function()
{
	var test:MyClass = new MyClass();
}

Why? Thanks so much if you can help.

Dene

Just thought i’d post some feedback:

Using the form of setInterval() without the reference to ‘this’ meant that the function called by the interval didn’t have access to the properties of the class.

Back to using the full version of setInterval() !

something like this should work okay,

[AS]
class MyClass {
private var intervalID:Number;
public function MyClass() {
init();
}
public function init():Void {
intervalID = setInterval(this, “update”, 20);
}
private function update():Void {
trace(“update”);
}
public function clearUpdate():Void { // assuming something doesn’t clear the interval internally add a method so the movie can stop it
clearInterval(intervalID);
}
}
[/AS]

then in the movie,

[AS]
var test:MyClass;
start_btn.onPress = function() {
test = new MyClass();
};
stop_btn.onPress = function() {
test.clearUpdate();
};
[/AS]