如何在 AS3 中完全删除影片剪辑 [英] How to completely remove a movieclip in AS3

查看:39
本文介绍了如何在 AS3 中完全删除影片剪辑的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我希望删除 mc 及其所有计时器、事件...有没有简单的方法可以做到这一点?

I want the mc to be removed with All its timers, events,... Is there a simple way to do this?

推荐答案

当然...取消注册其计时器和事件,将其从其父项中删除,并删除对其的所有引用.;)

Sure... unregister its timers and events, remove it from its parent, and delete all references to it. ;)

也就是说,AS3 是一种垃圾收集语言,因此您无法控制对象(包括 MC)何时从内存中真正删除.当您删除对它的所有引用(包括事件注册)时,GC 会检测到它不再需要并为您清理.

That is, AS3 is a garbage collected language, so you can't control when an object (including a MC) is really deleted from memory. When you delete all references to it (including event registration), the GC will detect that it is no longer needed and clean it up for you.

您可以(并且应该)做的一件事是,每当您注册事件时,将 useWeakReference 参数设置为 true.即:

One thing you can (and should) do is, whenever you register for events, set the useWeakReference parameter to true. That is:

myMC.addEventListener( Event.ENTER_FRAME, onFrame, false, 0, true );

这告诉 AS3 这个特定的事件监听器不应该算作一个引用——所以如果你删除所有其他对 MC 的引用,即使你没有取消注册监听器,它也会被垃圾收集.(至于计时器,如果您使用的是 setTimeout 或 setInterval,据我所知,它们也不被视为引用.但我不确定.)

This tells AS3 that this particular event listener should not count as a reference - so if you remove all other references to the MC, it will get garbage collected even if you don't unregister the listener. (As for timers, if you're using setTimeout or setInterval, as far as I know they aren't considered references either. But I'm not sure about that.)

因此,无论是长还是短,都没有办法让您的 MC 使用核武器并让 Flash 清理所有内容.这就是 AS3 的工作方式 - 管理您的引用和事件是认真编码的一部分.如果您的 MC 没有更多的计时器或事件,从其父级中删除,并且没有被您的代码的任何部分引用,那么它就会消失.

So the long and the short of it is, there is no way to nuke your MC and get Flash to clean up everything. That's just how AS3 works - managing your references and events is part of conscientious coding. If your MC has no more timers or events, is removed from its parent, and is not referenced by any part of your code, that's when it's gone.

这篇关于如何在 AS3 中完全删除影片剪辑的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