Groups | Blog | Home
all groups > flash actionscript > march 2004 >

flash actionscript : HELP! setInterval (interval variable)


r2b2lynn
3/27/2004 8:19:37 PM
dynamic setInterval?
---------------------------

I'm new with setInterval(). This is how mine is set up:
setInterval(dropCircle,interval);
Based on my if conditions, I'm essentially changing the value of the
variable [b]interval[/b].
Everything works, [b]BUT[/b] as the 2nd if condition is met, the variable
[b]interval[/b] doesn't change. interval still equals 1, and not 10.
Changing that variable, would result in a change of speed, (which is what
I'm trying to get).

How can I get that variable to change?
Do I have to use clearInterval() somewhere in my code?
This is hard. Please help.


if (_root.cir1._y < 100) {
interval = 1;
}
[b]if (_root.cir1._y > 100) {
interval = 10;
}[/b]
function dropCircle() {
_root.cir1._y += 1;
trace(_root.cir1._y);
updateAfterEvent();
}
setInterval(dropCircle,interval);
pazzoboy
3/27/2004 8:36:59 PM
this.onLoad=function(){
startInterval();
};
if (_root.cir1._y < 100) {interval = 1;}
if (_root.cir1._y > 100) {interval = 10;}
function dropCircle() {
_root.cir1._y += 1;
clearInterval(speedup);
startInterval();
}
function startInterval(){
speedup = setInterval(dropCircle,interval);
}
Doesn't look like you need the updateAfterEvent, so I deleted it.
r2b2lynn
3/27/2004 11:05:27 PM
Thanks for responding. You code looks better and works better too.
BUT FOR SOME REASON, I'M GETTING THE SAME RESULTS.
-the interval variable [b]doesn't change[/b] to 10, as it's suppose
to, once _y is > 100.

if (_root.cir1._y>100) {
interval = 10;
}
the variable interval value should change to 10.
for some dumb reason, it's still initially 1 (interval = 1).
No...it should be 10, not 1.

Why? why? Why?

pazzoboy
3/27/2004 11:29:45 PM
Curious...do you have a stop(); command in the frame where you're initially
setting interval to 1? If not, then every time flash plays that frame,
interval is reset to 1. Try putting interval=1 inside the this.onLoad
function. There is something resetting it.
r2b2lynn
3/27/2004 11:57:52 PM
Ha!!!!! pazzoboy!! YOU ARE RIGHT!!!
By putting the interval=1 with it's associated condition, etc. inside the
startInterval() (this.onLoad = function() {...), it worked!!!
I've been spending a great deal of time on that problem.
I ow you one. Thank you.
pazzoboy
3/28/2004 5:37:23 AM
No worries. Pay me back by paying it forward. If you know the answer, share it.

Pazzoboy
AddThis Social Bookmark Button