mp3 preloader code check please

Sorry for cross-posting, but I’m in bit of a jam.

I’m trying to preload a dynamic mp3 and show the percentage loaded as a number and a graphic bar. But it’s not working.

The following code is on the the movie clip that the mp3 is being loaded into.


onClipEvent (load) {
mySound = new Sound();
mySound.loadSound(“music.mp3”, false);
}

onClipEvent (enterFrame) {
downloaded = mySound.getBytesLoaded();
total = mySound.getBytesTotal();
percent -= (percent-((downloaded/total)100)).25;
per = int(percent);
percentage = per+"%";
loadBar._width = per;

if (percent>99) {
_root.gotoAndPlay(“intro”);
}
}


Thanks.

*Originally posted by crapboyjr *
percent -= (percent-((downloaded/total)100)).25;
per = int(percent);
percentage = per+“%”;
loadBar._width = per;
These lines look odd to me but maybe it’s just me :wink:
You want to calculate the percent loaded but the first line got’s nothing to do with percents…
I think the following could help you out:

percent = downloaded / total;
// this isn’t percent either but I don’t know the English word for it
percentage = Math.round(percent * 100) + “%”;
loadBar._width = percent * totalWidthOfBar;

You need to replace the totalWidthOfBar with the acording variable :slight_smile:

Oh, by the way. This also means that you need to change your check for when to start. When (percent == 1) the movie is fully loaded (as it’s the actual percent divided by 100).

Thanks for your help. But I have to admit, I’m still a newbie at this. I’ll do as you suggested. But I can’t help feeling a little lost.