Advanced Preloader Problems... I want to smash my computer

I have spent hours trying to figure out what is wrong with my preloader, and I have no idea. I don’t think there is anything wrong with it, I’m patient, but I’ve had enough!
please help me!

ok heres the deal. I have a a movie clip called “preloader”.

it consists of another movie clip symbol called “loader” which is a 100 frame long clip of a shape tweened bar that gradually fills. This movie clip is inside “preloader” and the instance is named “loader”.

This is the script attached to frame 1 of “preloader” =

loadedbytes = _parent.getBytesLoaded();
totalbytes = _parent.getBytesTotal();
loadedkbytes = Math.round(loadedbytes/1024)+" Kb";
totalkbytes = Math.round(totalbytes/1024)+" Kb";
if (loadedbytes == totalbytes) {
frame = Math.round(loadedbytes/(totalbytes/100))+"%";
loadingbar = Math.round(loadedbytes/(totalbytes/100));
tellTarget ("loader") {
    gotoAndStop (loadingbar);
if (loadingbar == 100) {
    tellTarget ("loader") {
        gotoAndStop (100);

frame 2 of “preloader” just has a gotoAndPlay (1) in it.

“loading bar” gives a number between 1 and 100 and this should correspond to “loader” and thus give the effect of a gradually filling bar.
I attach “preloader” to Frame 1 of my movie and add a stop frame.

when online the bar just goes round and round - it doesn’t scale. I have tried adding stop frames in “loader” but to no avail.

I have attached the file, Please help me… I just can"t figure out why it doesn’t work.

Please note - THIS IS A FLASH 5 (FIVE) FILE.
Thanks in advance.

I ran into the same problem and found that it was solved by not trying to round down the variables. If you need the variables for text fields, try setting a new variable equal to the rounded down version of the old variable… but keep the old variable unaltered for the math part of the script.

I think that will solve your problem.

Hey RageWolf,

There are a couple of problems that I can see. First off, you have an if statement but there doesn’t seem to be an Else action you need to give flash another option by telling it to look there if the first isn’t true. Second I don’t see the why you are using the second if statement, the loader should scale and end up at the 100th frame anyways.

I have a suggestion, you might want to try using an enterFrame preloader. They only use one frame and you can scale the bar using actionscript.

onClipEvent (enterFrame) {
if (_root.getBytesLoaded() > 0 && _root.getBytesLoaded() == _root.getBytesTotal()) {
} else {
load_bytes = _root.getBytesLoaded();
total_bytes = _root.getBytesTotal();
percent = int(load_bytes/total_bytes * 100);
percentoutput = int(load_bytes/total_bytes * 100);
_root.preloader._xscale = percent;
_root.preload.text = percentoutput + “%”;

This way you can just create one preloader bar movieclip and then it scales accordingly.

Hope this helps


He doesn’t need an else statement. The “if” breaks it by sending the play head to frame 100… the loop sends it back to check again… As far as I see there is no scaling going on in that code, but if you see it in the FLA I’ll have to take your word for it. You’re correct that there is no reason to use both methods at the same time… that will just screw things up.

I was wrong about the answer anyway… we can see that he’s using the origional numbers to do the math, and new vars for whatever text fields he has.

I still think that his origional code would be fine with minor alterations
I always add in the (&&total!=0). It’s important. for a split second when any movie loads, totalBytes reads 0. If you leave that off, 9 out of ten times, on a slow enough computer, you’ll have an ineffective preloader.

loadedbytes = _parent.getBytesLoaded();
totalbytes = _parent.getBytesTotal();
loadedkbytes = Math.round(loadedbytes/1024)+" Kb";
totalkbytes = Math.round(totalbytes/1024)+" Kb";
if (loadedbytes == totalbytes&&totalbytes!=0) {
frame = Math.round(loadedbytes/(totalbytes/100))+"%";
loadingbar = Math.round(loadedbytes/(totalbytes/100));
loader.gotoAndStop (loadingbar);
if (loadingbar == 100) {
    loader.gotoAndStop (100);

I also switched the tellTarget notation to Flash 5.0 OOP syntax.

I find this last if statement to be redundant, and I would take it out. The loader is already going to and stoping at 100 when the movie loads 100% of itself. There’s no need to check it except perhaps during test mode to see what is going on in there.

I do recomend the method that Iceman offers though… If you create a movie clip that is a square of fill, you can simply scale that bar using


The nature of creating 100 frames of fill, tweened, is going to produce a much higher file size than the scaling method, AND the scaling method requires less work.

Hi, Thanks for posting.

I am aware I could use an onclipevent loader (as I did for my Portfolio with your help iceman) or could use x_scale for the bar, however with x_scale I found the bar grows bothways away from the center point - I havn’t full experimented with it, and I’m sure that can be corrected if desired by repositioning it with script. I am aware its fairly straight forward to do, but like I said I think my script is very nearly correct so it may be simpler just to correct my original code :stuck_out_tongue:
Also, I would also like to know WHY it doesn’t work, so I can learn from my mistake(s).

The size this method generates is not really and issue atall, it adds less that 1K to my file size with the 100frame shape tween.

I think originally I tried without the last If statement - as you say, its redundant - I had another If statement that flash didn’t seem to ackowledge so added the if statement there as a test, deleted and added bits but forgot to remove it when I copied from the code to paste here.
Even so I don’t believe removing it would solve the problem.
If you download the file you get a much clearer picture of what the problem is.
I will remove the statement 1st thing tommorow to ensure its not the problem but I’m pretty sures it not.
Right now its 6.10am, and hey - even Insomniacs need sleep :bandit:

In that case I’d add just that


to the if statement.

As for the bar growing either direction. That is solved by double clicking until you are at the fill itself. Then move the fill so that it’s left edge is flush with the center point of the clip.

Hi, I still couldn’t get it working.

In the end I just alterred the code slightly and used an x_scale preloader it works just as well. I didn’t realise positioning the loading bar was as easy as it is.

If anybody knows what the problem with the original is I would be interested to know, if you can’t be bothered to take a look don’t worry too much!

thanks to all those who replied.