TweenNano – 1.6k TweenLite with Some Sacrifices

  • Version: 1.05, Updated 2010-05-11
  • File size added to compressed SWF: About 1.6kb (AS3), or 2kb (AS2)

Check out v12 (beta)!
Version 12 of the animation platform is almost here. It’s in public beta now and we’d love to get your input. It is the most exciting release yet and it includes a JavaScript flavor. Check it out here and get your hands on the code today.

Description

TweenNano is a super-lightweight (1.6k in AS3 and 2k in AS2) version of TweenLite and is ideal for situations where you cannot afford the extra 3.1k (4.7k total) that the normal TweenLite engine would cost and your project doesn’t require any plugins. TweenNano can do everything TweenLite can do with the following exceptions:

  • No Plugins - One of the great things about TweenLite is that you can activate plugins in order to add features (like autoAlpha, tint, blurFilter, etc.). TweenNano, however, doesn’t work with plugins.
  • Incompatible with TimelineLite and TimelineMax - Complex sequencing and management of groups of tweens can be much easier with TimelineLite and TimelineMax, but TweenNano instances cannot be inserted into TimelineLite or TimelineMax instances. Sequencing in TweenNano can be done using the “delay” special property.
  • Fewer overwrite modes - You can either overwrite all or none of the existing tweens of the same object (overwrite:true or overwrite:false) in TweenNano. TweenLite, however, can use OverwriteManager to expand its capabilities and use modes like AUTO, CONCURRENT, PREEXISTING, and ALL_ONSTART (see http://www.greensock.com/overwritemanager/ for details).
  • Compared to TweenLite, TweenNano is missing the following methods/properties: pause(), play(), resume(), restart(), reverse(), invalidate(), onStart, defaultEase, easeParams, currentTime, startTime, totalTime, paused, reversed, and totalDuration. See the feature comparison chart for details about how TweenNano, TweenLite, and TweenMax compare.

TweenNano uses exactly the same syntax as TweenLite, so all the documentation and examples for TweenLite apply to TweenNano as well (except for the features mentioned above of course).

For a measly 1.6k, TweenNano is surprisingly capable. It can tween as many properties as you want of any object, base timing on frames or seconds, use onComplete and onUpdate callbacks, make delayedCall()s, do from() tweens, kill all the tweens of a particular object, and TweenNano easily outperforms most other engines including Adobe’s Tween class (by a wide margin).

Getting started

If you’re new to the GreenSock Tweening Platform, check out the “getting started” page. You’ll be up and running in no time.

Documentation

Please see the full ASDoc documentation.

Sample AS3 code

(AS2 is identical except for property names like “x”, “y”, and “alpha” are “_x”, “_y”, “_alpha” and alpha would be 100-based instead of 1-based).

import com.greensock.*;
import com.greensock.easing.*;

//tweens mc's alpha property to 0.5 and x property to 120 from wherever they are currently over the course of 1.5 seconds.
TweenNano.to(mc, 1.5, {alpha:0.5, x:120});

//same tween, but uses the Back.easeOut ease, delays the start time by 2 seconds, and calls the "onFinishTween" function when it completes, passing two parameters to it, 5 and "myParam2".
TweenNano.to(mc, 1.5, {alpha:0.5, x:120, ease:Back.easeOut, delay:2, onComplete:onFinishTween, onCompleteParams:[5, "myParam2"]});

//tweens mc into place from 100 pixels above wherever it currently is, over the course of 1 second using the Elastic.easeOut ease.
TweenNano.from(mc, 1, {y:"-100", ease:Elastic.easeOut});

FAQ

  1. Do you plan on eventually making TweenNano compatible with plugins?
    No. I am not interested in blurring the line between TweenNano and TweenLite by adding plugin capability or other features to TweenNano. The sole purpose of TweenNano is to provide an extremely lightweight engine capable of doing basic tweening, nothing more. If you want plugin-like capabilities, you can always use TweenNano’s onUpdate callback to have your own function perform any action every time the tween values are updated.
  2. I thought TweenLite was already lightweight. Why create TweenNano if it only saves 3.1k?
    Believe it or not, some developers (mostly banner ad creators) will rejoice at the thought of getting an extra 3.1k because they are forced to work within extremely tight file size constraints. That being said, if you’re trying to decide whether you should use TweenNano or TweenLite, I’d recommend using TweenLite and only shifting to using TweenNano if that 3.1k becomes critical. TweenLite is definitely more flexible with its plugins and compatibility with TimelineLite and TimelineMax.
  3. How do I install the class? Do I have to import it on every frame?
    Please refer to the “getting started” page.
  4. Why do my tweens keep getting overwritten? How can I prevent that?
    By default, when you create a tween, TweenNano looks for all existing tweens of the same object and kills them immediately. However, you can prevent this behavior by using overwrite:false in your vars object, like TweenNano.to(mc, 1, {x:100, overwrite:false});
  5. Can I set up a sequence of tweens so that they occur one after the other?
    Sure. Just use the “delay” special property, like :

    import com.greensock.TweenNano;
    TweenNano.to(mc, 2, {x:100});
    TweenNano.to(mc, 1, {y:300, delay:2, overwrite:false});
  6. Do the properties have to be in a specific order?
    Nope. The only thing that matters is that the first parameter is the object you’re tweening, the second parameter is the time (in seconds), and the third parameter contains all the properties you want to tween (in any order). So TweenNano.to(mc, 1, {scaleX:1.2, y:200, x:1}) is the same as TweenNano.to(mc, 1, {x:1, y:200, scaleX:1.2});
  7. Do I have to purchase a license to use this code? Can I use it for commercial purposes?
    You may use the code at no charge in commercial or non-commercial web sites, games, components, applications, and other software as long as end users are not charged a fee of any kind to use your product or gain access to it. If your client pays you a one-time fee to create the site/product, that’s perfectly fine and qualifies under the “no charge” license. If multiple end users are charged a usage/access/license fee of any kind, please simply sign up for a corporate Club GreenSock membership which comes with a special commercial license granting you permission to do so. Club GreenSock members get several useful bonus plugins, classes, update notifications, SVN access, and more. Your support keeps this project going. Please see the licensing page for details on licensing.

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.

Author: Jack Doyle, (e-mail: jack -at- greensock.com)
Copyright 2010, GreenSock (This work is subject to the terms here.)
  • Twitter
  • Facebook
  • Digg
  • StumbleUpon
  • del.icio.us
  • Yahoo! Buzz
  • Google Bookmarks
  • RSS
  • LinkedIn
  • Reddit

Comments (20) RSS

Posted by czebe on October 22, 2009

Wow Jack! we love TweenNano!
Will use it in every banner from now on…

Posted by Joe on October 22, 2009

Totally onboard with this release. Is great news. 3.1k can be all you need when you are developing a banner. Thanks again for creating an amazing product one more time.

Posted by Karl Macklin on October 22, 2009

This is awesome, great and excellent all at the same time!

Posted by Andrew on October 31, 2009

dude, about time! thanks for this. being a banner ad creator, an extra 3.1k can be like saving 1Gb. You truly are a king among men. Thanks a bunch.

Posted by Arold on November 5, 2009

Wow this is amazingly awesome. thanks for thinking about Ad & banner creators. TweenNano 100% GOOD and it uses the same syntax as TweenLite..

Bless Green Man, you rock…..

Posted by k-work on November 18, 2009

Rejoice! TweenNano just saved me from doing 25-life.

Posted by Urda on November 21, 2009

Thx Jack,
you managed to remove every last rest of possible reasons to not use your api in certain cases. I dont often make banners, but when i do, im thankful for every last kb.

Posted by John McLemore on February 20, 2010

Dude!!! Stop beating up Nano!! It’s pg reads like a “Why You Should Hate This!” It’s a 1.6′er and I work in advertising, so sometimes having this in a 40k environment freakin’ rox!
Be proud on the tools. Your eases are slicker than Penner’s and Flash’s combined AND those SICK code generating tools are amazing!!! Proud to use your stuff and hoping for a seminar or for SFSU to maybe recognize how often this is used and teach a class.
Seriously, I bounce from agency to agency around SF and EVRYONE knows and raves about TweenMax. I’m at Teak Motion Visuals on a gig and it was just assumed I knew TweenMax. LOVE IT! AS3 and TweenMax are the tools to know for todays pros!! Thanks, for the tiny solution!!!
And, Keep on crankin!!!!!! I can’t wait to see what I get to do next!
J

Posted by Louis Charland on March 3, 2010

You make my Year with Nano…thanks!

Posted by Jani S. on April 20, 2010

Oh wow this is good news!
Making banner ads suck a** but TweenNano eases the job a little bit. Actually, right now, I couldn’t get my work done without TweenNano. Thanks Jack!

Posted by ilfz on June 9, 2010

This rocks! Thanks!

Posted by Lil M. on August 4, 2010

Forever a fan of TweenMax, you, TweenNano have just saved my life. <3 Brightening up even the lowliest banner ads. THX!!

Posted by Dennis L on September 4, 2010

Love TweenLite! Use this in my Actionscript & Advanced Design Class. Students love it.

Posted by Alkashi on October 19, 2010

Many many many thanks for your job.
It’s just great :)

