Jump to content
Search Community

find out total duration of a couple of tweens

tean test
Moderator Tag

Recommended Posts

if I have couple of tweens with random delays, could I found out how long are they going to last (or the one that is going to last the longest) so I can set that time to another tween?

 

	
TweenLite.to(mc1, time, {x: num, delay: Math.random() });
TweenLite.to(mc2, time, {x: num, delay: Math.random() });
TweenLite.to(mc3, time, {x: num, delay: Math.random() });
TweenLite.to(mc4, time, {x: num, delay: Math.random() });

TweenLite.to(mc5, this_needs_to_last_as_long_as_all_others, {x: num });

Link to comment
Share on other sites

You have several options:

 

1) Do the math yourself before you put the delays into the tweens. Kinda like:

 

var duration:Number = 0;
var delay:Number = Math.random();
duration = Math.max(duration, delay + time);
TweenLite.to(mc1, time, {x: num, delay: delay });
delay = Math.random();
duration = Math.max(duration, delay + time);
TweenLite.to(mc2, time, {x: num, delay: delay });
...
TweenLite.to(mc5, duration, {x: num });

 

2) Just use the new TimelineLite class in v11, like:

 

var myTimeline:TimelineLite = new TimelineLite();
myTimeline.appendMultiple( [TweenLite.to(mc1, time, {x: num, delay: Math.random()}),
                           TweenLite.to(mc2, time, {x: num, delay: Math.random()}),
                           TweenLite.to(mc3, time, {x: num, delay: Math.random()}),
                           TweenLite.to(mc4, time, {x: num, delay: Math.random()})]);
myTimeline.insert( TweenLite.to(mc5, myTimeline.duration, {x: num}), 0);

 

So basically, you can dump your tweens into a TimelineLite and check its "duration" property.

 

Get v11 at http://blog.greensock.com/v11beta/

Link to comment
Share on other sites

  • 4 weeks later...

I have the similar problem:

 

this all may seem like a overkill but how could I do this math when I am using a loop?

 

I tried like so but I dont think this is good:

 

function select(e:MouseEvent):void {

var time:Number = 0;
var counter:Number = 0;

var r:int = 0;

for (var i:int = 0; i< arr.length; i++){

var _duration:Number = Math.random() + 0.4;
var _delay:Number = Math.random() * (i/10);
counter = Math.max(_duration, _delay);
time += counter;	

TweenLite.to(arr[i], _duration, { y: newY + r, ease:Elastic.easeOut, delay: _delay });
r += spacing;

}
TweenLite.delayedCall( time, myFunction );
}

 

the math looks good to me but I am waiting too long... except if for loop for some reason last so much and then delayed call gets called so much later...

 

I am too lazy to switch to version 11 :mrgreen:

Link to comment
Share on other sites

I just remembered how I could count:

 

var counter:int = 0;
var max:int = 0;

function select(e:MouseEvent):void {

max = arr.length;

for (var i:int = 0; i< arr.length; i++){

	TweenLite.to(arr[i], Math.random() + 0.4, { y: 200 + r, ease:Elastic.easeOut, delay: Math.random() * (i/10), onComplete: done });
	r += spacing;

}
}
}

function done():void {

counter++;

if (counter == max) {
	endTween();
	counter = 0;
}
}

function endTween():void {
trace("done");
}

 

 

maybe this helps someone.

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