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