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:
- stop();
- var loaded:Number;
- var percent:Number;
- fm_bar.addEventListener( Event.ENTER_FRAME, load_progress );
- function load_progress(e:Event):void
- {
- loaded = stage.loaderInfo.bytesLoaded / stage.loaderInfo.bytesTotal;
- percent = Math.round(loaded * 100);
- fm_bar.scaleX = loaded;
- loader_info.text = “Loading… “ + percent + “%”;
- if( percent == 100 )
- {
- fm_bar.removeEventListener( Event.ENTER_FRAME, load_progress );
- play();
- }
- }
UPDATES [15 September 2009]: Please read Preloader Infinity Problem in Flash AS3








I have a flashmo template in AS3. I need to add a geturl button. Every time I try the swf just flies through all its frames.
Help.
jeff: i’ve been doing some looking around regarding geturl as well, and it looks like it’s been depricated in AS3. There’s a URLRequest that seems to have replaced it. Sorry I don’t know more, but maybe that will point you in the right direction???
[...] 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 [...]
Hi, Dloaded the above sample at http://www.flashmo.com/preview/flashmo_124_delicious
Opened the FLA and cannot find the preloader AS code. Any ideas where it is? I see all the other code. Please help!
Dear Min Thu,
let me thank you for this little preloader: it’s really a smart and effective solution! I’m quite new at Flash, but I found it very practical and I make it working in a so short time!
However I experienced a little problem and I’d like you to give me your opinion about it. First of all, let me tell that I’ve put the preloader even in the “main.fla” of my project, and in the secondary movieclip it loads when the pages are choosen. Obviously, in every case I put the preloader in the first scene (of two) of the .fla.
But, while it works in the main .fla (I can see the progress bar going regularly to the completion), the other movieclips (corresponding each to a different .fla file) show the bar only when it’s already completed, then pass to the main scene.
Do you have any idea about this behaviour? Maybe the loading of file into a main.fla makes unapplicable this preloading solution?
Thanks for your attention. I hope to ear you soon.
Regards
basanet