Reputation: 302
I am tweening multiple items in array.But I want onComplete be called only once. Is there way to write it more readable?
for (var i : int = 0; i < _cardsToRollOut.length; i++)
{
var wCard : TacticCard = _cardsToRollOut[i];
if (doItOnce) TweenMax.to(wCard, 0.5, { delay:1, rotation:firstRotation + 0.4 * i} );
else
{
doItOnce = true;
TweenMax.to(wCard, 0.5, { delay:1, rotation:firstRotation + 0.4 * i, onComplete:updateCounters } );
}
}
Thank you in advance!
Upvotes: 0
Views: 52
Reputation: 2223
This is a common situation and there's plenty of ways to do it. One of them:
for (var i : int = 0; i < _cardsToRollOut.length; i++)
{
var wCard : TacticCard = _cardsToRollOut[i];
var properties:Object = {};
properties["delay"] = 1;
properties["rotation"] = firstRotation + 0.4 * i;
if(i == _cardsToRollOut.length - 1)
{
properties["onComplete"] = updateCounters;
}
TweenMax.to(wCard, 0.5, properties );
}
Upvotes: 1
Reputation: 52153
You could use a Timeline instead:
var timeline:TimelineLite = new TimelineLite({onComplete: updateCounters});
for (var i : int = 0; i < _cardsToRollOut.length; i++)
{
var wCard : TacticCard = _cardsToRollOut[i];
timeline.to(wCard, 0.5, { delay:1, rotation:firstRotation + 0.4 * i} , 0);
}
Upvotes: 3