# Problem With Interval & function

**URL:** https://forum.kirupa.com/t/problem-with-interval-function/82679
**Category:** flash
**Created:** [March 12, 2005, 6:17am UTC](https://forum.kirupa.com/t/problem-with-interval-function/82679 "2005-03-12T06:17:09Z")
**Posts on this page:** 1
**Page:** 1

<div class="post-metadata">

### Author: ![A7RSTR7K3](https://avatars.discourse-cdn.com/v4/letter/a/49beb7/32.png) [@A7RSTR7K3](https://forum.kirupa.com/u/A7RSTR7K3)
#### Post date: [March 12, 2005, 6:17am UTC](https://forum.kirupa.com/t/problem-with-interval-function/82679/1 "2005-03-12T06:17:09Z")

</div>

well currently, I have this mask set up… and I set the mask if the numbers randomly evaluate correctly… I set the mask. Then if it evaluates false, it gets rid of the mask. The problem is that the first time through… the function works perfect… however when run again it doesn’t work. The code is placed on the first and only frame of an mc… and when I trace(this) it returns like \_level0.instanceName the first time the function runs on all the mc’s however, the next time it runs this == undefined… I don’t understand that… Well I hope I explained it well, here is the code…

```auto
lightOn = function(){
	var isItOn = Math.floor(Math.random()*5);
	if(isItOn == 4){
		trace(this);
		this.light.setMask(dark);
		lightOnInterval = setInterval(lightOn, 6000);
	} else {
		this.light.setMask(null);
	}
}
lightOn();
lightOnInterval = setInterval(lightOn, 3000);

```
