Jump to content


how to use a TimelineLite/Max as a simple group of tweens (when sequence is irrelevant)

Recommended Posts

Say you have a bunch of user-initiated events coming in, and they each trigger some tweens on a panel. Your panel has a border around it with its own independent tweens (say, the border is continuously pulsing), and a button on the border that stops all the tweens on the panel (say, by switching to a different panel while leaving the border unaffected.) Maybe the border has another button that pauses/resumes all the tweens on the panel.


So you want a way to keep track of all the user-initiated panel-tweens so you can stop or pause/resume them all when the border-button is clicked. You don't want to use TweenMax.killAll/pauseAll because you want to leave the border-tweens unaffected (the border is still pulsing.) Should you add all the panel-tweens to a TimelineLite/Max instance, or just keep the panel-tweens in an Array? The timeline would be convenient, because you could call timeline.kill/pause instead of iterating through the Array and killing/pausing all the panel-tweens individually. I guess you'd call


timeline.insert(newTween, timeline.time);


Is there a better way to handle this use-case?


Also, neither an Array nor a timeline is really ideal for this use-case, because both will accumulate references to dead tweens which have long since completed and will not be played again. Ideally, you'd store the tweens in something like the master-list used internally by GSAP (like a sub-master-list), so that you could kill/pause them all with one function call, but once they completed, they'd be marked as eligible for garbage collection (in the GSAP sense, not the AVM2 sense of course) and removed from the list. Does this make sense?

Link to comment
Share on other sites

Timelines have a special property in the constructor vars:

autoRemoveChildren : Boolean - If autoRemoveChildren is set to true, as soon as child tweens/timelines complete, they will automatically get killed/removed. This is normally undesireable because it prevents going backwards in time (like if you want to reverse() or set the progress lower, etc.). It can, however, improve speed and memory management. The root timelines use autoRemoveChildren:true.


That should cover your garbage collection concerns, yes?

Link to comment
Share on other sites

Yes. :) Thank you, I didn't realize autoRemoveChildren existed.


Maybe in trying to make my example concrete, I've made it too verbose. This is a use-case other people run into, right? Using a TimelineLite/Max as a container for tweens so you can operate on them en masse (without operating on all the tweens in the swf), but you don't care about their timing relative to each other?

Link to comment
Share on other sites

Sorry I should have clarifiied, I think your solution of using a timeline to group them seems good, once you add the autoRemoveChildren for garbage collection. Are you having trouble getting it to work?

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