-
setInterval in a Button
yo yo,
I have a set interval on a button like this....
Code:
on (rollOver) {
fadeOutAction = setInterval(_root.fadeOut('quality'), 10);
}
the function it calls fades the target mc out... Unfortunatly when I roll over the button, the setInterval is only executed once, and not over and over every 10mS like it should.
I know it's nothing to do with the fucnction, as calling the setInterval from anywhere else produces the right results.
Anyone else experianced this problem or know how to fix it?
Cheers!!
-
What is your code for the set interval function as the rollover method should work fine?
-
I know what you have done, you have not used the object interval method.....
Code:
// replace your function to be executed with this...
fadeOut = new Object();
fadeOut.interval = function(qualityVar) {
// insert your current functions code in here!
}
// the code on your button is...
on (rollOver) {
fadeOutAction = setInterval(_root.fadeOut,"interval", 10, quality);
}
** edited to be named more like what you are using already
*** error corrected is in bold
-
interval? is that mx 2004?
i'm using mx...
Just been looking at your site... very nice! Like the artwork.
-
thanks Jon,
it should work fine in MX, its all AS1.
A side note though, if you roll over your mouse, roll out and then roll over again before the first set interval has completed, then you will get 2 instances of the same set interval function being run.
So you will probably want to set a variable somewhere to determine whether the set interval function is already running or not before executing it.
e.g.
Code:
// where buttonMC is the movieclip containg the button
fadeOut = new Object();
fadeOut.interval = function(qualityVar) {
stopInterval = true;
buttonMC._alpha-=10;
if (buttonMC._alpha == 0)
clearInterval(buttonMC.fadeOutAction);
stopInterval = false;
}
}
// the code on your button is...
on (rollOver) {
if (!_root.stopInterval){
fadeOutAction = setInterval(_root.fadeOut,"interval", 10, quality);
}
}
Please note that there was a mistake in the code I posted in previous post. the line should have read.
fadeOutAction = setInterval(_root.fadeOut,"interval", 10, quality);
-
yeah, this worked a treat! cheers!