Quick question on preloaders

well i was wondering if there was anything wrong with this code. I used the tut that Upu put in this forum, but i changed it a little…i was wondering if my substituting the “remaining” variable at the end would change anything. I can’t really test this cuz i only have a couple MCs and the file is only 6 KB so it loads too fast for me to see if the script is working…

total = getBytesTotal()/1000;
loaded = getBytesLoaded()/1000;
percentage = (loaded/total)*100;
remaining = total-loaded;
setProperty (“bar”, _xscale, percentage);
if (remaining<=0) {
gotoAndPlay (3);
}

all this is in the first frame w/ the loop in the second frame

just realize that this probly should have gone in Upu’s preloaders rererevisted post, sorry

I think that should work… though I still think that the !=0 is necessary. If the total and the loaded, are both equal to 0 at once, which sometimes happens in the first second of a movie loading, you’re script will make it play, even if it isn’t ready to be played.

My suggestion would be this

total = getBytesTotal()/1000;
loaded = getBytesLoaded()/1000;
percentage = (loaded/total)*100;
remaining = total-loaded;
setProperty (“bar”, _xscale, percentage);
if (remaining<=0&&loaded!=0) {
gotoAndPlay (3);
}

this will ensure that it will not play unless something is loaded.

ok, i was just trying to use somehting htat i understood more fully, but you explained the != so i’ll use that…thanks upu

** thanks upu, it worked perfectly.**

another question upu…is there anyway that i can display the numbers as whole numbers? and not that 1.000024830929349323240438209375814702 that shows up?

Yes… but I haven’t gotten that working yet… Suprabeener has an explination somewhere, I’ll look for it.

ok thanks up.

If you want to see your preloader, hit ctrl + enter, then hit ctrl + enter again. ( Do it twice). You will be able to see your preloader.

Math.round(num);

or .ceil or .floor

thanks supra…

if this is my code…

total = getBytesTotal()/1000;
loaded = getBytesLoaded()/1000;
percentage = (loaded/total)*100;
remaining = total-loaded;
setProperty (“bar”, _xscale, percentage);
if (loaded>=total && total != 0) {
gotoAndPlay (3);
}

where do i put that?

which variables do you want to round?

oh sorry…i want to round percentage.

percentage = Math.round((loaded/total)*100);

kool thanks!