Pass easing function as variable in AS3
I've been looking for some time now.. Is is possible to pass easing function as variable in AS3?
eg.
TweenLite.to(mcDelimiter, resizeTween, { x:(stageWidthHalf-(initStageWidthHalf-mcDelimiteri_X)), ease:Elastic.easeOut } );
TweenLite.to(mcBody, resizeTween, { x:(stageWidthHalf-(initStageWidthHalf-mcBody_X)), ease:Elastic.easeOut } );
... now if I at some point want to change "Elastic.easeOut" to something else I would have to change it at multiple parts of the code.. Can it be done开发者_运维技巧 so I just pass it as a variable and then if I want to change it, do it only on one place?
EDIT: ...also,
can for eg. if(currentFrame == "FrameLabel")
somehow be done? ..meaning, can I pass the currentFrame label name as a variable?
Thanks in advance for anwsers,
Andrej
You can pass around a reference to a function in ActionScript, just as you would with any other object. For instance ( pseudo code ):
var equation:Function;
equation = Elastic.easeInOutSine;
TweenLite.to(mcDelimiter, resizeTween, { x:(stageWidthHalf-(initStageWidthHalf-mcDelimiteri_X)), ease: equation } );
All you need to do is create a variable to act as a reference to the easing function. You could wrap the call to TweenLite in another function and pass the easing variable to it like so:
public function doTween( equation:Function ):void
{
TweenLite.to(mcDelimiter, resizeTween, { x:(stageWidthHalf-(initStageWidthHalf-mcDelimiteri_X)), ease: equation } );
}
thanks!! btw: if someone else has the same problem, using "currentLabel" instead of currentFrame gets the current frames name... duh! :)
精彩评论