# MY first AS 2.0 problem

**URL:** <https://forum.kirupa.com/t/my-first-as-2-0-problem/94227>\
**Category:** Uncategorized\
**Created:** [November 10, 2003, 2:16pm UTC](https://forum.kirupa.com/t/my-first-as-2-0-problem/94227 "2003-11-10T14:16:08Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![dene](https://avatars.discourse-cdn.com/v4/letter/d/f19dbf/32.png) [@dene](https://forum.kirupa.com/u/dene)\
**Post date:** [November 10, 2003, 2:16pm UTC](https://forum.kirupa.com/t/my-first-as-2-0-problem/94227/1 "2003-11-10T14:16:08Z")

</div>

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

```auto

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.

```auto

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

```

Why? Thanks so much if you can help.

Dene

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [November 14, 2003, 2:00am UTC](https://forum.kirupa.com/t/my-first-as-2-0-problem/94227/2 "2003-11-14T02:00:26Z")

</div>

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() !

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [November 14, 2003, 2:17am UTC](https://forum.kirupa.com/t/my-first-as-2-0-problem/94227/3 "2003-11-14T02:17:34Z")

</div>

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]
