Flash AS3 preloader doesn't show until 100%

289 Views Asked by At

I realize this have been asked and answered numerous times but even after some reading I can't fix the issue. What I have: A preloader A game which should happen after the preloader What really happens: All the components load before the preloader, which kind of makes the preloader useless haha. I've changed "Export classes in frame 1" to "frame 2", but to no avail. I would prefer not to use an external preloader.

Here's my code:

   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;

    preloader.scaleX = loaded/total;

 if (total == loaded){
    nextFrame();
    this.removeEventListener(Event.ENTER_FRAME, loading);
}

}

And here's this:

https://pp.vk.me/c630919/v630919494/37371/sgdJTWian6Q.jpg

What am I doing wrong?

2

There are 2 best solutions below

0
Tsubasa Yeung On

You should try to add listener with this.root.loaderInfo (this way is better though your way works in this condition,so never mind).

  1. No need to change "export classes in frame 1 => 2", just keep the default value;
  2. First frame code can be like this:
    import flash.events.ProgressEvent; this.root.loaderInfo.addEventListener(ProgressEvent.PROGRESS,loaderProgressHandler); function loaderProgressHandler(evt:ProgressEvent):void { preloader.scaleX = evt.bytesLoaded /evt.bytesTotal; }
  3. Second frame(you actually wanna show) code like this:
    stop();
  4. That's all.Maybe you can't see the progress clearly because local simulation speed is too fast. You can try "Simulate Download" with shutcut "Ctrl + Enter" twice.
0
FilippoG On

In order to avoid messing up with class export frames, I usually use a second SWF to preload. It works perfectly. You just need to make sure you clear all memory in the loader movie once the large SWF is loaded. In this way you can keep a super simplified pre-loader. In some projects I just used the same pre-loader for in game server connection waiting times. It is versatile and doesn't bother your main app logic.