Jump to content
Search Community

[SOLVED] TweenMax.staggerTo... Last element of array starts tweening?

Lasercode test
Moderator Tag

Recommended Posts

Hey folks,

 

maybe it's that I am blind, or just an idiot, but how can I get the moment when the last element of the (staggerTo) array starts tweening? I tried getTweensOf and all kinds of workarounds, but I failed :(

 

My example:

TweenMax.staggerTo(stepArray, tweenSpeed, {alpha:1, scaleX:1.5, scaleY:1.5, dropShadowFilter:{blurX:15, blurY:15, distance:5, alpha:0.33}, ease:Cubic.easeInOut, onComplete:tweenScaleDown, onCompleteParams:["{self}"]}, stepStaggerAmount);

 

 

Sorry if that's a dumb question, but I tried stuff for hours now and cant get it.

 

TIA,

Lasercode

Link to comment
Share on other sites

Hi Lasercode,

 

Interesting challenge, not dumb at all. I don't think any tween is ever aware of its position in the Array that staggerTo creates. But you can analyze each tween's target and see if it is the same as the last item in the array of objects that you pass into staggerTo.

 

I tried to keep the code as general as possible, meaning it should work on any staggerTo and doesn't require attaching any additional data to the object's being tweened.

 

 

import com.greensock.*;

var mcs:Array = [mc1, mc2];

//use onstartParams to send a refrence to the individual tween and the array that its target belongs to
TweenMax.staggerTo(mcs, 1, {x:400, onstart:onstartHandler, onstartParams:["{self}", mcs]}, .5);

function onstartHandler(tween:TweenLite, array):void{
trace(tween.target);

//if the current tween's target is the last item in the array then do stuff
if(tween.target == array[array.length-1]){
trace("last tween has started");
tween.target.rotation = 45;
}
}

 

I've attached CS5 fla and swf (use your GSAP v12 files)

 

*note in the code above, onstart and onstartParams should have upper-case S. Forums have a little issue.

last_staggerTo_start_CS5.zip

Link to comment
Share on other sites

Here's one other idea that utilizes v12's eventCallback() method:

 

 

var mcs:Array = [mc1, mc2];

var tweens:Array = TweenMax.staggerTo(mcs, 1, {x:400}, .5);
tweens[tweens.length - 1].eventCallback("onstart", onstartHandler);

function onstartHandler():void {
trace("last tween started");
}

 

(note: for some silly reason, the forums software seems to be forcing the "S" in "onstart" to be lowercase in the examples above, but it should be uppercase)

  • Like 1
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.
×
×
  • Create New...