AS3 通过动画剪辑在 MOTION_FINISH 之前删除补间
我已经在这个问题上摸索了一段时间了。我有一个可爱的小工具提示影片剪辑,它会跟随用户的鼠标几秒钟,然后自行删除。我的问题是,如果已经有一个,我将其删除,但是,我似乎无法删除 MOTION_FINISH 事件,它仍然会触发并可能删除一个新的工具提示。
我想要的是本质上放入一个行项目,例如 var tween(smallhelp_panel).deleteAll(); 我看到了一个tweenlight函数killtweensof(mc);不过,我在 30k 行 AS3 代码中使用了下面合并的补间。
这是我的工具提示处理程序。我用一个简单的“我的影片剪辑是一个“smallhelp_panel””来调用它
Main_Warning("Please don't forget to save!",5);
,然后检查它是否已经存在并将其删除。但是,alpha 和 MOTION_FINISH 补间仍然存在,并会导致任何新的smallhelp_panels 出现问题。
public function Main_Warning( the_text:String, myTimer:int = 4){
if(smallhelp_panel != null){
stage.removeChild( smallhelp_panel );
removeEventListener(Event.ENTER_FRAME, trackmouse);
smallhelp_panel = null;
}
smallhelp_panel = new small_help();
smallhelp_panel.name = "myWarning";
smallhelp_panel.x = mouseX - 50;
smallhelp_panel.y = mouseY + 15;
smallhelp_panel.helptext.text = the_text;
stage.addChild( smallhelp_panel );
addEventListener(Event.ENTER_FRAME, trackmouse);
var myTween:Tween;
myTween = new Tween(smallhelp_panel, "alpha", None.easeOut, 1, 0, myTimer, true);
tweenholder = myTween;
tweenArray.push(tweenholder);
myTween.addEventListener(TweenEvent.MOTION_FINISH, removeTween);
}
这是我的工具提示处理程序。
出于参考目的,我的补间移除器是:
public function removeTween(e:TweenEvent = null):void{
e.target.removeEventListener(TweenEvent.MOTION_FINISH, removeTween);
if(smallhelp_panel != null){
removeEventListener(Event.ENTER_FRAME, trackmouse);
stage.removeChild( smallhelp_panel );
smallhelp_panel = null;
}
}
用鼠标移动工具提示的鼠标跟踪器很简单:
public function trackmouse(e:Event):void{
smallhelp_panel.x = mouseX - 50;
smallhelp_panel.y = mouseY + 15;
}
I've been fumbling with this issue for a bit. I've got a lovely little tooltip movieclip that follows the user's mouse for a few seconds before it removes itself. My problem is that if there is one already there I remove it, however, I cannot seem to remove the MOTION_FINISH event and it still fires and possibly deletes a new tooltip.
What I want is to essentially put in a line item such as var tween(smallhelp_panel).deleteAll();
I saw a tweenlight function killtweensof(mc); However I've used the tweens I've incorporated below throughout my 30k lines of AS3 code.
Here is my tooltip handler. I call it with a simple
Main_Warning("Please don't forget to save!",5);
My movieclip is a 'smallhelp_panel' and I check if it already exists and remove it. However, the alpha and MOTION_FINISH tweens still exist and cause issues with any new smallhelp_panels.
public function Main_Warning( the_text:String, myTimer:int = 4){
if(smallhelp_panel != null){
stage.removeChild( smallhelp_panel );
removeEventListener(Event.ENTER_FRAME, trackmouse);
smallhelp_panel = null;
}
smallhelp_panel = new small_help();
smallhelp_panel.name = "myWarning";
smallhelp_panel.x = mouseX - 50;
smallhelp_panel.y = mouseY + 15;
smallhelp_panel.helptext.text = the_text;
stage.addChild( smallhelp_panel );
addEventListener(Event.ENTER_FRAME, trackmouse);
var myTween:Tween;
myTween = new Tween(smallhelp_panel, "alpha", None.easeOut, 1, 0, myTimer, true);
tweenholder = myTween;
tweenArray.push(tweenholder);
myTween.addEventListener(TweenEvent.MOTION_FINISH, removeTween);
}
That is my Tooltip handler.
for reference purposes my tween remover is:
public function removeTween(e:TweenEvent = null):void{
e.target.removeEventListener(TweenEvent.MOTION_FINISH, removeTween);
if(smallhelp_panel != null){
removeEventListener(Event.ENTER_FRAME, trackmouse);
stage.removeChild( smallhelp_panel );
smallhelp_panel = null;
}
}
and my mouse tracker that moves the tooltip with the mouse is a simple:
public function trackmouse(e:Event):void{
smallhelp_panel.x = mouseX - 50;
smallhelp_panel.y = mouseY + 15;
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
这是因为您已将 MOTION_FINISH 事件侦听器添加到补间,而不是面板。如果面板已经存在,则删除面板,但补间仍然存在于 tweenholder 和 tweenArray 变量中 - 并在计算完成时触发 MOTION_FINISH 事件。您的事件侦听器方法不知道事件来自哪个补间,并正确删除帮助面板。
要解决此问题,请删除 Main_Warning 函数中的补间和事件侦听器以及帮助面板,或者修改事件侦听器方法中的删除块:
我不明白为什么您需要同时需要 tweenholder 和 tweenArray 变量,尽管 ;)
That's because you've added your MOTION_FINISH event listener to the tween, not to the panel. You remove the panel, if one already exists, but the tween still exists in the tweenholder and tweenArray variables - and fires a MOTION_FINISH event, when its calculations are finished. Your event listener method doesn't know which tween the event came from, and correctly removes the help panel.
To fix this, either remove the tween and event listener along with the help panel in your Main_Warning function, or modify the removal block in your event listener method:
I don't understand exactly why you would need both a tweenholder and a tweenArray variable, though ;)
您的 TweenEvent 仍在被监听。您永远不会删除前一个侦听器,因此当补间计算完成时它将触发。
我假设 tweenholder 是在全局某个地方声明的? (就像这里的其他答案一样,我对您需要声明一个新的补间、将其存储在另一个引用中并将该引用添加到数组中感到困惑...)如果是这样,请尝试以下操作:
Your TweenEvent is still being listened for. You never remove the previous listener, so it will fire when the tween calculations are complete.
I assume tweenholder is declared somewhere global? (Like the other answer here, I'm confused as to your need of declaring a new tween, storing it in another reference and adding that reference to an array...) If so, try this: