闪光事件侦听器的影片剪辑结束了吗? [英] flash event listener for movieclip end?
本文介绍了闪光事件侦听器的影片剪辑结束了吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
谁能劝触发functiont当影片剪辑动画完成的最佳方法是什么? 我想,一个事件监听器可以处理这个问题,但不知道去它的最佳途径。 谢谢 保
Could anyone advise the best way to trigger a functiont when a movieclip animation finishes? I figure an eventlistener could handle this, but not sure the best way to go about it. Thanks Paul
推荐答案
有几种方法去这个问题:
There are a few ways to go about this:
- 要获取从您的动画的最后一帧的功能。
- 在发货你的函数的最后一帧上的事件和其他地方听吧。
- 在长期而有效的/整齐/推荐的方式。
在参考3点,我将创建一个基类作为您的对象。这样,您就可以在同样的逻辑应用到多个元素进行动画。
In reference to point 3, I would create a base class for your object. This way you can apply the same logic to multiple elements being animated.
事情是这样的:
package
{
import flash.display.MovieClip;
import flash.events.Event;
public class AnimatingObject extends MovieClip
{
// constants
public const ANIMATION_COMPLETE:String = "animation_complete";
/**
* Constructor
*/
public function AnimatingObject()
{
addEventListener(Event.ENTER_FRAME, _handle);
}
/**
* Called on dispatch of Event.ENTER_FRAME
*/
private function _handle(e:Event):void
{
if(currentFrame == totalFrames)
{
var evt:Event = new Event(ANIMATION_COMPLETE);
dispatchEvent(evt);
}
}
}
}
现在我们可以听animation_complete,并做相应的东西。
Now we can listen for "animation_complete" and do stuff accordingly.
package
{
import flash.events.Event;
public class MyAnimatingObject extends AnimatingObject
{
/**
* Constructor
*/
public function MyAnimatingObject()
{
addEventListener(ANIMATION_COMPLETE, _lastFrame);
}
/**
* Called on dispatch of AnimatingObject.ANIMATION_COMPLETE
*/
private function _lastFrame(e:Event):void
{
trace("i'm done");
}
}
}
这篇关于闪光事件侦听器的影片剪辑结束了吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文