Share Posted April 2, 2014 Hey guys, Just wondering if there is an easier way to first start a loop, then stop it. Let's start with this: //Single object loop function doTween():void { TweenLite.to(mc, 1, {rotation:"348", ease:Linear.easeNone, onComplete:doTween}); } doTween(); //Stop loop TweenLite.killTweensOf(mc); //Multiple object loop function doTween():void { TweenLite.to(mc_01, 1, {rotation:"348", ease:Linear.easeNone, onComplete:doTween}); TweenLite.to(mc_02, 1, {rotation:"348", ease:Linear.easeNone}); TweenLite.to(mc_03, 1, {rotation:"348", ease:Linear.easeNone}); } doTween(); //Stop loop TweenLite.killTweensOf(mc_01); TweenLite.killTweensOf(mc_02); TweenLite.killTweensOf(mc_03); If there are heaps of objects looping, is there an easier way to stop them all (like by stopping the function somehow)? Also in case 2, let's just say there is a grandfather clock swinging. You can't use the above method because it needs to go back and forth. function tilt_right() { TweenLite.to(mc, 1, {_rotation:30, onComplete:tilt_left, } ); } function tilt_left() { TweenLite.to(mc, 1, {_rotation:-30, onComplete:tilt_right, } ); } tilt_right(); Once I want it to stop looping, what code would I use? I could possibly use the killTweensOf method again, but if each function had heaps of tweens, it seems like a clunky way of doing it. Thanks guys, Rhys. Link to comment Share on other sites More sharing options...
Share Posted April 2, 2014 Hi and welcome to the GreenSock forums. Ideally, you would add all 3 tweens to a repeating TimelineMax like so: tl.to(mc1, 1, {x:550}) .to(mc2, 1, {x:550}, 0) .to(mc3, 1, {x:550}, 0) Here you can see a JavaScript version of this http://codepen.io/GreenSock/pen/ayimz/ The GSAP syntax is exactly the same except we're using DOM elements and not MovieClips. If you can't load TimelineMax for file size reasons, I'd suggest looking into TweenMax's getTweensOf() method. You can keep all objects that you are looping in an Array. You can then pass that Array into getTweensOf() to get an Array of all the tweens. Then loop through all the tweens and play() or pause() them as needed. Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now