GreenSock


OverwriteManager - auto overwriting (and more) comes to the TweenLite family

Posted in Tweening by jack on the August 29th, 2008
Version 1.0, Updated 11/12/2008
  • Compatibility: AS2 and AS3 versions available
  • File Size added to published SWF: About 1Kb

Join Club GreenSock to get updates, bonus classes, and more

DESCRIPTION

OverwriteManager is included in all TweenLite/TweenFilterLite/TweenMax downloads and allows you to control how tweens with overlapping properties are handled. Without OverwriteManager, tweens of the same object are always completely overwritten unless you set overwrite:0 (previously overwrite:false which still works by the way). For example:

  1. TweenLite.to(mc, 1, {x:100, y:200});
  2. TweenLite.to(mc, 1, {alpha:0.5, delay:2}); //Without OverwriteManager, this tween immediately overwrites the previous one

So even though there are no overlapping properties in the previous example, the 2nd tween would overwrite the first. The primary reason for this has to do with speed and file size. But if you're willing to sacrifice a little speed and file size, OverwriteManager can work with the tweening classes to automatically sense when there are overlapping properties and then only overwrite the individual properties in the other tween(s). Don't worry, you'd probably never notice even a slight speed decrease unless hundreds of tweens are beginning simultaneously with overlapping properties.

I kept OverwriteManager as a separate, optional class primarily because of file size concerns. I know, you're probably thinking "what the heck? It's not even 1Kb! What's the big deal?". Well, there are thousands of developers using TweenLite because of its extremely small footprint and blistering speed. Even 1Kb would represent a 33% increase in file size, and some developers have no use for the capabilities of this class.

So OverwriteManager is an optional enhancement to TweenLite and TweenFilterLite, but it is automatically included with TweenMax without any additional steps required on your part. That also means that if you use TweenMax anywhere in your project, OverwriteManager will automatically get initted and will therefore affect TweenLite and TweenFilterLite, making their default mode "AUTO" instead of "ALL".

USAGE

OverwriteManager has four modes: NONE, ALL, AUTO, and CONCURRENT. Without OverwriteManager, TweenLite and TweenFilterLite only have access to the NONE and ALL modes. With OverwriteManager initted, however, you get access to them all. By default, OverwriteManager uses AUTO. Here's what they do:

  • NONE (0): No tweens are overwritten. This is the fastest mode, but you need to be careful not to create any tweens with overlapping properties, otherwise they'll conflict with each other.
  • ALL (1): Similar to the default behavior of TweenLite/TweenFilterLite/TweenMax where all tweens of the same object are completely overwritten immediately when the tween is created.
    1. TweenLite.to(mc, 1, {x:100, y:200});
    2. TweenLite.to(mc, 1, {x:300, delay:2}); //immediately overwrites the previous tween

  • AUTO (2): Searches for and overwrites only individual overlapping properties in tweens that are running at the time the tween begins.
    1. TweenLite.to(mc, 1, {x:100, y:200});
    2. TweenLite.to(mc, 1, {x:300}); //only overwrites the "x" property in the previous tween

  • CONCURRENT (3): Overwrites all tweens of the same object that are active at the time the tween begins.
    1. TweenLite.to(mc, 1, {x:100, y:200});
    2. TweenLite.to(mc, 1, {x:300, delay:2}); //does NOT overwrite the previous tween because the first tween will have finished by the time this one begins.

To add OverwriteManager's capabilities to TweenLite and TweenFilterLite, you must init() the class once (typically on the first frame of your file) like so:

  1. OverwriteManager.init();

You do NOT need to add this line if you're using TweenMax because it automatically does it internally.

EXAMPLES

To start OverwriteManager in AUTO mode (the default) and then do a simple TweenLite tween, simply do:

  1. import gs.*;
  2.  
  3. OverwriteManager.init(); //only do this once in your SWF
  4. TweenLite.to(mc, 2, {x:"300"});

You can also define overwrite behavior in individual tweens, like so:

  1. import gs.*;
  2.        
  3. OverwriteManager.init();
  4. TweenLite.to(mc, 2, {x:"300", y:"100"});
  5. TweenLite.to(mc, 1, {alpha:0.5, overwrite:1}); //or use the constant OverwriteManager.ALL
  6. TweenLite.to(mc, 3, {x:200, rotation:30, overwrite:2}); //or use the constant OverwriteManager.AUTO

But normally, you'll just control the overwriting directly through the OverwriteManager with its mode property, like this:

  1. import gs.*;
  2.  
  3. OverwriteManager.init(OverwriteManager.ALL);
  4.  
  5. //-OR-//
  6.  
  7. OverwriteManager.init();
  8. OverwriteManager.mode = OverwriteManager.ALL;

The mode can be changed anytime.

FAQ

  1. 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 gs.OverwriteManager; or import gs.*;
  2. 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:

    1. TweenMax.to(mc, 1, {x:100, overwrite:3}); //uses the CONCURRENT mode for this tween even if the OverwriteManager's mode is something different.

  3. 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 or NONE modes.
  4. Where do I get the OverwriteManager class?
    It's included in all of the TweenLite/TweenFilterLite/TweenMax downloads.

Need Help?

Feel free to e-mail me a question. Or post your question on the new forums. I'd highly recommend joining Club GreenSock to get prioritized access to my time in answering your question, and so that you receive updates and lots more. When you e-mail your question, please include a simplified FLA file (and any class files) that clearly demonstrates the problem and provide a brief explanation.

Author: Jack Doyle, (e-mail: jack -at- greensock.com)
Copyright 2008, GreenSock (This work is subject to the terms here.)

11 Responses to 'OverwriteManager - auto overwriting (and more) comes to the TweenLite family'

Subscribe to comments with RSS

  1. brandy said,

    on August 29th, 2008 at 8:30 am

    fantastic, thanks!

  2. AmerSoft said,

    on September 2nd, 2008 at 4:42 am

    You are really wonderful … you keep getting our respect… THANK YOU MAN

  3. Og2t said,

    on September 2nd, 2008 at 4:56 am

    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!

  4. John Webber said,

    on September 2nd, 2008 at 12:21 pm

    My fingers were sore from writing overwrite:false so often. Thanks buddy!

  5. Chris Kelley said,

    on September 5th, 2008 at 5:14 am

    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

  6. @ndre said,

    on September 5th, 2008 at 8:48 am

    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? :-)

  7. jack said,

    on September 5th, 2008 at 8:59 am

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

  8. @ndre said,

    on September 5th, 2008 at 9:06 am

    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. :-)

  9. Shadow_SB said,

    on September 6th, 2008 at 4:08 pm

    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

  10. jack said,

    on September 6th, 2008 at 4:29 pm

    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.

  11. chris said,

    on October 4th, 2008 at 7:55 am

    wow…
    you did an amazing job :) thx.. i donate 20 dolars

Leave a Reply