Apr
30
2008
Getting a reference of a tweened MovieClip from an event handler function
When you are tweening an object using built-in Tween classes and you want to perform some actions on it when the tweening is done, you can reference the object using TweenEvent's obj property.
Lets say I want to move my object named ball_mc 40 pixels to the right and when this is done I want to change its alpha to 20%.
//create new tween that moves object along the x axis
var myTween:Tween = new Tween(ball_mc, "x", Strong.easeIn, 10, 50, 2, true);
//when animation is done kick off onBallFinish function
myTween.addEventListener(TweenEvent.MOTION_FINISH, onBallFinish);
function onBallFinish(e:TweenEvent):void
{
//currentTarget.obj is a reference to my ball_mc movie clip
e.currentTarget.obj.alpha = .2;
//remove unnecessary listener as I won't need it anymore
e.currentTarget.removeEventListener(TweenEvent.MOTION_FINISH, onBallFinish);
}


Comments
import fl.transitions.Tween;
import fl.transitions.TweenEvent;
import fl.transitions.easing.*;