开发者

ActionScript - Get Function Of Event Dispatcher

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("Dispatche开发者_Python百科r is FirstTweenAction()");
        else     
        trace("Dispatcher is SecondTweenAction()");
     }


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);
     }
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