简体   繁体   English

在显示它后卸载动态加载的 swf AS3

[英]unload dynamically loaded swf after displaying it AS3

I am doing a presentation on which I need to use a lot of video clips.我正在做一个需要使用大量视频剪辑的演示文稿。 I load all these videos dynamically using Loader.我使用 Loader 动态加载所有这些视频。 I use a code snippet like this:我使用这样的代码片段:

var req:URLRequest = new URLRequest("video.swf");
var a:Loader = new Loader();
a.load(req);
stage.addChild(a);

a Now the issue is: When I get to say the 7th one, it starts lagging. a 现在的问题是:当我说第 7 个时,它开始滞后。 I do not know why, but I think it is because everything is loaded to memory.我不知道为什么,但我认为这是因为所有内容都加载到 memory。 Is there a way I can erase a video from memory after displaying it?有没有办法在显示 memory 后删除视频? Or is there another solution to this?或者有其他解决方案吗?

If you just load a new video each time and add it to the stage, you will have a rather big hierarchy of movies sitting on top of each other;如果您每次都加载一个新视频并将其添加到舞台上,那么您将拥有一个相当大的电影层次结构; all kept on stage and in memory.全部保留在舞台上和 memory 中。

If you keep a reference to the previously loaded movie, you can just remove it from the stage when the 'next' movie is loaded.如果您保留对先前加载的电影的引用,则可以在加载“下一个”电影时将其从舞台上删除。 Haven't tested this properly, but just to give you an idea of what the code might look like:尚未对此进行正确测试,只是为了让您了解代码的外观:

var oldLoader:Loader = null;

var a:Loader = new Loader();
a.contentLoaderInfo.addEventListener(Event.COMPLETE, loader_complete);
a.load(<your url>);

function loader_complete(e:Event):void {
    var newLoader:Loader = e.currentTarget.loader as Loader;

    stage.addChild(newLoader);

    if(oldLoader != null) {
        stage.removeChild(oldLoader);
        oldLoader = null;
    }

   oldLoader = newLoader;
}

I think I found the solution.我想我找到了解决方案。 If you use removeChild, it only stops displaying, but the whole thing is still in memory (cache).如果您使用 removeChild,它只会停止显示,但整个内容仍在 memory(缓存)中。 So the more you load the videos, the more you fill up the cache.因此,您加载视频的次数越多,缓存就越多。 What we need is something that completely clears the cache before loading another video.我们需要的是在加载另一个视频之前完全清除缓存的东西。

I used unloadAndStop() and it seem to have completely done the trick, unless someone has something against it.我使用了 unloadAndStop() ,它似乎已经完全成功了,除非有人反对它。

Thanks again再次感谢

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM