Simple Preloader in ActionScript 3

Posted by admin in ActionScript 3, Flash

It is just a few number of lines for making a simple preloader. You may download this file as an example. Below codes are located in actions layer of preloader scene.

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

UPDATES [15 September 2009]: Please read Preloader Infinity Problem in Flash AS3