闪存预加载器仅在 90% 时启动
我正在 Flash CS5 / AS3 中开发一款游戏,我正在尝试让我的预加载器正常工作。目前,当我使用“模拟下载”加载 SWF 文件时,该文件将加载,但我的预加载器不会显示。当负载达到 90% 左右时,预加载器确实会显示一段时间。
我没有选中“导出到第一帧”,因为这是互联网告诉我要做的,但是几乎每个版本的 Flash/AS 都有很多不同的教程,我很困惑;不知道如何解决这个问题。
我的预加载器代码如下:
stop();
this.addEventListener(Event.ENTER_FRAME, loading);
function loading(e:Event):void{
var total:Number = this.stage.loaderInfo.bytesTotal;
var loaded:Number = this.stage.loaderInfo.bytesLoaded;
percent_txt.text = Math.floor((loaded/total)*100)+ "%";
if (total == loaded){
play();
this.removeEventListener(Event.ENTER_FRAME, loading);
}
}
但不确定这是否有任何帮助。希望有人知道快速修复。我在某处读到这可能与声音文件有关(我确实有几个)但是是的,不太确定从哪里开始。
提前致谢!
I'm working on a game in Flash CS5 / AS3 and I'm trying to get my preloader to work. At the moment, when I load the SWF file with 'simulate download', the file will load but my preloader won't show. The preloader does show for a moment when the loading is at around 90%.
I have unchecked 'export to first frame' since that's what the Internet told me to do, but there are so many different tutorials for nearly every version of Flash/AS around that I'm rather confused; not sure how to fix this.
My preloader code is as follows:
stop();
this.addEventListener(Event.ENTER_FRAME, loading);
function loading(e:Event):void{
var total:Number = this.stage.loaderInfo.bytesTotal;
var loaded:Number = this.stage.loaderInfo.bytesLoaded;
percent_txt.text = Math.floor((loaded/total)*100)+ "%";
if (total == loaded){
play();
this.removeEventListener(Event.ENTER_FRAME, loading);
}
}
Not sure if this is of any help though. Hopefully someone knows a quick fix. I read somewhere that this might have to do with sound files (I do have a couple of these) but yeah, not quite sure where to start.
Thanks in advance!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
如果您的主时间轴的第 1 帧上有任何内容,您将永远无法预加载该内容 - 只有在加载第 1 帧上的内容后,您的电影才会开始播放。尝试将所有非必要的“内容”移至第 2 帧,并将该帧设置为动作脚本的导出帧。您现在应该会看到预加载器早在 90% 之前就已经完成了。预加载完成后,使用 gotoAndPlay(2) 将影片发送到第 2 帧。
或者(可能是最佳实践),制作一个“加载器”swf,其唯一功能是加载主 swf。将预加载器放入该加载器 swf 中,仅此而已,并将所有其他内容保留在主 swf 中。使用 Loader 类或第 3 方加载库(如 BulkLoader)加载主 swf,并在加载完成后将其放置在舞台上。
希望这有帮助。
If you have any content at all on frame 1 of your Main Timeline, you will never be able to preload THAT content - your movie will only start playing once the content on frame 1 is loaded. Try moving all non-essential "stuff" to frame 2, and setting that frame as the export frame for actionscript. You should now see your preloader long before 90%. Once your preload is complete, send your movie to frame 2 with a gotoAndPlay(2).
Alternatively (and probably a best practice), make a "loader" swf whose only function is to load in your main swf. Put your preloader in that loader swf and nothing else, and keep all your other content in your main swf. Load your main swf using the Loader class or a 3rd party loading library like BulkLoader, and place it on the stage once it's finished loading.
Hopefully that helps.
当你编译&运行您的应用程序,单击“查看”,然后单击菜单中的“带宽分析器”。这将让您看到每个帧有多大,即该帧上加载的数据量。如果您的第一帧超过 30kb 左右,那么您就会遇到问题。尝试使预加载器尽可能简单(没有图像等)。同样如您所说,请确保您已在所有资产上取消选择“在第 1 帧中导出”。
另外,我会将
this.stage.loaderInfo
替换为root.loaderInfo
。When you compile & run your application, click View and then Bandwidth Profiler in the menu. This will let you see how large each frame is in terms of how much data is being loaded on that frame. If your first frame is more than around 30kb then you have a problem. Try and keep your preloader as simple as possible (no images, etc). Also like you said, make sure you've deselected "export in frame 1" on all of your assets.
Also I would replace
this.stage.loaderInfo
withroot.loaderInfo
.