GTween v2.01 Released

GTween V2.01 is a minor update that adds support for AS3 events, allows multiple callbacks at the same position on a timeline, introduces a version property, and fixes a number of bugs reported by users. It also includes a SWC file with the distribution.

Here’s the full list of changes:

  • added GTween.version property. (thanks to Colin Moock for the request)

  • added .dispatchEvents and GTween.defaultDispatchEvents properties, so you can enable AS3 events. (thanks to Colin Moock for the request)

  • fixed a problem with tweens in a timeline initing at the wrong time, and added support for position values less than -delay. (thanks to Erik Blankinship for the bug report)

  • fixed a problem with tween values being set to NaN before the controlling timeline started playing. (thanks to Erik for the bug report)

  • added support for multiple callbacks at a single position to GTweenTimeline. (thanks to sharvey, edzis for the feature request)

  • fixed issue with callbacks being called again when a timeline completes. (thanks to edzis for the bug report)

Go to gskinner.com/libraries/gtween to get all the information and download the new release.

I’m planning to migrate the source code to a public repository early in the new year.

Grant Skinner

The "g" in gskinner. Also the "skinner".

@gskinner

38 Comments

  1. “Pause, reverse, and jump to the start or end of the full timeline as easily as you would with a single tween.”

    This appears to be misleading, because as far as I can tell you can’t actually reverse a GTween or a GTweenTimeline. You can set reflect to true, advance to the end of a timeline, and crank repeatCount up, but that’s not quite the same thing.

    My workaround is to create a GTweenTimeline and set paused to true in all cases. Then, when I want to play or reverse the timeline, I create a GTween that operates on the GTweenTimeline’s position property.

    TimelineMax handles this case a lot better — you can just call play() to go forward or reverse() to go backward — but my client’s legal team thinks the greensock corporate licensing terms are too loose and so that library is out of the question. I also like their .append() function for tweens in a timeline — it’s a handy shortcut so that one doesn’t have to hand-calculate tween insertion points.

    Besides this omission, I’m greatly enjoying your tweening library. It’s probably the best-documented and easiest-to-use MIT-licensed tween library out there.

  2. Cory – you’re right. That description is left from GTween v1, which did have a reverse function and a reversed property. I want to address this at some point to make it easy to work with. For now you can fake it by setting your repeatCount=2, reflect=true, and position=duration, then playing it. This will make it play the reverse portion of the reflect. A bit of a hack, but it should be easier than what you’re doing right now.

  3. hi,

    thx for this release,

    but i cann’t find timingMode in this release.

    where it gone?

  4. “adds support for AS3 events”, does that mean you´ve added backward compability?! That´s more then welcome it that´s the case. I have not been able to upgrade, since the new version would overwrite the old version and all the old projects using the GTween class would stop work when recompiling.

    Anyway, thanks for a great tweening engine! Fast and simple, as it should be 🙂

  5. I have some issues with GTween when I cast values on the proxy object.

    private function handleRedrawAnimationComplete( event : Event ) : void {

    event.target.proxy.x = int( event.target.proxy.x );

    event.target.proxy.y = int( event.target.proxy.y );

    }

    This retriggers the whole tween again and again, is that supposed to be?

  6. Ah yes of course it’s supposed to be. My bad, I need to cast on the effective target.

  7. I have high respect for the work you give to flash community. I actually try to find a fun entry to flash development and gtween discovery : I’d like to create some generative art.

    Do you think that as3 + gtween can be ok for generative art ? Are there some samples (art + code) to work on ?

    I discovered Context Free and learned its grammar just by ‘playing’ with existing samples, can I do the same with as3+gtween ?

    Thx for any hints.

  8. Is the reason for dropping event dispatching as the default because of the overhead of creating event objects on performance?

  9. Hi,

    I’ve been playing a little with GTween and proxy:

    Works quite nicely, but it seems the onComplete fires ‘prematurely’ (stop giggling ^^)

    example:

    var tween:GTween = new GTween( _target, 2 )

    tween.ease = Sine.easeInOut;

    tween.onComplete = myFunction();

    tween.proxy.x -= myValue;

    Now, if i trace myFunction(), the onComplete fires

    right after start, not after 2 sec. as expected.

    Am i missing something?

    Btw.:

    GTween(_target, 2, {x:myValue}, {ease:Sine.easeInOut, onComplete:myFunction});

    works as expected.

    Reason for me to use proxy: i want to dynamically add or substract from _targets position – i haven’t found how to tween positions relatively, not absolutely. Greensock offers {x:”value”} to move target relatively.

    Anyway: cheers for the good work! Many Thx! Martin

  10. bug found:

    TypeError: Error #1009: Cannot access a property or method of a null object reference.

    at com.gskinner.motion::GTween/deleteValue()[/Users/fljot/flash_as3_classes/com/gskinner/motion/GTween.as:565]

    at com.gskinner.motion::GTweener$/clearValues()[/Users/fljot/flash_as3_classes/com/gskinner/motion/GTweener.as:193]

    at com.gskinner.motion::GTweener$/add()[/Users/fljot/flash_as3_classes/com/gskinner/motion/GTweener.as:109]

    at com.gskinner.motion::GTweener$/to()[/Users/fljot/flash_as3_classes/com/gskinner/motion/GTweener.as:89]

    I have traced, looks like _rangeValues is null. Tweens were with with MotionBlurPluging… Error was appearing from time to time.. useful?

  11. I discovered a bug in the ColorAdjustPlugin class on line 109 it returns value, but instead I believe it should return NaN. Returning value causes an error on AS3 created Sprites when more than one color adjustment is applied. Ex: Applying both contrast and saturation. This error is caused by a value being returned and it then trying to set that property value and it does not exist.

    Switching this line to return NaN fixed this issue in my cases.

  12. Think I’ve found a bug (v2.01).

    I’m creating some tweens objects ready for setting values later on, but it seems once you instantiate a tween, it begins counting down and then fires the onComplete callback.

    For example, I would expect this to make the call on onComplete until after the setValue function is called, but it does:

    var assetTween : GTween = new GTween( asset, 0.25 );

    assetTween.onComplete = function ( g:GTween ) : void { trace(“Logo tweened”); };

  13. hi! i noticed that there’s no GTweenFilter in the new version. How do I tween filters then?

  14. I guess I am not sure how to use GTween plugins with release 2 for concurrent tweens. It seems that plugins operate on every instance of tween — do I understand that correctly? Or can I apply different plugins to different concurrent tweens?

  15. Is there a list of all parameters for the color adjust plugin?

    contrast works but I get an error with saturation and what are the other properties?

    ColorTransformPlugin.install();

    ColorAdjustPlugin.install();

    new GTween(renderer, 3, {contrast:-20, blueMultiplier:100}, {repeatCount:0, reflect:true});

  16. Erik – Plugins are enabled globally. They won’t affect a tween unless you are tweening one of their special properties, but you can disable them for a specific tween by changing properties on the tween’s pluginData object. For example, to disable the AutoHidePlugin for a tween set:

    myTween.pluginData.AutoHideEnabled = false;

    You can also change the default enabled state for a plugin by setting it like:

    AutoHidePlugin.enabled = false;

    See the documentation for each plugin for more information.

    Chris – The documentation for the plugin includes all the parameters, though I noticed that it lists “hue” twice instead of saturation. The package also includes a demo of the ColorAdjust plugin in use, including tweening saturation.

  17. Some of us like to mess with the amplitude and period of the Elastic equations. I added two public vars to GTween: amp:Number = 0; and period:Number = 0;

    line 451 of GTween:

    ratio = (duration == 0 && _position >= 0) ? 1 : ease(calculatedPosition/duration,0,1,1);

    replaced by:

    if (duration == 0 && _position >= 0)

    {

    ratio = 1;

    }

    else

    {

    if (amp > 0 || period > 0)

    ratio = ease(calculatedPosition/duration, 0, 1, 1, amp, period);

    else

    ratio = ease(calculatedPosition/duration,0,1,1);

    }

    The Elastic class has to be altered to accept amp and period as arguments, with default 1 and 0.3. The vars a and p in all equations become amp and period respectively. The ‘s’ becomes var newS:Number = period / 4;

    It works. Make it so?

  18. Is there a way to change values relatively? e.g. xBy or yBy?

  19. There seems to be a bug in GTween class:

    public function deleteValue(name:String):Boolean {

    delete(_rangeValues[name]);

    delete(_initValues[name]);

    return delete(_values[name]);

    }

    Try example when you have simple fade in/out on some component when mouse over/out

    mouse over:

    GTweener.add(new GTween(closeButton, 0.5, {alpha: 1});

    mouse out:

    GTweener.add(new GTween(closeButton, 0.5, {alpha: 0});

    than try to move mouse very fast in and out… you’ll get an null reference error in the function I pasted above on properties “_rangeValues” and “_initValues”. Please try to fix it before the new release! Thanks

    If I’m doing it wrong please provide me with a correct use case.

  20. I’ve made some other test and I figured out that the issue is present only when tweeing by using Gtweener. It’s ok when using only Gtween instance and not passing it to Gtweener.

  21. Luckily I got some time to start having looking at it. I extended the previous version (especially the updateProperty method) so that based on the type of value (ie. ColorTransform, Rectangle, Point, but also other custom VOs) could interpolate the value accordingly.

    Based on the new architecture I presume I should create plugins for those interpolations. I’m only concerned that those plugins are static, which means, for instance, that the property which will handle a different VOs should be consistent across the all application. Not very scalable I would say. Other option is to modify the “set position” method.

    What is your opinion/recommendation? And about the scalability of this plugin architecture?

    Best, chr

  22. mmm, also the interpolation start to start+range can be a problem on different property types. start to end is handier 🙁

  23. thanks to the callback feature, we can now consider using your lib in our project. Thanks for that, you rock.

  24. I’ve played with gtween and found a kind of bug :

    my tweens are interrupted when meeting other tweens.

    example :

    I hace a tween launched on mouseover

    myTween =new GTween(mySprite,2,{scaleX:3,scaleY:3,alpha:0}{reflect:true,repeatCount:2})

    If I mouseover before the end of this tween, mySprite get stuck.

    For example with a duration of 2 second and a relaunch at 1s, mySprite is now always at scale 3.

    I have tried with or without reflect/alpha/repeatCount,… whatever the tween, I have always the same issue (not going back to the initial mySprite). I have also tried resetValues with no success …

    Quite annoying.

    – if people have no time here to answer, could you please give a place (forum) where to ask …:)

  25. Niels Keetlaer March 11, 2010 at 1:34pm

    Hi Grant,

    I love the work do and am very happy with your GTween class which has already found numerous uses. A bit silly to get back here only to complain though… an earlier thank you would have been nice. Hopefully I can supply the fix as well, so I’m not all bad ;).

    I noticed that when using tweens with delays, the delays are ignored after the first time you use the proxy object. Now, I might not get the complete intricacies of your GTween class, but as I see it the problem lies in the ‘invalidate’ function on line 701:

    if (_position > 0) { _position = 0; }

    This resets the position to 0 instead of -delay, which is what the delay setter does. Perhaps there is a better place to fix this… but replacing the line with

    if (_position > -delay) { _position = -_delay; }

    does seem to work like a charm.

    Hope this helps, and thanks again,

    Niels

  26. Hello,

    I was thinking of switching from Tweener to GTween but there are two problems:

    – no “addCaller” method in GTween. It is possible to do something similar by tweennig on some random object but I wish there was a cleaner solution…

    – synchronization issue. It occurs when creating several tweens at the same time on different objects and with same the duration. The onComplete methods aren’t called in the same order as the order in which the tweens were created. I know this is a really minor issue, but in my situation, it causes problems that I don’t have with Tweener for example.

    (I also did the test with TweenLite, and the onComplete methods were called in the complete reverse order.)

    There is a lot of stuff that I find better in GTween (syntax , ease of use, plugins, speed, size, etc…), but I will have to stick with Tweener for now because of this synchronization problem.

    Impressive lib anyway, thank you for releasing it.

    Cheers,

    Yann

  27. X Enterprises April 25, 2010 at 7:11pm

    Hi, I’m making an audio player and I’m trying to fade out the sound when you pause it, so I have this:

    sTransform = new SoundTransform();

    resumeTime = channel.position;

    new GTween(sTransform, .8, {volume:0}, {ease:Linear.easeNone, onComplete:pauseSndCrsFdeCmplte});

    It doesn’t work. How would I get it to work?

    P.S. This is a great library. It works great for everything else. 😀

  28. Jovica Aleksic April 26, 2010 at 10:35am

    Still can’t find a proper example of how to tween text color with GTween….

    One might even ask for a TextColorPlugin… 🙂

  29. Jovica Aleksic May 6, 2010 at 4:25am

    Hello Grant!

    i have a question about cleaning up / destroying GTween instances.

    Since we are using callback methods instead of event listeners, how important is it to null out the references to the callback function when the GTWeen instance is supposed to be destroyed?

    Should we care about myTween.onComplete = null etc?

    Is there anything else you would recommend regarding cleanup/destruction of GTWeen instances (Except of stopping animation)?

    Or is it enough to null out the GTween instance itself like myTween=null?

    And thanks for the great library. You stay my personal AS-Hero 🙂

  30. Doc bug: The timingMode functionality has been replaced with useFrames, but some of the docs still mention timingMode.

  31. Hello!

    I think that

    public function get proxy():TargetProxy

    need to be

    public function get proxy():Object

    because TargetProxy is private class.

  32. I also would like to put a request in for a reverse() function. For UI’s where you open or close menus and the like, it sure is handy to just reverse() it when the user dismisses a menu before it is completely open (here in pseudocode):

    function openMenu():void {

    myTween = new GTween(menu, 1, { y: 100 });

    }

    function onCloseMenu():void {

    myTween.reverse();

    }

  33. Hey man,

    I’m getting a lot of these errors being flung at me..

    Error: Error #2105: The Proxy class does not implement nextNameIndex. It must be overridden by a subclass.

    at Error$/throwError()

    at flash.utils::Proxy/http://www.adobe.com/2006/actionscript/flash/proxy::nextNameIndex()

    at flash.external::ExternalInterface$/_getPropNames()

    at flash.external::ExternalInterface$/_objectToJS()

    at flash.external::ExternalInterface$/_toJS()

    at flash.external::ExternalInterface$/_objectToJS()

    at flash.external::ExternalInterface$/_toJS()

    at flash.external::ExternalInterface$/call()

    at Main/_carouselMoved()

    at com.gskinner.motion::GTween/set position()

    at com.gskinner.motion::GTween$/staticTick()

    I’m building with mxmlc (Version 4.0.0 build 14159) and it’s happening when I try to trace the method argument from an onComplete call.

  34. Hi, again!

    I found new error. Now in GTweener.

    Sometimes GTweener try clear values from not inited tween and Tween.deleteValue method throw error.

    Thanks

  35. I’m using GTween and I noticed that staticTick() is never unregistered, which means the SWF will always be using some CPU cycles every frame, even if there are no tweens in action. I’d like to keep CPU usage to a minimum in this case, so how about having staticTick() remove the event handler if there are no tweens? I have a proposed code change to GTween.as, how would you like it delivered?

  36. I wanted to create a gTween which made sure to have certain init values. I found there was no way to manually set the initial values of a tween. A good place to do this would be the onInit callback but it’s run after the initial values are set. So I updated the class to have a preInit callback as well. This is very useful functionality, if you would like to added to a later release, I would suggest mimicking the way TweenLite does it, and have onInit run before anything else, and onStart run after the tween has been initialized.

  37. There a slight mistake in the documentation for the ColorAdjustPlugin. It says: “hue”, and/or “hue” tween values. I’m guessing its supposed to say “hue”, and/or “saturation” tween values.

    http://gskinner.com/libraries/gtween/docs_v2_01/index.html?com/gskinner/motion/GTween.html&com/gskinner/motion/class-list.html

Leave a Reply

Your email address will not be published. Required fields are marked *