Posted by Ryno on March 14, 2011

Great job man! It works like a dream!

Posted by Emmanuel Ulloa on August 17, 2011

Hi! I created a tutorial on how to use filters and frame tweens using TweenNano. I think it might come handy for Flash Banner creators:

http://emmanuelulloa.blogspot.com/2011/08/using-tweennano-for-filters-and-frame.html

Posted by Kizzie Jarzembowski on November 17, 2011

Hello! My mate has recommended me to read your site. And I’d like to say that I really like what you’re providing here.

Posted by Mehdi Golzadeh on January 11, 2012

thanks friends … this library is the best one ever …

Posted by hoc thiet ke thoi trang on May 24, 2012

Thanks GreenSock. I am newbie in ActionScript

Posted by Joey Padasian on September 9, 2013

Woah, I just switched out my TweenLite for TweenNano, on a banner I’m developing. Now I’ve managed to change the image compression to 35% of the original to 60%.

Makes a world of difference for 40kb limit banners.

To download the code, you must agree to the following license:

"NO CHARGE" NON-EXCLUSIVE SOFTWARE LICENSE AGREEMENT
-----------------------------------------------------------------------------
PLAIN ENGLISH SUMMARY:

  1. You may use the code at no charge in commercial or non-commercial apps, web sites, games, components, and other software as long as end users are not charged a fee of any kind to use your product or gain access to any part of it. If your client pays you a one-time fee to create the site/product, that's perfectly fine and qualifies under the "no charge" license. If end users are charged a usage/access/license fee, please sign up for a "Business Green" Club GreenSock membership which comes with a comprehensive commercial license. See http://www.greensock.com/club/ for details.
  2. Use at your own risk. No warranties are offered.
  3. Please respect the copyright.

