English 中文(简体)
如何在.addchild之后清理电影剪辑?AS3/闪存
原标题:How to clean a MovieClip after a .addchild ? AS3/Flash

我正在使用.addchild将图像添加到电影剪辑中:

function imageLoaded(e:Event):void {
    fn=fn+1;
    if (fn==1) { panel.estadoimg.addChild(imageLoader); loadImage(datosXML.localiza);}
    if (fn==2) { panel.mapa.mapaimg.addChild(imageLoader); fn=0; }
}

我的想法是,我想重复使用那部电影,我该如何清理它?谢谢

最佳回答

在您的示例中,似乎您正在将图像添加到两个不同的容器中,但如果movieclip中唯一的东西是图像,则您将使用removeChildAt(0)将它们取出。还删除与该图像相关联的所有侦听器。使图像为空以将其提供给垃圾收集。

问题回答

如果imageLoader是要删除的对象:

var p:DisplayObjectContainer = imageLoader.parent;
if (p)
  p.removeChild(imageLoader);

imageLoader = null;

此外,如果<code>imageLoader</code>的类型为<code>flash.display.Loader</code>,则在清理它之前,您需要对其调用<code>unload()</code>。如果是Flex的ImageSWFBLoader组件,则可以将source属性设置为null

you can have a look at what casalib does with casaMovieClip. Usually I would use this library instead of adding these function, but it is good to have a peak at what s going on. removeChild is ok, but without knowing what else is happening behind the scene and not completely destroying objects can cause memory leaks.

假设您使用的是图像加载器,我假设您已经至少有一个事件侦听器。此事件侦听器可以连接到您加载的映像,即使您从显示列表中删除此映像(通过removeChild/removechildAt),您仍然可以使对象延迟。





相关问题
Disable button tooltip in AS3

I want to disable the tooltip on certain buttons. The tooltip manager seems to be an all or nothing solution. Is it possible to disable the tooltip for just one or two buttons?

Sorting twodimensional Array in AS3

So, i have a two-dimensional Array of ID s and vote count - voteArray[i][0] = ID, voteArray[i][1] = vote count I want the top 3 voted items to be displayed in different colors, so i have a 2nd Array -...

Virtual Tour using sketch up, ajax, flash technologies

I want to know if there are existing technology that make your 3d models in sketch into virtual tours, using either Ajax or Flash for web presentation. If there s none, which will be a good approach ...

AS3 try/catch out of memory

I m loading a few huge images on my flex/as3 app, but I can t manage to catch the error when the flash player runs out of memory. Here is the what I was thinking might work (I use ???? because i dont ...

Red5 Security Tutorial

I am looking for a step by step tutorial on securing Red5 from intrusion. This seems to be a question that comes up alot in a google search, but is never really answered in a way that makes sense to ...

Clipboard access using Javascript - sans Flash?

Is there a reliable way to access the client machine s clipboard using Javascript? I continue to run into permissions issues when attempting to do this. How does Google Docs do this? Do they use ...

visible property of DisplayObject

For example I have a hierarchy of movie clips. mc1 is a child of mc, and mc2 is a child of mc1. Turns out that when I set mc1.visible = false; mc2.visible stays true. Is that supposed to happen?...

热门标签