Jump to content
Search Community

onUpdate not firing in nested TimelineMax

gdub2 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 am having trouble getting onUpdate event to fire in a TimelineMax that I have nested inside of another TimelineMax. Basically i have a "master" timeline, and a bunch of different "section" timelines. The master timeline has its own onUpdate , but I would like the onUpdate for each of the different sections to call a different function. for example...

 

var master = new TimelineMax( {paused:true, onUpdate:masterUpdate});

 

var sec1 = new TimelineMax({paused:true, onUpdate:sec1Update});

var sec2 = new TimelineMax({paused:true, onUpdate:sec2Update});

 

master.add([sec1, sec2], "+=2", "stagger");

 

master.play();

 

The problem I am having is that sec1Update, and sec2Update are not getting called when their respective timelines are being played. Any help would be greatly appreciated. Thanks

 

Greg

Link to comment
Share on other sites

Hi,

 

Your problem is that your nested timelines are paused, so basically your master timeline is playing but the nested ones are still paused, change it to this:

var master = new TimelineMax( {paused:true, onUpdate:masterUpdate});

var sec1 = new TimelineMax({onUpdate:sec1Update});
var sec2 = new TimelineMax({onUpdate:sec2Update});

master.add([sec1, sec2], "+=2", "stagger");

master.play();

And it should work. Also i set up a fiddle in case you want to see a working sample.

 

http://jsfiddle.net/rhernando/KSdKe/

 

Hope this helps,

Cheers,

Rodrigo.

  • Like 2
Link to comment
Share on other sites

No problemo, glad to help.

 

Carl, Jack question:

 

I tried adding paused timelines inside an alive timeline and of course the parent timeline progresses but the nested ones were still paused, at the end the parent progress is 1 and the nested ones is 0. But if you un-pause the nested ones while the parent is playing, their progress starts at the parent progress and at the end all the progress values are 1.

 

When nesting alive tweens/timelines inside a paused timeline the parent force the nested ones to be paused, why it doesn't works the other way?.

 

Cheers,

Rodrigo.

Link to comment
Share on other sites

Try to visualize timelines like containers and each timeline has a virtual playhead. Every tween (and timeline) is placed on a timeline. As the parent timeline's playhead drags across the child tween/timeline, it updates that child's playhead accordingly. I tried to visually explain it in an old video here: http://www.greensock.com/timeline-basics/ as did Carl in his video series here: http://active.tutsplus.com/series/timelinelite-ultimate-starter-guide/ (note that the API has changed a bit from when those videos were posted, but the concept is identical)

 

When you pause() a timeline, that basically tells it to REFUSE to move its playhead. You're telling it you want it to stay put - the platform honors that even if you unpause its parent. 

 

The reason a child tween/timeline acts paused when the parent is paused is because it wouldn't make any sense otherwise - the parent's playhead isn't moving, so why would the child's? But again, if the parent's playhead moves to a new position and it encounters a child that is paused, it should NOT force that child's playhead to the new position because you told that child specifically to be paused. Otherwise, it'd be pretty frustrating to tell a certain tween/timeline to be paused and then have the system ignore that and move the playhead anyway just because the parent's playhead moved. 

 

Make more sense now?

  • 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...