Jump to content
Search Community

stop a tween when leaving frame

mgason test
Moderator Tag

Recommended Posts

Hi,

I have a movieclip that has nothing in frame 1, then this in frame 2 with mc "text_mc"

TweenMax.to(text_mc, 1, {y:0, repeat:5, yoyo:true, onComplete:allDone});

function allDone():void{
trace("all done");
this.dispatchEvent(new Event("All Done"));
this.gotoAndStop(1);
}

stop();

if from elsewhere I send that movieclip back to frame 1 and stop before the end of the tween, how do I stop the tween running.

Although the text_mc is not there and does not move around the "All Done" event is still dispatched after 5 seconds.

 

well I think this is the case?

 

thanks Mark

Link to comment
Share on other sites

There are several ways to accomplish this:

 

1) kill() your tween whenever you want:

 

var tween:TweenMax = TweenMax.to(text_mc, 1, {y:0, repeat:5, yoyo:true, onComplete:allDone});
//then later...
tween.kill();

 

2) You can kill all the tweens of a particular object with TweenLite.killTweensOf():

 

TweenLite.killTweensOf(text_mc);

 

But obviously you'll need to make sure text_mc exists when you make that call (don't do it after you leave that frame)

 

3) This wouldn't be my first choice because you're allowing a tween to continue even though you no longer need it, but you could add conditional logic to your onComplete so that it won't run unless it's on frame 2 (or wherever):

 

function allDone():void{
  trace("all done");
  if (this.currentFrame == 2) {
     this.dispatchEvent(new Event("All Done"));
     this.gotoAndStop(1);
  }
}

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...