# \[AS\] MP3 preloader and sound object

**URL:** <https://forum.kirupa.com/t/as-mp3-preloader-and-sound-object/10416>\
**Category:** flash\
**Created:** [December 31, 2002, 5:42pm UTC](https://forum.kirupa.com/t/as-mp3-preloader-and-sound-object/10416 "2002-12-31T17:42:44Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Nawak](https://avatars.discourse-cdn.com/v4/letter/n/e56c9b/32.png) [@Nawak](https://forum.kirupa.com/u/Nawak)\
**Post date:** [December 31, 2002, 5:42pm UTC](https://forum.kirupa.com/t/as-mp3-preloader-and-sound-object/10416/1 "2002-12-31T17:42:44Z")

</div>

Hi all,  
First time I post on this great website.

And… I have a problem… (no, really? hmmm… yes!)  
Excuse my broken English (I will try to be clear).

I’m creating a MP3 jukebox for my website, a Movie Clip (MC) named “miniJuke”. A function “preloadSound” is called, and should preload my sound object. But it doesn’t work : I get a NaN until the movie is fully loaded and then I get 100.

Here is my code :

> // the sound preloader function, where “pieceOfCake”  
> // is the path to find my MP3

function preloadSound(pieceOfCake){  
this.createEmptyMovieClip (“tempLoader”,this);

tempLoader.onEnterFrame = function() {  
var bl = mySound.getBytesLoaded();  
var bt = mySound.getBytesTotal();  
var p = isNaN(bt)?0 : Math.floor(bl\*100/bt);

if (p \< 100){  
\_root.miniJuke.percent.text = p;  
trace (“that works ?”);  
}else{  
mySound.start (0,99);  
mySound.isPlaying = true;  
tempLoader.removeMovieClip();  
}  
};  
mySound.loadSound(pieceOfCake,false);  
};

“percent” is a textfield, “mySound” is the sound object.  
The “trace” instruction (that works?) is never displayed, so, i think than “p” is never lower than “100”.

How to preload “mySound” correctly ?  
I really need help.  
Thx.

---

<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 31, 2002, 5:49pm UTC](https://forum.kirupa.com/t/as-mp3-preloader-and-sound-object/10416/2 "2002-12-31T17:49:01Z")

</div>

I apologize, I didn’t see ActionScript Forum.  
I copy this post.  
\<:}
