Todd Todd - 2 months ago 23
Javascript Question

Delaying CreateJS Animation Timeline

I'd been using Swiffy to output .fla files pretty easily, but then I was tipped off that the display would alternate "flashing" white over half the project if viewed in Landscape Mode on a iPad. Very strange behavior, which I couldn't replicate on any other device.

So, I've moved on to trying to use CreateJS to fix the issue. I only know enough JS at this time to get by editing code developed by others, so I've been very ineffective so far.

I've gotten this far:

/* js
this.stop();
var t=setTimeout(function(){(this.play())}, 1000);
*/

or

/* js
this.stop();
setTimeout(this.play(), 1000);
*/


I've not been able to get the animation to mind the timeout, and I've tried MANY different variants to try and make some magic happen. All it does is immediately loads the next frame, it doesn't pause at all. Where am I going wrong here?

Here is the original Actionscript:

stop();

var shortTimer:Timer=new Timer(1000);
shortTimer.addEventListener(TimerEvent.TIMER, timerN1);
shortTimer.start();


function timerN1(e:TimerEvent):void{
play();
shortTimer.reset();
}


Any help would be very appreciated, as I've gotten no where on my own trying to fix this is in my off time for several weeks, and my client is becoming increasingly angry. More of a designer, still very uneducated as far as programming is concerned. Again, even a suggestion would be super helpful at this point. Can't seem to crack it.

Answer

This syntax is more correct:


/* js
this.stop();
var t=setTimeout(function(){(this.play())}, 1000);
*/

However, you may find that "this" is Window, not the MovieClip that calls it. You can get around this by using a local reference (in this case, its "_this").


/* js
this.stop();
var _this = this;
var t=setTimeout(function(){
    console.log(this, _this);
    _this.play();
}, 1000);
*/

You can test this by looking at your console, and seeing what the difference between "this" and "_this" is.

Cheers.

Comments