OverwriteManager – control how (and if and when) tweens get overwritten
- Version: 6.0, Updated 10/21/2009
- File size added to compressed SWF: About 1kb
Description
OverwriteManager resolves conflicts between tweens and controls if (and how) existing tweens of the same target are overwritten. Think of it as a referee or traffic cop for tweens. For example, let's say you have a button with ROLL_OVER and ROLL_OUT handlers that tween an object's alpha and the user rolls their mouse over/out/over/out quickly. Most likely, you'd want each new tween to overwrite the other immediately so that you don't end up with multiple tweens vying for control of the alpha property. That describes the ALL_IMMEDIATE mode which is the default mode of TweenLite when it is not used in conjunction with TweenMax, TimelineLite, or TimelineMax. This keeps things small and fast. However, it isn't ideal for setting up sequences because as soon as you create subsequent tweens of the same target in the sequence, the previous one gets overwritten. And what if you have a tween that is controling 3 properties and then you create another tween that only controls one of those properties? You may want the first tween to continue tweening the other 2 (non-overlapping) properties. This describes the AUTO mode which is the default whenever TweenMax, TimelineLite, or TimelineMax is used in your swf. OverwriteManager offers quite a few other modes to choose from in fact:
- NONE (0):
- When: Never
- Finds: Nothing
- Kills: Nothing
- Performance: Excellent
- Good for: When you know that your tweens won't conflict and you want maximum speed.
- ALL_IMMEDIATE (1):
- When: Immediately when the tween is created.
- Finds: All tweens of the same target (regardless of timing or overlapping properties).
- Kills: Every tween found
- Performance: Excellent
- Good for: When you want the tween to take priority over all other tweens of the same target, like on button rollovers/rollouts. However, this mode is bad for setting up sequences.
This is the default mode for TweenLite unless TweenMax, TimelineLite, or TimelineMax are used in the SWF (in which case AUTO is the default mode).
- AUTO (2):
- When: The first time the tween renders (you can invalidate() a tween to force it to re-init and run its overwriting routine again next time it renders)
- Finds: Only tweens of the same target that are active (running). Tweens that haven't started yet are immune.
- Kills: Only individual overlapping tweening properties. If all tweening properties have been overwritten, the entire tween will be killed as well.
- Performance: Very good when there aren't many overlapping tweens; fair when there are.
- Good for: Virtually all situations. This mode does the best job overall of handling overwriting in an intuitive way and is excellent for sequencing.
This is the default mode when TweenMax, TimelineLite, or TimelineMax is used in your swf (those classes automatically init() OverwriteManager in AUTO mode unless you have already initted OverwriteManager manually).
- CONCURRENT (3):
- When: The first time the tween renders (you can invalidate() a tween to force it
to re-init and run its overwriting routine again next time it renders) - Finds: Only tweens of the same target that are active (running). Tweens that haven't started yet are immune.
- Kills: Every tween found
- Performance: Very good
- Good for: When you want the target object to only be controled by one tween at a time. Good for sequencing although AUTO mode is typically better because it will only kill individual overlapping properties instead of entire tweens.
- When: The first time the tween renders (you can invalidate() a tween to force it
- ALL_ONSTART (4):
- When: The first time the tween renders (you can invalidate() a tween to force it to re-init and run its overwriting routine again next time it renders)
- Finds: All tweens of the same target (regardless of timing or overlapping properties).
- Kills: Every tween found
- Performance: Very good
- Good for: When you want a tween to take priority and wipe out all other tweens of the same target even if they start later. This mode is rarely used.
- PREEXISTING (5):
- When: The first time the tween renders (you can invalidate() a tween to force it to re-init and run its overwriting routine again next time it renders)
- Finds: Only the tweens of the same target that were created before this tween was created (regardless of timing or overlapping properties). Virtually identical to ALL_IMMEDIATE except that PREEXISTING doesn't run its overwriting routines until it renders for the first time, meaning that if it has a delay, other tweens won't be overwritten until the delay expires.
- Kills: Every tween found
- Performance: Very good
- Good for: When the order in which your code runs plays a critical role, like when tweens that you create later should always take precidence over previously created ones regardless of when they're scheduled to run. If ALL_IMMEDIATE is great except that you want to wait on overwriting until the tween begins, PREEXISTING is perfect.
With the exception of ALL_IMMEDIATE (which performs overwriting immediatly when the tween is created), all overwriting occurs when a tween renders for the first time. So if your tween has a delay of 1 second, it will not overwrite any tweens until that point.
You can define a default overwriting mode for all tweens using the OverwriteManager.init() method, like:
-
OverwriteManager.init(OverwriteManager.AUTO);
If you want to override the default mode in a particular tween, just use the overwrite special property. You can use the static constant or the corresponding number. The following two lines produce the same results:
-
TweenMax.to(mc, 1, {x:100, overwrite:OverwriteManager.PREXISTING});
-
TweenMax.to(mc, 1, {x:100, overwrite:5});
OverwriteManager is a separate, optional class for TweenLite primarily because of file size concerns. Without initting OverwriteManager, TweenLite can only recognize modes 0 and 1 (NONE and ALL_IMMEDIATE). However, TweenMax, TimelineLite, and TimelineMax automatically init() OverwriteManager in AUTO mode unless you have already initted OverwriteManager manually. You do not need to take any additional steps to use AUTO mode if you're using any of those classes somewhere in your project. Keep in mind too that setting the default OverwriteManager mode will affect TweenLite and TweenMax tweens. OverwriteManager has no effect on TweenNano tweens.
FAQ
- I'm trying to use the AUTO overwriting mode, but it's not working - what am I doing wrong?
You probably just forgot to call OverwriteManager.init() in your SWF. You only need to do that once by the way. And be sure you're using the latest version of tweening classes and that you imported the OverwriteManager class too, either with import com.greensock.OverwriteManager; or import com.greensock.*; - What if I set the mode to AUTO, but I have a tween that I'd like to use a different mode for - can I do that?
Of course. Just use the overwrite property in that tween, like:Actionscript:-
TweenMax.to(mc, 1, {x:100, overwrite:3}); //uses the CONCURRENT mode for this tween even if the OverwriteManager's mode is something different.
-
- Is there a big performance hit when using the AUTO mode?
Not really. Maybe if you're starting hundreds of simultaneous tweens with overlapping properties, but you'd probably never notice any difference whatsoever in typical use. If you want the absolute best speed, stick with the ALL_IMMEDIATE or NONE modes. - Where do I get the OverwriteManager class?
It's included in all of the tweening downloads. Just click the "Download AS2" or "Download AS3" button.
Need help?
Feel free to post your question on the forums. You'll increase your chances of getting a prompt answer if you provide a brief explanation and include a simplified FLA file (and any class files) that clearly demonstrates the problem.
Comments (12)

fantastic, thanks!
You are really wonderful … you keep getting our respect… THANK YOU MAN
This is great Jack! I had some many headaches with overwriting different properties on the same object without stopping/resetting others – that should solve it all now! Thanks!
My fingers were sore from writing overwrite:false so often. Thanks buddy!
Outstanding – I just loaded up the site to double check the documentation on the old overwrite:false stuff and look what you’ve gone and done! Saved me a big headache, -again-.
Thanks, keep up the good work.
Chris
Looks like a very welcome addition. Only thing I’m a bit sceptic about after reading the post, is the default setting. If I understand it correctly, the ALL mode is the way that TweenMax (since this is the only class where it is included by default, my concern only applies here) used to work before?
Then, since the default mode is AUTO now, backwards compability is not 100%. If I replace the old classes with the new ones, it could potentially create unwanted results when recompiling my previous projects because properties that I expected to be overwritten when creating a new tween, isn’t…
Or did I misunderstand?
@ndre, you are correct – since AUTO is now the default, there is a possibility that your old stuff won’t work exactly the same way. I weighed the decision to make the default mode AUTO and I realized backwards compatibility might be an issue at the default setting, but I decided to go with AUTO because:
1) It is the most intuitive and prevents confusion. I’ve gotten lots of “bug” reports that weren’t bugs at all – it was just that people expected auto overwriting and didn’t understand the old default behavior of overwriting ALL.
2) If you want to replicate the old default “ALL” mode, it’s super-easy. Simply call OverwriteManager.init(OverwriteManager.ALL); That’s it.
Basically, the benefits seemed to outweigh the risks. If anyone else wants to disagree or share their opinion, let me know. In the end, I think people expect (and are happiest with) the AUTO mode by default. Keep in mind you can control overwriting on an individual basis too – you don’t need to control it with the global OverwriteManager mode setting.
Ok, I mostly wanted to get confirmed that it worked the way I thought. I agree that the AUTO mode is the most intuitive, I remember being confused about the overwriting when I first started using TweenMax/Lite.
As long as I know about it, option 2) is no sweat at all.
Hi. I’m wondering about consequences of using NONE mode in cases that AUTO was made for… I suppose that this is not good idea but since NONE mode is more efficient it sounds seductive… Generally I don’t use thousands of simultenous tweens, but I do use TweenLite in cpu-stressful projects where performance matters
Shadow_SB, if you’re careful with the way you write your code, feel free to use the NONE mode. You can always use the overwrite special property in individual tweens to accomplish whatever you want. You might also want to do some testing of your own to see how NONE compares with AUTO because you may be very surprised how efficient AUTO mode is. Frankly, I noticed very little difference even when running hundreds of tweens simultaneously. But if you want absolutely maximum performance, NONE or ALL is best. In most projects, however, given the almost imperceptible performance difference and increased convenience, I suspect most developers will appreciate AUTO. The nice thing is that OverwriteManager gives you lots of options.
wow…
you did an amazing job
thx.. i donate 20 dolars
Jack, this is awesome. I’ve been trying for days to get a slow, smooth zoom effect, and I did it in seconds thanks to you.









