Jump to content
Search Community

Loop (check!) Reset Values (ah crap!) [SOLVED]

sondanz test
Moderator Tag

Recommended Posts

Awesome Engine! Awesome forums! However, after all the posts and examples, there are still some things I just can't figure out.

 

I've gotten this timeline to loop 3 times. But how do I put all my MCs back in their starting positions before each repeat? (I must use TimeLineLite for weight reasons).

 

// AS2 TimeLineLite

// import the tween engine
import com.greensock.*;
import com.greensock.easing.*;

// tracks how many times it has repeated
var cycles:Number = 0;

// define a function for repeating
function playAgain():Void {
if (cycles <= 2) {

// define the timeline
var timeline:TimelineLite = new TimelineLite();

// begin tweening
timeline.append(new TweenLite(box1,     		1, {_x:100, ease:Expo.easeOut}));
timeline.append(new TweenLite(box2,     		1, {_x:200, ease:Expo.easeOut}));
timeline.append(new TweenLite(box3,     		1, {_x:300, ease:Expo.easeOut}));
timeline.append(new TweenLite(box4,     		1, {_x:400, ease:Expo.easeOut, onComplete:playAgain}));

cycles += 1;
}
}

playAgain();

Link to comment
Share on other sites

I would define the timeline instance outside the playAgain function, and set it paused.

Then in the playAgain function I would just restart the timeline. Try this out:

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

var timeline:TimelineLite = new TimelineLite({onComplete:playAgain, paused:true});
timeline.append(new TweenLite(box1, 1, {_x:100, ease:Expo.easeOut}));
timeline.append(new TweenLite(box2, 1, {_x:200, ease:Expo.easeOut}));
timeline.append(new TweenLite(box3, 1, {_x:300, ease:Expo.easeOut}));
timeline.append(new TweenLite(box4, 1, {_x:400, ease:Expo.easeOut}));

var cycles:Number = 0;

function playAgain():Void
{
if (cycles <= 2)
{
	timeline.restart();
	cycles += 1;
}
}

playAgain();

Link to comment
Share on other sites

  • 4 weeks later...

Sorry for digging up this post again but can you use "timeline.restart();" only in a function? I tried to put it just after the last "timeline.append(new TweenLite(box4, 1, {_x:400, ease:Expo.easeOut}));" but it doesn't work. (I just want to make sure to understand and use it properly. :mrgreen: )

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