AS3 Preloader Listener not firing in Internet Explorer

Posted by
Ziwei

Posted On
Sep 17 2009 5:15 pm

The ProgressEvent and loaderInfo listener does not fire in IE 6 and 7 during the preloading of a swf’s main timeline. It works fine the first time thought, but upon subsequent reload of the page either through refreshing the page, or through accessing the page from some other webpage in the same browser window, the 2 listener simply refuse to function. Closing the browser and opening it again solved the problem but its not the solution to the problem.

  1.  
  2. function progressionListener(e:ProgressEvent):void {
  3. var percentage:Number = Math.floor( (e.bytesLoaded*100)/e.bytesTotal );
  4. trace (percentage);
  5. }
  6. //
  7. function completeListener(e:Event):void{
  8. trace("Loading Complete");
  9. }
  10. //
  11. this.loaderInfo.addEventListener(ProgressEvent.PROGRESS, progressionListener);
  12. this.loaderInfo.addEventListener(Event.COMPLETE, completeListener);

The above example will fail to work after the first loading in IE 6 and 7.

To overcome this problem, i forgo loader events and turn to enterframe events to grab the value of bytesLoaded on every pass of the enterframe event. Then i compare my bytesLoaded and bytesTotal to tell if my swf has finished loading before executing whatever that comes after that. This method is very AS 2.0 but at least it works. See the code below for the workaround.

  1.  
  2. function enterFrameListener(e:Event):void {
  3. var _bytesLoaded =this.loaderInfo.bytesLoaded;
  4. var _bytesTotal = this.loaderInfo.bytesTotal;
  5. var percentge:Number = Math.floor( (_bytesLoaded*100)/_bytesTotal );
  6. trace(percentage)
  7. //
  8. if (_bytesLoaded == _bytesTotal) {
  9. trace("Loading Complete");
  10. this.removeEventListener(Event.ENTER_FRAME,enterFrameListener);
  11. }
  12. }
  13. //
  14. this.addEventListener(Event.ENTER_FRAME,enterFrameListener);

One interesting point to note is that this problem seen to only occur in the main swf and not other files loaded into the main swf.

Comments ( 0 )

No Comment to “AS3 Preloader Listener not firing in Internet Explorer” so far

Post Comment

Remember! Spamming is for losers

Trackback from your own website