Preloader Infinity Problem in Flash AS3

Posted by admin in ActionScript 3, Flash, Tips

Some people have been facing the problem with Flash AS3 preloader. Loading Infinity% seems to be caused by a division by zero error. Below is a little change to the preloader codes which fixed the error. If you are using one of the flash files from flashmo.com, you may update your codes at the preloader scene (Shift + F2, or Main menu bar > Window > Other Panels > Scene). This is located on “actions” layer. You can edit through the actions panel (press F9). You may download 188 chrome black to see the real working example.

loading infinity

Actionscript:
  1. stop();
  2.  
  3. var loaded_bytes:Number;
  4. var total_bytes:Number;
  5. var percent:Number;
  6.  
  7. fm_bar.addEventListener( Event.ENTER_FRAME, load_progress );
  8.  
  9. function load_progress(e:Event):void
  10. {
  11. loaded_bytes = stage.loaderInfo.bytesLoaded;
  12. total_bytes = stage.loaderInfo.bytesTotal;
  13.  
  14. if( total_bytes == 0 ) total_bytes = 1;
  15.  
  16. percent = Math.round(loaded_bytes / total_bytes * 100);
  17. fm_bar.scaleX = percent * 0.01;
  18. loader_info.text = “Loading… “ + percent + “%”;
  19.  
  20. if( percent == 100 )
  21. {
  22. fm_bar.removeEventListener( Event.ENTER_FRAME, load_progress );
  23. play();
  24. }
  25. }

If you have any question, you may drop a comment below. Thanks!

UPDATES [22 September 2009]: I have found out that a few number of people got a preloader with incorrect loading percent while some people have infinity value problem. Below is the screenshot from David Kennedy’s GFX site while preloader is loading. I guess these 2 different problems seem to be because of different hosting platforms.

loading infinity 2