ActionScript - 获取事件调度程序的函数
我的代码中有 2 个函数可以调度 TweenEvent。每个函数调度相同的补间并添加相同的 TweenEvent.MOTION_FINISH 事件侦听器。但是,事件侦听函数必须根据调度事件的函数进行操作。
是否可以从事件监听器中获取事件调度程序的功能?如果没有其他优雅的解决方案,我可以使用一个标志来完成这项工作。
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()");
}
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()");
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您无法找出补间是通过哪个方法初始化的。相反,创建两个补间成员变量并检查事件的目标对象:
或调用两个不同的事件处理程序:
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:
or call two different event handlers: