Jump to content
Search Community

TimelineMax reverse callback problem

Farzanmc 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

Hi.
I declare

var cacTimeline;

as global variable.
I then use it like this in function1 for example :

function1 () {
     cacTimeline = new TimelineMax();
     cacTimeline.to($linePath,0.5,{height:300});
     ......
}

I then want to reverse it in function2 and have a onReverseComplete or some callback at the end. But for the sake of my app , I have to append this callback in function2 , not in the object declaration.

function2 () {
     cacTimeline.addCallback(callback_function_name,0);
     cacTimeline.reverse();
}

Fires the callback_function_name twice. One at the start of the tween , one at the end of the sequence.
 

function2 () {
     cacTimeline.addCallback(callback_function_name,cacTimeline.totalDuration());
     cacTimeline.reverse();
}

callback_function_name never fires.

 

Can anyone help me.

I'm new to this , maybe there is a better solution for this.

Link to comment
Share on other sites

I assume you meant something like this:

 

function function2() {
    cacTimeline.eventCallback("onReverseComplete", callback_function);
    cacTimeline.reverse();
}

If you just want to call a function at that time, you could use a simple delayedCall():

 

TweenLite.delayedCall(cacTimeline.time(), callback_function);
cacTimeline.reverse();

Another option is if you're using a TimelineMax, you can use a tweenTo() and add a callback like this:

 

cacTimeline.tweenTo(0, {onComplete:callback_function});

Lots of options :)

  • Like 2
Link to comment
Share on other sites

I don't believe it. It works like a charm.
I tested the 3 of them with sending parameters also. They all works just fine.
It's so look like OOP and I'm so happy to use it. Makes me feel I'm still on AS 3.0
Thank you Jack. you saved me tons of codes.
 
For any one else who may have the same problem , to complete this forum, I'll write the callbacks with Parameters.
 

function function2() {
    cacTimeline.eventCallback("onReverseComplete", callback_function);
    cacTimeline.eventCallback("onReverseCompleteParams", [parameter_value]);
    cacTimeline.reverse();
}
function2() {
     TweenLite.delayedCall(cacTimeline.time(), callback_function, [parameter_value]);
     cacTimeline.reverse();
}

function2() {
     cacTimeline.tweenTo(0, {onComplete:callback_function,onCompleteParams:[parameter_value]});
     cacTimeline.reverse();
}

And also for any one who has the same problem as me, you should not write the callback function with " () " , you just write the name of the function and the separately the parameters.

function callback_function(parameter) {
     // Do some stuff
}

// Right way to use the method.
cacTimeline.tweenTo(0, {onComplete:callback_function,onCompleteParams:[parameter_value]});

// Wrong way to use the method.
// Fires the function immediately at the runtime 
cacTimeline.tweenTo(0, {onComplete:callback_function(),onCompleteParams:[parameter_value]});
  • 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...