Hi all,
Is there any way to make sure a onComplete callback always runs?
I started by using the onComplete callback of TweenLite but since I kill any previous tweens, the onComplete callback may never get the chance to run.
Example:
function show ($view, onCompleteCallback) {
TweenLite.killTweensOf($view);
TweenLite.fromTo($view, 0.3,
{
opacity: 0,
},
{
opacity: 1,
ease: Quad.easeInOut,
onComplete: onCompleteCallback
}
);
}
So I ended up using a setTimeout or TweenLite.delayedCall (which essentially is a better looking setTimeout? is it?). Like so:
function show ($view, onCompleteCallback) {
TweenLite.killTweensOf($view);
TweenLite.fromTo($view, 0.3,
{
opacity: 0,
},
{
opacity: 1,
ease: Quad.easeInOut
}
);
TweenLite.delayedCall(onCompleteCallback, 0.3);
}
Is this the "proper" way to do it? Is there any way to make sure the onComplete of a tween runs even if I kill previous Tweens?
The complete callback here must run in order to perform some important tasks (such as removing listeners etc) - so I can't rely on the onComplete (apparently?). However I do have to base it on the tween because it shouldn't happen until it's completely visible in the view (tweened).
And the reason I do killTweensOf before the Tween is just in case the user clicks around too fast: so it immediately stops whatever is being tweened and tweens only the last interaction.
Is using the Timeline any different for callbacks? Any improvements suggestions here?