Jump to content
Search Community
Jonathan test
Moderator Tag

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

hello hello..

 

i know instead of using setInterval(), we can use delayedCall() for GSAP.. what would be the clearInterval() equivalent in GSAP.

 

In setInterval() when you declare it in a variable, returns an ID (unique identifier) which is used in clearInterval() to cancel the timer

var intervalID = window.setInterval(animate, 500);

// later called to cancel the timer
window.clearInterval(intervalID);

so my question is.. 

  • what is the equivalent in GSAP to cancel a specific delayedCall() instances... since if i use killAll()
//kill only delayedCalls
TweenMax.killAll(false, false, true, false);

it kills all delayed calls, but not just a specific delayedCall()..

 

I could use killDelayedCallsTo() which kills all of the delayedCalls to a particular function..

  • but is there a method to kill specific instances of delayedCalls that might have multiple delayedCall() being used, like when using clearInterval?
  • does delayedCall() return a unique identifier like setInterval() does to reference later for cancelling / killing?

Below i can use the following to cancel timers at different times due to the instances referenced with the setInterval() ..

var intervalID = window.setInterval(animate, 500),
    intervalID2 = window.setInterval(animate, 1000);

// later called to cancel timer 1
window.clearInterval(intervalID);

// called again later to cancel timer 2
window.clearInterval(intervalID2);
  • so what would be the equivalent to cancelling the delayedCall() on different instances like above using setInterval().. instead of cancelling all tweens associated with a function that you pass to killDelayedCallsTo() ?

let me know if i need to clarify more, and if the way im explaining my question is long winded? :P

Link to comment
Share on other sites

HI Jonathan,

 

I think TweenLite.killTweensOf() will do the trick

 

Kills all the tweens (or specific tweening properties) of a particular object or delayedCalls to a particular function. 
 
...
 
To kill all the delayedCalls that were created like TweenLite.delayedCall(5, myFunction);, you can simply call TweenLite.killTweensOf(myFunction); because delayedCalls are simply tweens that have their target and onComplete set to the same function (as well as a delay of course).

 

TweenLite.delayedCall(2, someFunction);
//to kill
TweenLite.killTweensOf(someFunction);
If you have remaining questions, just let us know.
  • Like 2
Link to comment
Share on other sites

Yup, delayedCall() returns a TweenLite instance.

 

delayedCall docs

 

delayedCall(delay:Number, callback:Function, params:Array = null, scope:* = null, useFrames:Boolean = false):TweenLite

 

...

 

Returns
TweenLite — TweenLite instance

 

 
 
So, since its a tween you could kill it by name:
var myDelayedCallback = TweenLite.delayedCall(2, someFunction);


myDelayedCalback.kill();
  • Like 1
Link to comment
Share on other sites

Also, just to clarify, TweenLite.delayedCall() is an analog to setTimeout(), not setInterval().

// setTimeout()
var timeout = TweenMax.delayedCall(2, function() {
  // do something once after 2 seconds
});
// setInterval()
var interval = new TimelineMax({ repeat: -1 }).call(function() {
  // do something every 2 seconds
}, null, null, 2);
...
interval.kill();
  • 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.
×
×
  • Create New...