在 Actionscript 中,有没有办法创建 Loader 的副本或缓存版本?
我正在加载一个 SWF 动画并希望同时在多个位置显示它,但我能弄清楚如何做到这一点的唯一方法是每次显示它时都加载它,如下所示
private function playSounds():void {
for (var i:Number = 0; i < 14; i++)
{
for (var a:Number = 0; a < 16; a++)
{
if (boxes[i][a].x == linePos && boxes[i][a].selected == true && played[i][a] == false)
{
played[i][a] = true;
MovieClip();
var swf:URLRequest = new URLRequest("../assets/glow2.swf")
var glow:Loader = new Loader()
glow.load(swf)
glow.x = boxes[i][a].x - 25*0.7;
glow.y = boxes[i][a].y - 27*0.7;
glow.scaleX = 0.7;
glow.scaleY = 0.7;
this.addChild(glow);
glows.push(glow)
glowTime.push(0)
var sc:SoundChannel = new SoundChannel();
sc = (sounds[i] as Sound).play();
}
}
}
}
:一次显示超过 5 次,所以我想知道是否有一种方法只需加载一次并在多个地方使用它。
I'm loading an SWF animation and want to display it in multiple places concurrently, but the only way I could figure out how to do that is to load it every time I display it, as seen here:
private function playSounds():void {
for (var i:Number = 0; i < 14; i++)
{
for (var a:Number = 0; a < 16; a++)
{
if (boxes[i][a].x == linePos && boxes[i][a].selected == true && played[i][a] == false)
{
played[i][a] = true;
MovieClip();
var swf:URLRequest = new URLRequest("../assets/glow2.swf")
var glow:Loader = new Loader()
glow.load(swf)
glow.x = boxes[i][a].x - 25*0.7;
glow.y = boxes[i][a].y - 27*0.7;
glow.scaleX = 0.7;
glow.scaleY = 0.7;
this.addChild(glow);
glows.push(glow)
glowTime.push(0)
var sc:SoundChannel = new SoundChannel();
sc = (sounds[i] as Sound).play();
}
}
}
}
This is very very slow when it's being displayed more than, say, 5 times at once so I'm wondering if there's a way to only have to load it once and use it in multiple places.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您拥有
Loader
的content
属性。因此,加载一次,多次使用内容。
编辑:在使用加载的内容之前,您可能需要添加一个侦听器以了解加载何时完成:
edit2:(
但尚未尝试)。
You have the
content
property of theLoader
.Thus, load once, use the content many times.
edit: you may want to add a listener to know when the loading completes, before you use the loaded content:
edit2:
(haven't tried though).
一种快速解决方法是创建第二个加载器,并通过 loadBytes() 方法:
这在大多数情况下都有效。在某些情况下,您应该能够摆脱像以下这样简单的事情:
还有第三个选项:“blitting”您的moviclip,这意味着您将存储一个或多个(取决于您需要缓存多少个MoveClip帧)内存中的 BitmapData 对象的数量 draw() 从您想要绘制的源 MovieClip(同时在多个位置)。
loadBytes 方法实现了问题所建议的目的:创建 Loader 的副本,因此它重新使用加载的字节,但初始化新内容,因此为此使用内存。
如果这不是您所需要的,那么使用 BitmapData 缓存 MovieClip 是您的最佳选择。
One quick workaround is to create a second loader and pass the loaded bytes to that via the loadBytes() method:
This will work in most cases. In some cases you should be able to get away with something as simple as:
And there is also a 3rd option: 'blitting' your moviclip, which means you'll store one or more (depending how many MoveClip frames you need to cache) of BitmapData objects in memory which will draw() from the source MovieClip you want to draw (in multiple locations at the same time).
The loadBytes approach achieves what the question suggests: creates a copy of the Loader, so it re-uses the bytes loaded, but initializes new content, so uses memory for that.
If this is not what you need, caching the MovieClip using BitmapData is your best bet.