# Preloader Music

**URL:** <https://forum.kirupa.com/t/preloader-music/7925>\
**Category:** Uncategorized\
**Created:** [November 10, 2002, 3:23pm UTC](https://forum.kirupa.com/t/preloader-music/7925 "2002-11-10T15:23:11Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![HCLPfan](https://avatars.discourse-cdn.com/v4/letter/h/d9b06d/32.png) [@HCLPfan](https://forum.kirupa.com/u/HCLPfan)\
**Post date:** [November 10, 2002, 3:23pm UTC](https://forum.kirupa.com/t/preloader-music/7925/1 "2002-11-10T15:23:11Z")

</div>

How do I add music to a preloader? i tried putting the music on the same frame as the preloader and it didn’t work… and i tried putting it on a new layer in the same frame # as the preloader but satill doesn’t work…

any suggestions??

---

<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:** [November 10, 2002, 6:23pm UTC](https://forum.kirupa.com/t/preloader-music/7925/2 "2002-11-10T18:23:38Z")

</div>

```php
function loadSound() {
	
	// create a holder for the sound, a instance of the sound object, and load in the sound file
	_root.createEmptyMovieClip("soundHolder", 1);
	userSound = new Sound(soundHolder);
	userSound.loadSound(urSoundPath, true);
	
	// get the sound length
	soundLength = formatTime(userSound.duration)
	
	// set the textfields
	_root.min.text = soundLength.minutes;
	_root.seconds.text = soundLength.seconds;
	
	notDone == true;
	
	_root.onEnterFrame = function () {
	
		percentage = userSound.getBytesLoaded() / userSound.getBytesTotal() * 100;
		
		if (percentage > 5 && notDone == true) {
			notDone = false;
			userSound.start();
		}
		
		if (percentage >= 100) _root.onEnterFrame = undefined;
		
		percentageBar._xscale = percentage;
	
	}
	
}

function formatTime(milliseconds) {
	// find minutes expressed in decimal
	minutes = new Number((milliseconds/1000)/60);
	
	// split the minutes to find the minute (str[0]) and the seconds expressed in decimal
	str = new String(minutes.toString());
	str = str.split(".");
	
	// return an object with minutes and seconds properties
	// to find minutes, multiply the seconds expressed in decimal to find the seconds in integer format
	return {minutes:str[0], seconds: Math.round(("." + str[1])*60)};
}

```

This would work!

yours,  
–h88

---

<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:** [November 10, 2002, 6:24pm UTC](https://forum.kirupa.com/t/preloader-music/7925/3 "2002-11-10T18:24:57Z")

</div>

Using the values from the getBytesTotal and getBytesLoaded method you can quickly create a sound buffer, so your sound won’t start playing until enough of the sound has loaded
