开发者

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. 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开发者_StackOverflow社区 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. 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.


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 with 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();
    }
}
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