Game Design
stories, tips, follies,
...and making some $$$ along the way!




AS3 Loaders - Update

Posted by: Sam Horton on Dec 2, 2008 at 3:43 PM


In a previous post, I described a method for making a self-contained loader in AS3. In older versions of Flash it seemed to work great, but after installing Flash Player 10, I noticed some caching issues in IE.

It appears that when using the loadProgress, and loadComplete events on an swf file that has been cached by the browser, the events will never fire because the file is technically 100% loaded. I found this out right after I released my new game Flubber Rise, and had to scramble to find a solution! The game was just sitting there on the loading frame, waiting patiently for some progress to occur.

Luckily it's an easy fix, and it makes the loader code even more similar to the way we used to do things in AS2. Instead of using the loadProgress event to update the loader bar, and instead of using loadComplete to detect when the file is fully loaded, just use an enterFrame event with some really basic code to check the bytesLoaded vs bytesTotal.

This code can be placed on frame 1 along with your loader bar/percent text/whatever you are using:

import flash.events.Event;
this.addEventListener(Event.ENTER_FRAME,loaderUpdate);
function loaderUpdate(e:Event):void{
if(loaderInfo.bytesLoaded==loaderInfo.bytesTotal){
this.removeEventListener(Event.ENTER_FRAME, loaderUpdate);
this.gotoAndStop("someFrame");
}
}

Again, this issue seems to only affect IE, and not Firefox. I'm not sure about other browsers so feel free to let me know.

Labels: , ,

By: Sam Horton | Dec 2, 2008 at 3:43 PM | | Leave a comment