0

I created a looping tween using Greensock javascript and I got it to loop using a function, maybe this is not the best way to loop, if you know a better way please advice, but basically when I try to kill the tween using this method, it doesn't work.

My code:

var dvdTween;
function playDVD()
{
 dvdTween = TweenMax.to($("#bigDVD"), 4, {css:{rotation:+1440, transformOrigin:"150px 150px"},ease:Expo.easeNone, delay:7, onComplete:playDVD});
}

/// Later in a function I call

dvdTween.kill(); /// but this does nothing. 

Again, there may be a better way to loop a tween, and this may be my issue, but as of now this tween keeps on calling the function after I "kill" it.

Thanks for your tips and help.

Papa De Beau
  • 3,744
  • 18
  • 79
  • 137

1 Answers1

6

Your code should indeed work - I'd love to see an example set of files that shows it not working. I wonder if you're running into a scope issue or something - are you sure "dvdTween" is referencing the tween in the context you're calling it? Try adding onCompleteScope:this to your tween.

Two other tips:

1) You can loop a TweenMax infinitely by setting repeat:-1, like:

TweenMax.to($("#bigDVD"), 4, {css:{rotation:1440}, repeat:-1}); 

2) You can kill all the tweens of a particular object using TweenMax.killTweensOf() like:

TweenMax.killTweensOf($("#bigDVD"));
Jack
  • 2,930
  • 17
  • 13
  • Hi Jack! haha :) Thanks so much for the awesome response. I will try to be brief. My code worked but it kept calling the onComplete even after I killed the tween. I tried your method and it works but I can't get the tween to delay. Also when the functions keeps on calling it calls bigDVD but that is a loaded div. If they go to a new page the div is not there and it causes all javascript to stop working. That is why I was trying to kill the tween, but again the onComplete kept on going, thus restarting the tween again. Would you like me to post my code? It's long and messy :( but works :) – Papa De Beau Dec 05 '12 at 23:49
  • Yeah, I'd recommend creating a separate, isolated (simplified) example file because often times that will help identify the problem. Feel free to post your file over in the GreenSock forums at http://forums.greensock.com. – Jack Dec 06 '12 at 08:44