-----------------------------------------------------------------------------

LEGALESE:

This is a legal agreement between you (either an individual or a single entity) and GreenSock, Inc. ("GREENSOCK") for the proprietary GreenSock code known as TweenLite, TweenMax, TweenNano, TimelineLite, TimelineMax, and other copyrighted code that is available for download at http://www.greensock.com (this code and documentation, as well as any updates which may at GREENSOCK's sole discretion be provided to you from time to time, are referred to in this Agreement as "PROGRAM"). By downloading, copying, or otherwise using the PROGRAM, you agree to the terms and conditions of this Agreement. If you do not agree to the terms and conditions of this Agreement, please do not download or use the PROGRAM.

I. LICENSE
A. Subject to the terms and conditions of this Agreement, GREENSOCK hereby grants you a non-exclusive, worldwide, non-transferable right to use the PROGRAM in apps, web sites, games, components and other software applications ("Developed Works") for which the end user is NOT charged any fees. If you would like to use the code in a commercially licensed Developed Work for which end users are charged a fee (either for usage or access), simply sign up for the appropriate "Business Green" Club GreenSock membership at http://www.greensock.com/club/.

II. LIMITATION OF LICENSE AND RESTRICTIONS
A. You agree that you will not sell, rent, or license the PROGRAM's source code or any derivative works thereof to any third party without the prior written consent of GREENSOCK. Distribution of the PROGRAM as part of your Developed Work is acceptable so long as it is used exclusively as a part of your Developed Work. You agree not to modify or delete GREENSOCK'S existing copyright notices located in the source code.

B. You may use, duplicate, and distribute the compiled object code as embedded in Developed Works created by you, either for your own use or for distribution to a third party so long as end users of the Developed Work are not charged a fee for usage of or access to any portion of the Developed Work. Please see http://www.greensock.com/licensing/ for descriptions of Developed Works that qualify for the "No Charge" license.

C. You may make modifications to the source code exclusively for your own use in order to perform bug fixes or other minor edits required to operate the PROGRAM as originally intended.

