Flash Event.COMPLETE sometimes doesn’t fire in Firefox
I have run into some strange behaviour in Flash and Firefox recently. We had a Flash movie (AS3) that loads up, in its document classes constructor it sets a few event handlers on loaderInfo:
this.loaderInfo.addEventListener(Event.COMPLETE, loadComplete);
this.loaderInfo.addEventListener(ProgressEvent.PROGRESS, progress);
this.loaderInfo.addEventListener(IOErrorEvent.IO_ERROR, ioErrorHandler);
this.loaderInfo.addEventListener(HTTPStatusEvent.HTTP_STATUS, httpStatusHandler);
The problem taht seemed to be happening (most of the time, ie not 100% reproducible) was that the movie was failing to fire the Event.COMPLETE event handler. After some browsing I found Marguera’s post which suggests adding another event handler, Event.INIT and pointing it at the same handler as the Event.COMPLETE event.
this.loaderInfo.addEventListener(Event.INIT, loadComplete);
Then updating the loadComplete method to check if we had actually finished loading, if so remove the event handlers and carry on setting up the movie.
private function loadComplete(e:Event):void {
if(this.loaderInfo.bytesLoaded == this.loaderInfo.bytesTotal){
this.loaderInfo.removeEventListener (Event.INIT, loadComplete);
this.loaderInfo.removeEventListener (Event.COMPLETE, loadComplete);
// Finish setting up the movie
// ...
}
}
This approach fixed our issue, and hopefully this post will point anyone else seeing similar irregularities in the right direction. The Flash documentation states that the Event.INIT event is fired when:
- All properties and methods associated with the loaded object and those associated with the
LoaderInfoobject are accessible. - The constructors for all child objects have completed.
And that the init event always precedes the complete event. That wasn’t what we were seeing in practice, as our complete event was failing to fire completely. hth.
Category: Adobe, development, flash, web 8 comments »
January 21st, 2010 at 12:16 pm
Ryan you genius! I just came across this problem doing a big load queue for Numiko 2010. Searched and got your labs entry. So it came full circle. Yeah worked fine when i tested it in Chrome. Does a funny thing in Firefox whereby if i open up a new tab the images all load in instantly. It’s as if all the Event.COMPLETE listeners get called once i browse off the page.
Anyway i hope this helps someone else other than the folks here!
February 8th, 2010 at 1:09 pm
Or don’t use the wmode parameter unless its neccessary in which case apply this fix
February 11th, 2010 at 12:54 am
thanks for sharing.
saved me a couple of hours at that least!!!
I owe you beer.
April 20th, 2010 at 7:42 am
Wow, it’s amazing how sometimes you just stumble against the perfect answer. Thanks heaps for contributing.
You wouldn’t happen to know anything about FBML Briding between JS/Flash? Basically the SWF is calling a JS function using callFBJS. It works well in all browsers, except Firefox…
If you happen to know of any known issues, give us a shout.
Cheers for your help!
Sebastian.
December 8th, 2010 at 8:22 pm
WOW thank you!! After a couple of hours struggling what the f*** was going on, I googled the problem and found your solution. I’m eager to try it, it must work!
Thanks!
March 10th, 2011 at 2:46 am
Thx a lot, U saved me a bunch of work !
U RuleZ !
Greg
August 20th, 2011 at 12:32 am
A very big thank you for this. In PC/FF3, when I did not have wmode = transparent, everything was fine. However, with wmode = transparent, Event.COMPLETE was not firing. I was having major problems determining what the heck the issue was. I added the Event.INIT line above it, and now it is working, even with FF3 + wmode = transparent.
THANK YOU for this solve! May you continue to receive good karma for sharing it for years to come.
February 25th, 2012 at 4:19 pm
Just wanna say thanks, you saved my day!