Jump to content
GreenSock

Search In
  • More options...
Find results that contain...
Find results in...
snowscarecrow

Looping problem TimelineLite, TimeLineLite and with function

Recommended Posts

Hi

 

I just cant get this to work,neither with TimeLineLite or TimelineMax, what am I doing wrong? I want it to loop - a couple of times or infinite.( replay -1, from what I've seen on the forums), It plays only once - and then stops.

This is my code

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


mc_01.stop();
mc_02.stop();
mc_01._alpha = 0;
mc_02._alpha = 0;


var myTween:TimelineLite = new TimelineLite({onComplete:repeatTimeline});
//var myTween:TimelineMax = new TimelineMax({repeat:2});
myTween.append(new TweenMax.to(mc_02, .3, {frameLabel:"endFrame", _alpha:100, ease:Cubic.easeIn, delay:3}));
myTween.append(new TweenMax.to(mc_01, .3, {frameLabel:"endFrame", _alpha:100, delay:2}));
myTween.append(new TweenMax.to(mc_02, .3, {frameLabel:"startFrame", _alpha:100, ease:Cubic.easeIn, delay:5}));
myTween.append(new TweenMax.to(mc_01, .3, {frameLabel:"startFrame", _alpha:100, delay:4}));


function repeatTimeline()
{
myTween.restart();
}

 

 

This is one way i found out to make it loop for small banners(example it youre making small banners with around 20 kb)

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


mc_01.stop();
mc_02.stop();
mc_01._alpha = 0;
mc_02._alpha = 0;
function myFunction()
{
var myTween:TimelineLite = new TimelineLite();
myTween.append(new TweenMax.to(mc_02, .3, {frameLabel:"endFrame", _alpha:100, ease:Cubic.easeIn, delay:3}));
myTween.append(new TweenMax.to(mc_01, .3, {frameLabel:"endFrame", _alpha:100, delay:2}));
myTween.append(new TweenMax.to(mc_02, .3, {frameLabel:"startFrame", _alpha:100, ease:Cubic.easeIn, delay:5}));
myTween.append(new TweenMax.to(mc_01, .3, {frameLabel:"startFrame", _alpha:100, delay:4, onComplete:myFunction}));
}


myFunction();

 

Thanks for any help on this

Link to comment
Share on other sites

from what I can see, your first code example should work fine.

 

I did a simple as2 test and had no problem getting a TimelineLite onComplete to restart the timeline.

 

import com.greensock.*;

var tl:TimelineLite = new TimelineLite({onComplete:done})
tl.append( TweenLite.to(a, 1, {_x:100}) );
tl.append( TweenLite.to(b, 1, {_x:300}) );

function done(){
trace("restart");
tl.restart();
}

 

the above repeated fine as expected and it doesn't look much different than yours.

 

are you using the latest version of the platform?

 

feel free to upload a zip of your files or a simplified example that can illustrate the problem (CS5 or earlier)

Link to comment
Share on other sites

tween_test.fla.zip

 

Heres the file. Zipped in mac.

 

Really appreciate the help, Im quite stuck on this...

 

I have the latest version of the platform.

Link to comment
Share on other sites

remove the "new" keyword when using a to() tween.

 

 

GOOD

new TweenMax(mc, 1, {x:100})

 

GOOD

TweenMax.to(mc, 1, {x:100})

 

BAD

new TweenMax.to(mc, 1, {x:100});

 

it appears your tweens weren't added to the timeline. I traced myTween's duration and it was 0. also noted that the onComplete was firing instantly.

remove the new and you should be good to go,

 

var myTween:TimelineLite = new TimelineLite({onComplete:repeatTimeline});



myTween.append( TweenMax.to(mc_02, .3, {frameLabel:"endFrame", _alpha:100, ease:Cubic.easeIn, delay:1}));
myTween.append( TweenMax.to(mc_01, .3, {frameLabel:"endFrame", _alpha:100, delay:1}));
myTween.append( TweenMax.to(mc_02, .3, {frameLabel:"startFrame", _alpha:100, ease:Cubic.easeIn, delay:1}));
myTween.append( TweenMax.to(mc_01, .3, {frameLabel:"startFrame", _alpha:100, delay:1}));
trace(myTween.duration);

function repeatTimeline()
{
trace("hello");
myTween.restart();
}

 

also note, you don't have to specify a delay when you append tweens, you could use the offset parameter. its a little less typing and you can also have a negative offset so that tweens overlap. its a bit more

flexible but your way is fine too.

 

myTween.append( TweenMax.to(mc_01, .3, {frameLabel:"startFrame", _alpha:100, delay:1}));

 

is the same as

 

myTween.append( TweenMax.to(mc_01, .3, {frameLabel:"startFrame", _alpha:100}), 1);

Link to comment
Share on other sites

:D Great!! :D

 

Now everything is a bit more clear for me, it works and I can move on experimenting with the code.

 

Thanks a lot Carl for explaining!

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