III. CONSIDERATION
A. The license rights granted to you under this Agreement are at no charge, but only in the following circumstances: If on your own behalf or on behalf of a third party you incorporate the PROGRAM into a web site, app, game, program or any component thereof (collectively, "Developed Work"), which in the case of a web site, must be accessible to internet users without payment of a fee of any kind, and in the case of a software application, game, program or component, neither you nor anyone to whom you distribute the Developed Work charges a user a fee of any kind to use such Developed Work or application, game, program or component into which such Developed Work is embedded. The foregoing shall apply regardless of whether you are paid to create such Developed Work.

B. In the event your intended use of the PROGRAM does not meet the criteria for the "no charge" license rights set forth in the immediately preceding paragraph, then you are not licensed to use the PROGRAM under this Agreement and must license the PROGRAM under GREENSOCK'S separate fee-based Software License Agreement which is granted to "Business Green" Club GreenSock members (see http://www.greensock.com/club/ for details).

C. You may make modifications to the source code exclusively for your own use in order to perform bug fixes or other minor edits required to operate the PROGRAM as originally intended.

IV. TITLE AND OWNERSHIP
A. The PROGRAM is licensed, not sold, and is protected by copyright laws and international treaty provisions. You acknowledge that no title to the intellectual property in the PROGRAM is transferred to you. You further acknowledge that title and full ownership rights to the PROGRAM, including all intellectual property rights therein, will remain the exclusive property of GREENSOCK and you will not acquire any rights to the PROGRAM except as expressly set forth in this Agreement. You agree that any copies of the PROGRAM you make will contain the same proprietary notices which appear on and in the PROGRAM. You agree that GREENSOCK may identify you as a licensee unless you make a written request otherwise. GREENSOCK hereby grants to you the right to disclose that your product, game, software application, component, or other Developed Work makes use of GREENSOCK code (for example, "Powered by TweenLite").

V. DISCLAIMER OF WARRANTY AND LIMITATION OF LIABILITY
A. THE PROGRAM IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. GREENSOCK DOES NOT WARRANT THAT THE FUNCTIONS CONTAINED IN THE PROGRAM WILL MEET YOUR REQUIREMENTS OR THAT OPERATION WILL BE UNINTERRUPTED OR ERROR FREE. GREENSOCK shall not be liable for special, indirect, incidental, or consequential damages with respect to any claim on account of or arising from this Agreement or use of the PROGRAM, even if GREENSOCK has been or is hereafter advised of the possibility of such damages. Because some states do not allow certain exclusions or limitations on implied warranties or of liability for consequential or incidental damages, the above exclusions may not apply to you. In no event, however, will GREENSOCK be liable to you, under any theory of recovery, in an amount in excess of $250. Notwithstanding anything else in this agreement, you agree to indemnify GREENSOCK, its assignees, and licensees, and hold each of them harmless from and against any and all claims, losses, damages, and expenses, including legal fees arising out of or resulting from any negligent act or omission by you.

B. GREENSOCK may, at its sole discretion, provide support services related to the PROGRAM, but has no obligation to do so.

VI. TERMINATION
If you at any time fail to abide by the terms of this Agreement, GREENSOCK shall have the right to immediately terminate the license granted herein and pursue any other legal or equitable remedies available.

VII. MISCELLANEOUS
A. This Agreement shall be construed in accordance with the laws of the State of Illinois. In the event of any dispute between you and GREENSOCK with respect to this Agreement, we both agree that if we cannot resolve the dispute in good faith discussion, either of us may submit the dispute for resolution to arbitration with the American Arbitration Association before a single arbitrator using the AAA Rules for Commercial Arbitration. The arbitrator's decision is final and can be enforced in any court with jurisdiction over such matters.

B. This agreement represents the complete and exclusive statement of the agreement between GREENSOCK and you and supersedes all prior agreements, proposals, representations and other communications, verbal or written, between them with respect to use of the program. This agreement may be modified only with the mutual written approval of authorized representatives of the parties.

C. The terms and conditions of this Agreement shall prevail notwithstanding any different, conflicting, or additional terms or conditions which may appear in any purchase order or other document submitted by you. You agree that such additional or inconsistent terms are deemed rejected by GREENSOCK.

D. GREENSOCK and you agree that any xerographically or electronically reproduced copy of this Agreement shall have the same legal force and effect as any copy bearing original signatures of the parties.

Copyright 2006-2013, GreenSock, Inc. Updated 2012-08-28

I'd like to learn how to get bonus plugins, update notifications, SVN access, and more.
To continue, you must agree to the following license: