# mp3 preloader code check please

**URL:** <https://forum.kirupa.com/t/mp3-preloader-code-check-please/96962>\
**Category:** Uncategorized\
**Created:** [December 15, 2003, 10:24pm UTC](https://forum.kirupa.com/t/mp3-preloader-code-check-please/96962 "2003-12-15T22:24:29Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![crapboyjr](https://avatars.discourse-cdn.com/v4/letter/c/bbe5ce/32.png) [@crapboyjr](https://forum.kirupa.com/u/crapboyjr)\
**Post date:** [December 15, 2003, 10:24pm UTC](https://forum.kirupa.com/t/mp3-preloader-code-check-please/96962/1 "2003-12-15T22:24:29Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [December 15, 2003, 10:40pm UTC](https://forum.kirupa.com/t/mp3-preloader-code-check-please/96962/2 "2003-12-15T22:40:26Z")

</div>

> \*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 😉  
> 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 🙂

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).

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [December 15, 2003, 11:08pm UTC](https://forum.kirupa.com/t/mp3-preloader-code-check-please/96962/3 "2003-12-15T23:08:09Z")

</div>

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.
