Jump to content
GreenSock

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

Nesting timelines within timelines: the state of 'play'

Recommended Posts

I know that when you nest timelines within timelines, you need to have the child-timelines be 'playable', that is not have paused == true.

 

I'm creating complex timeline(maxe)s within separate functions and then adding them to the main timeline.  This seems to work, but I feel uneasy — I don't know how the child timelines 'know' to remain paused until they are added to the main timeline.  I believe I read here on the forums that a timeline will wait until the next enter-frame to start -- but how do I really know when that is?

 

Thus, in pseudo code, I have something like this

_mainTimeline = new TimelineMax({paused:true});
createChildTimelineOne();// not paused
createChildTimelineTwo();// not paused

_mainTimeline.append(_childTimelineOne);
_mainTimeline.append(_childTimelineTwo);

/// ... and so on...///

_mainTImeline.play();

Why//how do I know this will always work?  

 

 

Link to comment
Share on other sites

Actionscript is not multi-threaded (unless you are using Workers) so all currently executing Actionscript must be completed in full before the next enter frame event will fire. This is why doing things like running long, complicated loops can cause the UI to stutter or hang.

 

As long as you aren't waiting for an event in between creating the child timeline and appending it, you can rest easy that it's all happening on one frame.

  • Like 2
Link to comment
Share on other sites

Yep, Jamie is exactly right. And just for the record, there are 3 other ways you can handle this if you're building things in a way that may allow an ENTER_FRAME event to elapse before you append()/add() the timelines to the master one...

 

(all of the following code assumes you're using v12...)

 

1) create them as paused initially, then unpause them as you append them:

//calling play() simply unpauses them, but if _mainTimeline is paused, they won't actually play since the parent timeline's playhead isn't moving.
_mainTimeline.add( _childTimelineOne.play() );
_mainTimeline.add( _childTimelineTwo.play() );

2) add them to a temporary paused timeline, and then when you're ready, drop them into the "real" main timeline. Since they can only have one parent, when you add them to another timeline they're automatically removed from the previous one.

var temp:TimelineLite = new TimelineLite({paused:true});
temp.add( _childTimelineOne );
temp.add( _childTimelineTwo );

//then later...
_mainTimeline.add( _childTimelineOne );
_mainTimeline.add( _childTimelineTwo );

3) create the child timelines as paused, populate the main timeline however you please, and then when it comes time to play() the main timeline, you could getChildren(), loop through that array and unpause each one. 

 

I hope all these options didn't add to the confusion. In general, you don't need to employ any of these, as Jamie said. 

  • Like 1
Link to comment
Share on other sites

Thanks, both answers quite helpful!

 

On thinking about it, it might be nice to have a utility function that accomplished method '3' above -- sort of TimelineMax.playAllChildren() or something.

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