Have you ever embedded an swf into an html docuement and all seemed fine until you started getting calls from customers saying that the preloader is stuck at 100%?
Well I have, and it took me quite some time to figure this out.
If you embed different wmode, such as wmode=transparent, Firefox will load the first frame of your swf but then it appears to lock up!
It turns out that the loaderInfo Event.COMPLETE and PROGRESS are not firing.
Here is my working preloader:
var preLoaderPercent:Number = 0;
addEventListener(Event.ENTER_FRAME, loadComplete);
function loadComplete(e:Event):void {
if (this.loaderInfo.bytesLoaded == this.loaderInfo.bytesTotal) {
removeEventListener(Event.ENTER_FRAME, loadComplete);
this.loaderInfo.removeEventListener(Event.COMPLETE, loadComplete);
this.loaderInfo.removeEventListener(ProgressEvent.PROGRESS, loadProgress);
gotoAndStop(2);
}
}
this.loaderInfo.addEventListener(Event.COMPLETE, loadComplete);
this.loaderInfo.addEventListener(ProgressEvent.PROGRESS, loadProgress);
function loadProgress(e:ProgressEvent):void {
preLoaderPercent = e.bytesLoaded / e.bytesTotal;
preloader.percentText.text = Math.ceil(preLoaderPercent * 100) + "%";
}
Basically this is a normal preloader with one addition.. On each frame (line 5) the function loadComplete is called. This function is SUPPOSED to be called when ProgressEvent.PROGRESS (line 19) is fired. Anyway, loadComplete (line 7) checks to see if the number of bytes loaded is the actual size of the file. This is basically a failsafe in the case that ProgressEvent.PROGRESS fails to fire!
What a weird bug.. Anyway, it works!
THANK YOU SOOOOOOOOOOO MUCH. I’ve been fiddling around with this for 3 days… I love you man.
hehe… No problem, this one saved me too. Really frustrating problem
Thank you so much. It took me hours of searching to find your solution and I am so greatful. I think I stumbled across it from a link on actionscript.org
The problem I was having – I hadn’t put in and event listener for ENTER_FRAME. It seems so obvious now.
Thank you
Thank you
Thank you
🙂
sure! This one drove me nuts for over a year when I first started learning flash. It seemed like an inconsistent problem so I never dug too deep for a solution.