# SetInterval function calls, this question

**URL:** <https://forum.kirupa.com/t/setinterval-function-calls-this-question/30034>\
**Category:** flash\
**Created:** [September 3, 2003, 4:05am UTC](https://forum.kirupa.com/t/setinterval-function-calls-this-question/30034 "2003-09-03T04:05:29Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![grandsp5](https://avatars.discourse-cdn.com/v4/letter/g/6bbea6/32.png) [@grandsp5](https://forum.kirupa.com/u/grandsp5)\
**Post date:** [September 3, 2003, 4:05am UTC](https://forum.kirupa.com/t/setinterval-function-calls-this-question/30034/1 "2003-09-03T04:05:29Z")

</div>

I am trying to create the effect of falling leaves and as part of this effect, I am writing a function called fall which takes 2 parameters, speed and angle. The function “fall” is called using SetInterval from the movie clip itself every 1 second. I have a problem though that I cant get around. Here is the code for the function fall

[AS]  
MovieClip.prototype.fall = function(speed, angle) {  
this.\_x += Math.sin(angle)\*3;  
this.\_y += speed;  
};  
[/AS]

and this is the code that calls it from the movie clip  
[AS]  
onClipEvent (load) {  
var speed = (.5+Math.random())\*4;  
var angle = Math.random()\*50;  
interval = 1000+Math.random()\*1000;  
setInterval(fall,interval , speed, angle);  
}  
[/AS]

my problem is I can’t figure out to to get the “this.\_y” statement and the “this.\_x” statement to reference the movie clip. When I call the funciton fall, this becomes undefined and does not reference anything. I tied this

[AS]  
setInterval(this.fall,interval , speed, angle);  
[/AS]

but that didn’t work very well. The only way around it I can think of is to pass the instance name of the movie clip I am calling it from as a parameter and use that instead of “this”. Basically, my question is how do I use 1 function that I wrote, called through setInterval, to have command over numerous different movie clips. I want to use 1 function to control all the leaves. If you need a better explanation, I will try. Thanks a bunch

---

<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:** [September 3, 2003, 5:07am UTC](https://forum.kirupa.com/t/setinterval-function-calls-this-question/30034/2 "2003-09-03T05:07:09Z")

</div>

One question, maybe kax can answer…  
can you call set interval for a prototype? 👁

---

<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:** [September 3, 2003, 5:34am UTC](https://forum.kirupa.com/t/setinterval-function-calls-this-question/30034/3 "2003-09-03T05:34:50Z")

</div>

You can, claudio. 😉  
[AS]setInterval(this, “fall”, interval, speed, angle);[/AS]

---

<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:** [September 3, 2003, 5:41am UTC](https://forum.kirupa.com/t/setinterval-function-calls-this-question/30034/4 "2003-09-03T05:41:02Z")

</div>

Thx for the info kax 😉

---

<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:** [September 3, 2003, 5:49am UTC](https://forum.kirupa.com/t/setinterval-function-calls-this-question/30034/5 "2003-09-03T05:49:23Z")

</div>

Anytime. 😛

---

<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:** [September 3, 2003, 6:49am UTC](https://forum.kirupa.com/t/setinterval-function-calls-this-question/30034/6 "2003-09-03T06:49:35Z")

</div>

gotcha. thanks a bunch. and claudio, i think he is kode now. kax has been deprecated

---

<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:** [September 3, 2003, 7:31am UTC](https://forum.kirupa.com/t/setinterval-function-calls-this-question/30034/7 "2003-09-03T07:31:54Z")

</div>

No problem, grandsp5. 😉

And yeah, kax has been deprecated. I don’t mind if you guys still call me kax, though. 😛

---

<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:** [September 3, 2003, 7:39am UTC](https://forum.kirupa.com/t/setinterval-function-calls-this-question/30034/8 "2003-09-03T07:39:20Z")

</div>

> \*Originally posted by kode \*  
> **And yeah, kax has been deprecated.**  
> I didnt know you were a scripting language Kax 😛 😛  
> Guess thats why you are such good coder  
> :beam:

---

<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:** [September 3, 2003, 7:42am UTC](https://forum.kirupa.com/t/setinterval-function-calls-this-question/30034/9 "2003-09-03T07:42:24Z")

</div>

Yup! I’m always up-to-date. 😛

And thanks for the compliment. 😊
