So I have a pretty complex set of functions but I will try to make this understandable with minimal code…
I have a group of buttons. When each button is pressed it calls on the leafFall() function.
leafFall = function () {
var leafTotal = 9;
var i = 0;
for (i=1; i<leafTotal; i++) {
var leaf = eval("leaf"+i+"_mc");
leaf.enabled = false;
var k = random(4000);
leaf.delay = setInterval(leafFall2, k, i);
openedInterval=leaf.delay
}
};
which then calls on leafFall2() from the setInterval
leafFall2 = function (i) {
leaf = eval("leaf"+i+"_mc");
leaf.enabled = false;
clearInterval(leaf.delay);
leaf.j = i;
leaf.grow = random(75)+25;
leaf.fallSpeed = random(3)+2;
leaf.rotationSpeed = random(10)-5;
leaf.onEnterFrame = function() {
if (leaf.rotationSpeed == 0) {
leaf.rotationSpeed = random(10)-5;
}
this._rotation += this.rotationSpeed;
this._x += (_root._xmouse-this._x)/60;
if (this.hitTest(hitTest_mc)) {
delete this.onEnterFrame;
leafFade(this);
} else if (this._y>600) {
delete this.onEnterFrame;
leafFade(this);
} else {
this._y += this.fallSpeed;
}
}
};
So the problem is, if two buttons are pressed quickly enough, it doesn’t have time to clear the interval and the leaves just repeatedly fall (It just repeats the leafFall2() function for most of the leaves). So I would think since the “leaf” variable will always be the same each time leafFall() function is called, then leaf.delay would overwrite itself when the function was called a second time, which would be the same as clearInterval… Relatively speaking… But that’s not the case.
So I’m wondering if there’s some way to make that work properly. I was thinking also perhaps of using a different way of creating a random timer, that would only run once, which would solve the problem altogether.
It’s a relatively small problem, but I’d like to fix it if possible.
Thanks a bunch,
iLan