如何在停止循环之前完成循环电影脚本?
Posted
技术标签:
【中文标题】如何在停止循环之前完成循环电影脚本?【英文标题】:How do I make a looping moviescript finish before stopping it? 【发布时间】:2017-08-27 06:11:17 【问题描述】:我正在为水滴落下的泄漏对象制作动画。我希望在单击其他对象后立即停止泄漏。当我使用 stop();它只是停止,水滴卡在空中。我当然不想要这个,我该如何解决?
Bloempoteetkamer.addEventListener(MouseEvent.CLICK, rotplanteetkamer);
Bloempoteetkamer.buttonMode=true;
Bloempoteetkamer.mouseChildren=false;
function rotplanteetkamer(evt:MouseEvent)
Planteetkamer.play()
Druppel.stop()
Bloempoteetkamer.removeEventListener(MouseEvent.CLICK, rotplanteetkamer);
Bloempoteetkamer.buttonMode=false;
stop();
Bloempoteetkamer 是您必须单击以阻止泄漏的对象。 Druppel 是落下的水滴。 Planteetkamer 是一个不同的电影脚本,当我点击 Bloempoteetkamer 时会播放。
【问题讨论】:
不看你的代码我们怎么知道? Bloempoteetkamer.addEventListener(MouseEvent.CLICK, rotplanteetkamer); Bloempoteetkamer.buttonMode=true; Bloempoteetkamer.mouseChildren=false;功能 rotplanteetkamer(evt:MouseEvent) Planteetkamer.play() Druppel.stop() Bloempoteetkamer.removeEventListener(MouseEvent.CLICK, rotplanteetkamer); Bloempoteetkamer.buttonMode=false;停止(); Bloempoteetkamer 是您必须单击以停止泄漏的对象。 Druppel 是落下的水滴 Planteetkamer 是当我点击 Bloempoteetkamer 时播放的不同电影脚本 更新您的问题,不要将您的代码作为评论发布 “我当然不想要这个”……好吧,你想要什么做? 像标题所说的那样在停止之前完成剪辑 【参考方案1】:您可能希望使用EnterFrame
选项在播放 MClip (Druppel) 期间检查它是否实际到达最后一帧,然后才应该使用 MClip stop()
。
试试这样:
Bloempoteetkamer.addEventListener(MouseEvent.CLICK, rotplanteetkamer);
Bloempoteetkamer.buttonMode=true;
Bloempoteetkamer.mouseChildren=false;
function rotplanteetkamer(evt:MouseEvent)
Planteetkamer.play();
//Druppel.stop();
Druppel.addEventListener(Event.ENTER_FRAME, check_if_LastFrame);
Bloempoteetkamer.removeEventListener(MouseEvent.CLICK, rotplanteetkamer);
Bloempoteetkamer.buttonMode=false;
stop();
function check_if_LastFrame(target : Event) : void
if (target.currentFrame == target.totalFrames)
Druppel.stop();
Druppel.removeEventListener(Event.ENTER_FRAME, check_ifLastFrame);
【讨论】:
按原样测试代码,然后让我知道是否有任何问题。目前无法自己测试它,但通常它是这样工作的。【参考方案2】:另一个更紧凑的选择是使用 AddFrameScript。 addFrameScript
方法将代码注入到 MovieClip 的特定帧中,就像您使用 Adobe Animate 中的工具一样。
这是一个创建可重用函数的示例,用于在影片剪辑下一次到达其最后一帧时停止它:
function stopClipAfterLastFrame(clip:MovieClip):void
//addFrameScript to the last frame that calls an inline function
clip.addFrameScript(clip.totalFrames-1, function()
clip.stop(); //stop the clip
clip.addFrameScript(clip.totalFrames-1, null); //remove the frame script so it doesn't stop again the next time it plays
);
因此,如果您调用 stopClipAfterLastFrame(Druppel)
,它将在到达最后一帧时停止。
请记住,addFrameScript 是一个未记录的功能 - 这意味着它可能在未来的某些 Flash 播放器/AIR 版本中不再起作用 - 尽管目前这不太可能。删除框架脚本(通过将 null 作为函数传递)以防止内存泄漏也非常重要。
【讨论】:
以上是关于如何在停止循环之前完成循环电影脚本?的主要内容,如果未能解决你的问题,请参考以下文章
如何让 lua 在 while true 循环中停止 if 循环?