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 LoaderInfo object 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.