as3删除子项问题
我正在舞台上的 0 处加载一些 swf 文件。它们是我网站的页面。
要从一个页面切换到另一个页面,我使用removeChildAt(0),然后使用addChildAt("page_title", 0)。
问题是,removeChild 不会从加载的第一个 swf 文件(卸载之前)中删除函数。
那我怎么能停下来呢?
我必须使用其他方式来删除Child吗?
谢谢!
I'm loading some swf files at 0 on my stage. They are the pages of my site.
To change from page to page I use removeChildAt(0) and then I addChildAt("page_title", 0).
The problem is that removeChild dont delete the functions from the first swf file loaded (before unloaded).
How can I stop then?
Do I have to use other way to removeChild?
Thanx!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
在我看来,你实际上并没有删除它们。首先,从显示列表中删除某些内容只是视觉/交互更改。它仍然在运行,直到您删除对它的任何引用(作为事件侦听器或 w/e),然后您必须将其设置为 null,以便垃圾收集将在下一个周期捕获它。
如果您使用的是 Flash Player 10,spender 是正确的,unloadAndStop 将为您工作,因为他们最近创建了它来解决您的问题。
我只是觉得我应该解释一下发生了什么,因为人们不仅应该知道修复方法,还应该知道事情发生的原因。
另一个建议是,我不会将这些电影加载到舞台上,我会创建一个容器
Sprite
/MovieClip
来保存它们,这样即使您稍后添加其他内容,它们是独立的、干净的,并且可以通过其父级(例如imageContainer_mc
)轻松访问。It sounds to me like you aren't actually removing them. First things first, removing something from the display list is only a visual/interactive change. It is still running until you remove any references to it, being event listeners or w/e, and then you must set it to null so that garbage collection will grab it on the next cycle.
If you are using Flash Player 10, spender is correct that unloadAndStop will work for you as they just recently created it to fix your very problem.
I just thought I should explain what is going on, because people should not only know about the fix, but why things happen.
One other suggestion, I wouldn't load these movies to stage, I would create a container
Sprite
/MovieClip
to hold them, that way even if you add other things later, they are separated, clean, and easy to access through their parent (imageContainer_mc
for instance).假设您正在使用 Loader 加载,您可以使用 unloadAndStop方法。
更多信息请参见:
http://www.gskinner.com/blog/档案/2008/07/additional_info.html
Assuming you are loading with a Loader you can use the unloadAndStop method.
More info here:
http://www.gskinner.com/blog/archives/2008/07/additional_info.html
或者,您可以将子电影加载到不同的 ApplicationDomain 中,以将加载的代码与主应用程序隔离。看一下
flash.system.ApplicationDomain
类(它是Loader.load()
方法的参数)。Alternatively, you can load the submovie into a different ApplicationDomain to insulate the loaded code from your main app. Take a look at the
flash.system.ApplicationDomain
class (it's a parameter to theLoader.load()
method).