A Simple example of tween class usage with callback in as3:
The 'obj' variable in the callback points to the object that was being altered / moved around by the tween object.
var t = new Tween(this, "x", Regular.easeIn, x, newX, 0.1, true); t.addEventListener(TweenEvent.MOTION_FINISH, function(e:TweenEvent){ trace(e.currentTarget.obj); });
This is how you import the neccesary classes:
import fl.transitions.Tween; import fl.transitions.easing.*; import fl.transitions.TweenEvent;
Be very wary though of defining tweens as local variables inside AS3 class methods! After the method's execution is completed any local variables may become eligible for garbage collection and if the tween is one of these, it may be destroyed even before it can finish it's animation or call it's onmotionfinish callback function.
This causes seemingly unexplainable problems with tweened animations malfunctioning seemingly at random.
One method to stop this from happening is to define an object or array as property of the class to serve simply as a container of the tweens. Push all tweens into this object upon creation to prevent them from from loosing all references when the method that created them returns and become eligible for garbage collection.