Reputation: 17217
there are 2 functions in my code that dispatch a TweenEvent. each function dispatches the same tween and adds the same TweenEvent.MOTION_FINISH event listener. however, the event listening function must act according to which function dispatched the event.
is it possible to get the function of the event dispatcher from the event listener? i could use a flag to make this work if there are no other elegant solutions.
public function FirstTweenAction():void
{
myTween = new Tween(/* tween stuff */);
myTween.addEventListener(TweenEvent.MOTION_FINISH, myTweenEventMotionFinishHandler);
}
public function SecondTweenAction():void
{
myTween = new Tween(/* tween stuff */);
myTween.addEventListener(TweenEvent.MOTION_FINISH, myTweenEventMotionFinishHandler);
}
private function myTweenEventMotionFinishHandler(evt:TweenEvent):void
{
evt.currentTarget.removeEventListener(TweenEvent.MOTION_FINISH, myTweenEventMotionFinishHandler);
if (/* Event was fired from FirstTweenAction() */)
trace("Dispatcher is FirstTweenAction()");
else
trace("Dispatcher is SecondTweenAction()");
}
Upvotes: 0
Views: 200
Reputation: 22604
You can't find out from which method the tween was initialized. Instead, make two tween member variables and check the event's target object:
if (evt.target == myFirstTween) doSomething();
else doSomethingElse();
or call two different event handlers:
public function FirstTweenAction():void
{
myTween = new Tween(/* tween stuff */);
myTween.addEventListener(TweenEvent.MOTION_FINISH, myFirstTweenEventMotionFinishHandler);
}
public function SecondTweenAction():void
{
myTween = new Tween(/* tween stuff */);
myTween.addEventListener(TweenEvent.MOTION_FINISH, mySecondTweenEventMotionFinishHandler);
}
Upvotes: 1