Actionscript 3.0 MovieClip 帧更改侦听器

发布于 2024-12-10 05:24:29 字数 315 浏览 10 评论 0原文

我有一个与怪物的场景。怪物眨着眼睛。眨眼是一个单独的MovieClip。 在某些条件下,怪物会张开嘴。张嘴也是一个单独的影片剪辑。此时此刻我不得不闭上眼睛MovieClip。一旦怪物闭上嘴,我就必须让眨眼的眼睛再次可见。

我的想法是让一些听众听 Mouth_opening MovieClip。当嘴巴张开的currentFrame从1变成2时,我会隐藏眼睛。当它从 2 变为 1 时,我会将其显示回来。

那么,问题是:如何监听 currentFrame 的变化? Event.ENTER_FRAME 不合适:它在每个渲染帧都被调用,而不仅仅是在 currentFrame 更改时调用。

I have a scene with a monster. Monster blinks its eyes. Eyes blinking is a separate MovieClip.
Under some conditions, monster opens its mouth. Mouth opening is a separate MovieClip as well. At this moment I have to hide eyes MovieClip. As soon as monster closes its mouth, I must make eyes blinking visible again.

My idea is to have some listener that listens to Mouth_opening MovieClip. When Mouth opening's currentFrame changes from 1 to 2, I will hide eyes. When it changes from 2 to 1, I will show it back.

So, the question is: how do I listen to currentFrame changes?
Event.ENTER_FRAME is not appropriate: it's being called every render frame, not only when currentFrame changes.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

不必在意 2024-12-17 05:24:29

ActionScript 中没有“frameChange”事件,因此您需要制定自己的系统。例如,您可以通过监听 enterFrame 来使其工作,然后监视当前帧 - 当它更改时调用您的函数。类似的东西应该有效:

private var lastFrame:int = -1;

// Then add this in your constructor:
addEventListener("enterFrame", onEnterFrame);

private function onEnterFrame(event:*):void {
    if (lastFrame != currentFrame) {
        onFrameChanged();
        lastFrame = currentFrame;
    }
}


private function onFrameChanged():void {
    trace("The frame has changed to " + currentFrame);
}

There is no "frameChange" event in ActionScript so you need to come up with your own system. For example, you can make it work by listening to enterFrame then monitor the current frame - when it changes call your function. Something like that should work:

private var lastFrame:int = -1;

// Then add this in your constructor:
addEventListener("enterFrame", onEnterFrame);

private function onEnterFrame(event:*):void {
    if (lastFrame != currentFrame) {
        onFrameChanged();
        lastFrame = currentFrame;
    }
}


private function onFrameChanged():void {
    trace("The frame has changed to " + currentFrame);
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文