Warning: A non-numeric value encountered in /homepages/10/d677520614/htdocs/ryanragle.com/wp-content/themes/Divi/functions.php on line 5560

If you have ever written an AS3 preloader like this one, you may have noticed that on certain browsers they do not work correctly. Usually they hang as a results of having the total bytes as being returned as 0, instead of the actual size. The two most common browsers that will show this problem are Safari and IE 8. There are a couple of reasons that this can happen.

Possible Issue #1 – Your Server is compressing your .swf with Gzip.
The easiest way to test this is to put your .swf on another server not running gzip compression, or configure your server to not use Gzip for .swf, but the real issue can be address with Possible Issue #2. Here is a good article on the Gzip / SWF issue

Possible Issue #2 – Your code stinks! OK, a bit harsh, but just like the example above the ‘tutorial’ they show have you using the ENTER_FRAME. I thought we all knew about the true way to load up data, and that is with the Event.COMPLETE and ProgressEvent.PROGRESS. Honestly though I wrote this article because I probably did the same thing as you. To be quick, here is what you should essentially have in the first frame of the first scene that loads up:


stop();

var preLoaderPercent:Number;
this.loaderInfo.addEventListener(Event.COMPLETE, loadComplete);
this.loaderInfo.addEventListener(ProgressEvent.PROGRESS, loadProgress);

function loadComplete(e:Event) {
    // load complete - remove listeners and move on
    this.loaderInfo.removeEventListener(Event.COMPLETE, loadComplete);
    this.loaderInfo.removeEventListener(ProgressEvent.PROGRESS, loadProgress);
    play();
}

function loadProgress(e:ProgressEvent):void {
    preLoaderPercent = e.bytesLoaded / e.bytesTotal;
    // Put code here to update your display
}

If you want an example to test on your server, download the example ActionScript 3.0 preloader hereand see if your problem goes away.