简体   繁体   English

Flash预加载器仅从90%开始

[英]Flash preloader only starts at 90%

I'm working on a game in Flash CS5 / AS3 and I'm trying to get my preloader to work. 我正在使用Flash CS5 / AS3开发游戏,我正在努力让我的预加载器工作。 At the moment, when I load the SWF file with 'simulate download', the file will load but my preloader won't show. 目前,当我使用“模拟下载”加载SWF文件时,文件将加载但我的预加载器将不会显示。 The preloader does show for a moment when the loading is at around 90%. 预加载器确实显示负载大约为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; 我已经取消选中'导出到第一帧',因为这是互联网告诉我要做的事情,但是对于几乎所有版本的Flash / AS都有很多不同的教程我很困惑; 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! 提前致谢!

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. 如果您在主时间轴的第1帧上有任何内容,您将永远无法预加载该内容 - 只有在加载第1帧内容后,您的电影才会开始播放。 Try moving all non-essential "stuff" to frame 2, and setting that frame as the export frame for actionscript. 尝试将所有非必要的“东西”移动到第2帧,并将该帧设置为actionscript的导出帧。 You should now see your preloader long before 90%. 您现在应该在90%之前看到您的预加载器。 Once your preload is complete, send your movie to frame 2 with a gotoAndPlay(2). 预加载完成后,使用gotoAndPlay(2)将影片发送到第2帧。

Alternatively (and probably a best practice), make a "loader" swf whose only function is to load in your main swf. 或者(可能是最佳实践),制作一个“加载器”swf,其唯一功能是加载到主swf中。 Put your preloader in that loader swf and nothing else, and keep all your other content in your main swf. 将您的预加载器放在该加载器swf中,而不是其他内容,并将所有其他内容保存在主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. 使用Loader类或第三方加载库(如BulkLoader)加载主swf,并在加载完成后将其放在舞台上。

Hopefully that helps. 希望这会有所帮助。

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. 如果您的第一帧超过30kb,那么您就遇到了问题。 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. 也像你说的那样,确保你在所有资产上取消选择“第1帧中的导出”。

Also I would replace this.stage.loaderInfo with root.loaderInfo . 我也会用this.stage.loaderInfo替换root.loaderInfo

stop();

var total:uint = root.loaderInfo.bytesTotal;
var loaded:uint = 0;

addEventListener(Event.ENTER_FRAME, loading);
function loading(e:Event):void
{
    loaded = root.loaderInfo.bytesLoaded;
    percent_txt.text = Math.floor((loaded/total)*100)+ "%";  

    if(total >= loaded)
    {
        removeEventListener(Event.ENTER_FRAME, loading);
        play();
    }
}

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

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