PDA

View Full Version : Timer not working


StealingVision
11-08-2008, 10:14 PM
I'm trying to make a simple splash screen with my logo animation before the real animation starts. I don't want to add more frames so I made the animation into a movie clip with the stop(); function at the end. This is the code I put in the main timeline on frame 1

stop();

var nextTimer:Timer = new Timer(5000);
var preloader = new Preloader();
addChild(preloader);
preloader.x = 360;
preloader.y = 240;

stage.addEventListener(TimerEvent.TIMER, playFrame);

function playFrame(e:TimerEvent):void
{
gotoAndPlay(nextFrame);
removeChild(preloader);
}

nextTimer.start();

I get no errors and the preloader works gets added and plays just fine (it's not really a preloader, it's the name of my animation) but the timer never sets off the function. Any idea what's going wrong?

alpsoy
11-09-2008, 11:08 PM
You have to addEventlistener to nextTimer.

But in this case as you have not defined a repeatCount, it will be 0 by default which means the timer will run forever until you stop the timer. So your animation will try to go nextFrame every 5 seconds.

So you have to stop the animation manually when you are done or define the repeatCount like :

new Timer(5000, 1)

to make your timer dispatch the event once and stop.

And you better removeEventListener when you are done. And set the nextTimer to null.