Click to See Complete Forum and Search --> : AS2.0 - For loops and Intervals


XTREEMMAK
12-04-2008, 03:58 PM
Hey guys,
I'm trying to create a fade in and fade out effect with just Action Script and I'm having a bit of trouble. I'm no Action Script expert but I was able to decode a few things to put some code together. This is basically what I'm trying to do:

on (rollOver) {

var myInterval = setInterval(FadeUp, 1000);
function FadeUp () {
for (i = 0; i < 30; i++) {
brightcounter +=1
clearInterval(myInterval);
setBrightness(FirstNews_btn,brightcounter);
trace(brightcounter);

}//End For Loop
}//End of Function

}//End

The brightness fuction is defined somewhere else so dont worry about that. The problem is between the for loop and the intervals. What it's doing is delaying the evaluation of the for loop for the interval seconds, rather than delaying each for loop evaluation by the interval second. How do I correct this?

So what it does is when you roll over something, it holds than evaluates the for loop. What I want it to do is roll over something, evaluate once, then wait by seconds defined, then evaluate again till i > 30.

infinityspiral
12-04-2008, 11:45 PM
The interval needs to be set and cleared inside the for loop. So instead the flow would be sometihng like this:

- start loop
- trigger evaluate function
- if parameters meet goal then stop/break/return otherwise(else) create an interval that triggers the evaluation function
- evaluation function adds an interation to the for loop before exiting
- end loop