Jump to content
GreenSock

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

Timeline.clear() not removing Callbacks

Warning: Please note

This thread was started before GSAP 3 was released. Some information, especially the syntax, may be out of date for GSAP 3. Please see the GSAP 3 migration guide and release notes for more information about how to update the code to GSAP 3's syntax. 

Recommended Posts

Hi,

 

just wanted to let you know that it seems that clear() on a timeline does not remove eventCallbacks. It doesn't matter if they are set by the constructor or afterwards with eventCallback('eventtype', function)

 

 

I'm using latest Chrome and the latest TweenMax & TimelineMax JS versions on Windows 8 (shouldn't matter)

 

 

just try the following:

 

 

var tl = new TimelineMax({onComplete: function() {console.log('complete');}});

tl.eventCallback('onComplete'); //returns function

tl.eventCallback('onReverseComplete', function() {console.log('reversed');});

tl.clear();

tl.eventCallback('onReverseComplete'); // still there
tl.eventCallback('onComplete'); // still there

 

Although eventCallbacks get not killed, the containing tweens and timelines are removed and the totalDuration is 0 afterwards.

 

 

 

Would be nice if someone could confirm that!

Link to comment
Share on other sites

Yes, that is correct (and intentional) - clear() is only supposed to remove all the child tweens/timelines, it is not supposed to destroy the callbacks associated with the timeline itself. Typically, when someone adds an onComplete/onUpdate/onStart/onRepeat to a timeline instance, they want it to happen regardless of specific child tweens that exist inside the timeline, so it would be pretty annoying if clear() wiped out all their event callbacks and they had to re-add them again.

 

You can, of course, delete callbacks by using the eventCallback() method and setting the callback to null, like:

 

myAnimation.eventCallback("onComplete", null);
myAnimation.eventCallback("onUpdate", null);
myAnimation.eventCallback("onStart", null);

  • Like 2
Link to comment
Share on other sites

Thank you for your quick response! Just read the docs before and I think I was kind of confused because it says 'Empties the timeline of all ... callbacks'.

 

But now I understand that custom callbacks are meant and not the internal ones (complete, reverseComplete etc.).

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.

×