Jump to content
Search Community

reverse and then loop - newbie

lister110 test
Moderator Tag

Recommended Posts

Hi,

 

Just want to say, how much fun I had playing around with this..

All I want to do is reverse my tweens on complete and then goto and play from the beginning.

I cant figure out how I restart the movie after the reverse.

 

I did have gotoAndPlay in myFunction function and it looped ok. But I want to reverse and play again. I hope this makes sense, as i'm a bit of a newbie

 

import com.greensock.*;
import com.greensock.easing.*;

var timeline:TimelineLite = new TimelineLite({onComplete:myFunction});
timeline.append(TweenLite.to(mc1, .5, {x:"-600",  ease:Back.easeOut}), 2);
timeline.append(TweenLite.to(mc2, .5, {x:"-550",  ease:Back.easeOut}), 2);
timeline.append(TweenLite.to(mc3, .5, {x:"-500", ease:Back.easeOut}), 2);
timeline.insertMultiple(TweenMax.allTo([mc1, mc2, mc3], 2, {y:"-200"}), timeline.duration );

function myFunction():void {	
timeline.reverse();
}

 

 

lister

Link to comment
Share on other sites

The simplest way would just be to use TimelineMax instead of TimelineLite because it has a "repeat" and "yoyo" functionality. So your code would look like this:

 

import com.greensock.*;
import com.greensock.easing.*;

var timeline:TimelineMax = new TimelineMax({repeat:2, yoyo:true});
timeline.append(TweenLite.to(mc1, .5, {x:"-600",  ease:Back.easeOut}), 2);
timeline.append(TweenLite.to(mc2, .5, {x:"-550",  ease:Back.easeOut}), 2);
timeline.append(TweenLite.to(mc3, .5, {x:"-500", ease:Back.easeOut}), 2);
timeline.insertMultiple(TweenMax.allTo([mc1, mc2, mc3], 2, {y:"-200"}), timeline.duration );

 

That'll repeat the TimelineMax twice - the first time will go backwards and the second time will go forwards (hence the "yoyo:true"). If you want it to go back and forth forever, just set repeat:-1

Link to comment
Share on other sites

If you want the absolute lightest weight file, then you should shift to using TweenLite instead of TweenMax and TimelineLite instead of TimelineMax, but there's a price to pay in terms of conveniences. The whole point of TweenMax and TimelineMax is to add features that make your life easier as a developer. So you need to decide what the priorities are in your particular situation. The code you posted would roughly double in length if you shift to the "Lite" versions because you can't use "repeat" and "yoyo" and you'd need to manually loop through your array and create each tween instead of using the TweenMax.allTo() call. See what I mean?

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...