0
votes

I have 2 movies (swf) which have to run from a single file.

Both of them have separate preloaders.

I load the first movie and stop it while it plays. For playing the second movie, i am using a timer. Timer has to run till it expires to move to the second movie.

This is the code.

var today:Date = new Date();

var currentTime = today.getTime();

var targetTime =  currentTime + 20000;


this.onEnterFrame = function()
{
//Determines how much time is left.  Note: Leaves time in milliseconds
var timeLeft = targetTime - currentTime;

if(timeLeft<0)
{

    gotoAndPlay(3);
    }

}

It gives a warning - Scene 1, Layer 'Actions', Frame 2, Line 15 Warning: 1090: Migration issue: The onEnterFrame is not triggered automatically by Flash Player at run time in ActionScript 3.0. You must first register this handler for the event using addEventListener ( 'enterFrame', callback_handler).

How to handle it?

1

1 Answers

0
votes

This is ActionScript 3, so AS2-style on-functions don't work anymore. Instead of using this:

this.onEnterFrame = function () {
    // code...
}

Use this:

this.addEventListener(Event.ENTER_FRAME, function (e:Event) {
    // code...
});

In AS3, the new event model replaces a lot of AS2's automatically-called functions, which turns out to be a good thing. Once you get used to the new syntax, it's considerably more robust than anything AS2 had to offer.

Even though that will fix the error, your code will still fail to do anything. There are multiple problems with the code itself, but really, you shouldn't be approaching it that way, anyway. Use the Timer class instead!

var timer:Timer = new Timer(20000, 1);
timer.addEventListener(TimerEvent.TIMER_COMPLETE, function (e:TimerEvent) {
    gotoAndPlay(3);
});
timer.start();