Jump to content
Search Community

remove tween automatically

frosty383 test
Moderator Tag

Recommended Posts

Hey!

 

I have something like this:

 

var thisMc = this as MovieClip;

var thisAnim = TweenLite.to(thisMc, T, {alpha:0, rotation:360, onComplete:function(){
   thisAnim.reverse();
}, onReverseComplete:function(){
   thisAnim.restart();
}});
 
And the movieclip doesn't exist in the next frame.
How can I remove the tween automatically when my SWF goes to the next frame?
Thank you!
Link to comment
Share on other sites

solved!

 

I added this into the root:

var btnClicked:Boolean = false;

 

function clickHandler(e:MouseEvent){

  btnClicked = true;

}

 

and now my tween looks like this

 

var thisAnim = TweenLite.to(thisMc, T, {alpha:0, rotation:360, onUpdate:function(){
    if(MovieClip(root).btnClicked) thisAnim.kill();
}, onComplete:function(){
    if(MovieClip(root).playBtnClicked) return;
    thisAnim.reverse();
}, onReverseComplete:function(){
    if(MovieClip(root).playBtnClicked)return;
    thisAnim.restart();
}});
 
It works ok so far... If there is a better way to do it, please help!
Thank you!
Link to comment
Share on other sites

I would much rather use clickHandler to kill the tween than use an onUpdate to repeatedly check (or any callback for that matter)

 

function clickHandler(e:MouseEvent){
  btnClicked = true;
  thisAnim.kill()
}
Link to comment
Share on other sites

  • 1 month later...

Hello, I have a problem replaying my simple animation, when I clicked the "Replay" button, a looping (repeat=-1) timelineMax which nested in my main timelineMax cannot be killed, and hence continue playing... my code simplified as below:

replayBTN.buttonMode=true;

replayBTN.addEventListener(MouseEvent.CLICK, replayOnce);
function replayOnce(event:MouseEvent):void
{    
loopingTL.kill(); // a timelineMax that nested in my main timelineMax, with repeat=-1, GOT ERROR >.<
main.totalProgress(0); //<<My main timelineMax
main.restart();
}

 

Thanks!!

Link to comment
Share on other sites

Thanks for the file. There are a few programming errors

 

 

 

function replayOnce(event:MouseEvent):void
{ 
greeting.kill(); // a looping timelineMax that nested in my main timelineMax, with repeat=-1, GOT ERROR >.<
}


function greeting():void {
var greeting = new TimelineMax({repeat:-1,repeatDelay:2});
greeting
.to(en, 2.5, {alpha:alphaValueOrig})
.to(en, 2.5, {alpha:alphaValueZero,delay:2.5})
}
issue 1: your greeting timeline is defined inside a function. this means that code in your replay function will not see it.

issue 2: you have a function named greeting AND a timeline named greeting. 

 

do something like this

var greetingTimeline:TimelineLite; // declare timeline var outside of functions and give it a name different than your function

function replayOnce(event:MouseEvent):void
{ 
greetingTimeline.kill(); 
}


var greetingTimeline = new TimelineMax({repeat:-1,repeatDelay:2});
greetingTimeline.to(en, 2.5, {alpha:alphaValueOrig})
.to(en, 2.5, {alpha:alphaValueZero,delay:2.5})
}
Link to comment
Share on other sites

you are still declaring greetingTimeline as a local variable inside the greeting() function

 

BAD

function greeting():void {
var greetingTimeline = new TimelineMax({repeat:-1,repeatDelay:2});
greetingTimeline
.to(en, 2.5, {alpha:alphaValueOrig})
.to(en, 2.5, {alpha:alphaValueZero,delay:2.5})
;
}
GOOD (don't use var)
function greeting():void {
greetingTimeline = new TimelineMax({repeat:-1,repeatDelay:2});
greetingTimeline
.to(en, 2.5, {alpha:alphaValueOrig})
.to(en, 2.5, {alpha:alphaValueZero,delay:2.5})
;
}
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...