Jump to content
GreenSock

eco_bach

TimeLineMax callbacks not called

Recommended Posts

I have a TimeLineMax sequence defined thus

var tl=new TimelineMax({paused: true});

tl.append(TweenMax.to(f, _flipSpeed, {rotationY: 90 + _offset, visible: false, onComplete:doneRotateF,ease:Linear.easeNone}))

tl.append(TweenMax.to(b, 0, {alpha: 1, immediateRender: false}))

tl.append(TweenMax.to(b, _flipSpeed, {rotationY: 0, onComplete:doneRotateB, ease:Linear.easeNone}));

When I call it using

tl.tweenTo(_tl.duration());

the callbacks work, are called, but when I try to reverse it

tl.tweenTo(0);

the tweens work fine but the callbacks are NOT called. What gives?

Link to comment
Share on other sites

onComplete is not quite the same as inserting a callback after the end of a tween - it only fires when the tween completes, reaching its duration when playing forward. There is also an onReverseComplete for playing in reverse, but that is called when the reverse completes i.e. when the tweens time reaches 0. Be aware that .tweenTo() only tweens time and doesn't change the timelines reversed property, so even if you tween to a time in the past, it won't be technically reversed unless you set it.

 

In this situation, you might be better off adding the callback into the timeline itself, so it will be called in either direction.

var tl = new TimelineMax({paused: true});

tl.to(f, _flipSpeed, {rotationY: 90 + _offset, visible: false, ease:Linear.easeNone});

tl.call(doneRotateF); // "onComplete"

tl.set(b, {alpha: 1}); // timeline.set doesn't require immediateRender:false

tl.to(b, _flipSpeed, {rotationY: 0, ease:Linear.easeNone});

tl.call(doneRotateB); // "onComplete"

Also, if you're using GSAP v12, the append() function is deprecated in favour of the add() function, but you can also create your tweens directly on the timeline, which drastically improves the readability of your timeline code.

  • Like 1
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.
×