Skip to main content
Known Participant
May 22, 2009
Answered

array with timer

  • May 22, 2009
  • 1 reply
  • 681 views

I've got this timer function worked out, but it is putting all four clips on the stage at once. I'd like each clip to come on one at a time. Could you tell me what I am doing wrong?

THANKS!

var timer:Timer = new Timer(1000);

timer.addEventListener(TimerEvent.TIMER, onTimer);

timer.start();

function onTimer(evt:TimerEvent):void {

for(i=0;i<arrCSnav.length;i++)

var enterTween:Tween = new GCSafeTween(arrCSnav, "x", Strong.easeOut, arrCSnav.x,arrCSnav.x+180,12,false);

timer.stop();

}

This topic has been closed for replies.
Correct answer Ned Murphy

You use the Timer to call the function, four times.  You have a counter that you use to keep track of how many times and for the array index.  The function tweens the array[counter] object, increments the counter, when the counter reaches all it needs to, the function stops the timer.

Timer(call function)

counter=0

function{

     Tween(array[counter])

     counter += 1

     if(counter == array.length) stop Timer

}

1 reply

Ned Murphy
Legend
May 22, 2009

Your for loop is the reason for that, loops don't wait for anything, so it's adding all four.  You need to have a separate counter variable and use that to increment for the function.  The function should only tween one object for each call. When the counter reaches all you need it to be, then you shut off the timer.

(I didn't notice your followup to other posting until just now)

Known Participant
May 22, 2009

Thanks so much for your quick response!

I'm confused, if i don't use a for loop, how can I run through the movie clips in the array?

Ned Murphy
Ned MurphyCorrect answer
Legend
May 22, 2009

You use the Timer to call the function, four times.  You have a counter that you use to keep track of how many times and for the array index.  The function tweens the array[counter] object, increments the counter, when the counter reaches all it needs to, the function stops the timer.

Timer(call function)

counter=0

function{

     Tween(array[counter])

     counter += 1

     if(counter == array.length) stop Timer

}