Search code examples
javascriptgsap

Adding onComplete handler after TweenMax object created?


I want to add an onComplete handler after I create my TweenMax object but I can't find a way to do it. How would I go about this?

Just to clarify I do not want to do this:

TweenMax.to(obj, 0.5, { x: 100, onComplete: myFunc });

But instead I want to do something like this:

var tween = TweenMax.to(obj, 0.5, { x: 100 });
tween.onComplete = myFunc; //  Or however you do this...

Using TweenMax.set(obj, { onComplete: myFunc }); fires the event instantly. I think I have to dig into the TweenMax object to find the onComplete reference but I can't find it.

Any ideas?


Solution

  • Use eventCallback, like so

    var tween = TweenMax.to(obj, 0.5, { x: 100 });
    tween.eventCallback("onComplete", myFunc, ["param1","param2"]);
    

    I got it from here http://greensock.com/docs/#/HTML5/GSAP/TweenLite/eventCallback/