# Combo Box With Mp3 player problem

**URL:** <https://forum.kirupa.com/t/combo-box-with-mp3-player-problem/219545>\
**Category:** flash\
**Created:** [March 17, 2007, 6:37pm UTC](https://forum.kirupa.com/t/combo-box-with-mp3-player-problem/219545 "2007-03-17T18:37:05Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![kwick](https://avatars.discourse-cdn.com/v4/letter/k/e9c0ed/32.png) [@kwick](https://forum.kirupa.com/u/kwick)\
**Post date:** [March 17, 2007, 6:37pm UTC](https://forum.kirupa.com/t/combo-box-with-mp3-player-problem/219545/1 "2007-03-17T18:37:05Z")

</div>

I tried adding the combo box component to my mp3 player but ran into a little problem. When i choose an option from my combo list it just counts +1 in my song array. I figured the problem was in my playSong function but I tried changing some of that code around and it didn’t seem to help matters. Anyone got any tips or answers I’d love to hear them.

**songs.xml**

\<?xml version=“1.0” encoding=“iso-8859-1”?\>  
\<songs\>  
\<song url=“changes.mp3” artist=“Tupac Shakur” track=“Changes” time=“269” /\>  
\<song url=“hipHopHooray.mp3” artist=“Naughty By Nature” track=“Hip Hop Hooray” time=“263” /\>  
\<song url=“hypnotize.mp3” artist=“Notorius B.I.G” track=“Hypnotize” time=“243” /\>  
\<song url=“firstOfTheMonth.mp3” artist=“Bone Thugs And Harmony” track=“First Of Da Month” time=“314” /\>  
\</songs\>

**Song.as**

class Song{  
public var earl:String;  
public var artist:String;  
public var track:String;  
public var uime:Number;

```
public function Song(e:String, a:String, t:String, u:Number){
    earl = e;
    artist = a;
    track = t;
    uime = u;
}

```

}  
\*\*[U]

mp3Player.as[/U]\*\*

\_global.styles.ComboBox.setStyle(“backgroundColor” , 0x000000);  
\_global.styles.ComboBox.setStyle(“color” , 0xcccccc);

//Setup Sound Object  
var s:Sound = new Sound();  
s.onSoundComplete = playSong;  
s.setVolume(75);

//Array of songs sa=Song Array  
var sa:Array = new Array();

// Currently Playing Song CPS= currently playing song  
var cps:Number = -1;

//Position of music  
var pos:Number;

//Load in XML songs

var xml:XML = new XML();  
xml.ignoreWhite = true;  
xml.onLoad = function() {  
var nodes:Array = this.firstChild.childNodes;  
for(var i=0;i\<nodes.length;i++)  
{  
mp3List.addItem(nodes\*.attributes.track , nodes\*.attributes.url);  
sa.push(new Song(nodes\*.attributes.url, nodes\*.attributes.artist, nodes\*.attributes.track, nodes\*.attributes.time));  
}  
playSong(mp3List.getItemAt(0).data);  
mp3List.selectedIndex=0;  
};

var songList:Object = new Object();

songList.change = function(){  
playSong(mp3List.getItemAt(mp3List.selectedIndex).data);  
trace(“Index Number” +(mp3List.selectedIndex));

}

mp3List.addEventListener(“change”,songList);

xml.load(“songs.xml”);

//Play the MP3 File  
function playSong():Void{  
s = new Sound();  
s.onSoundComplete = playSong;  
s.setVolume(dist);  
mute.gotoAndStop(‘on’);  
if(cps == sa.length-1){  
cps=0;  
s.loadSound(sa[cps].earl,true);  
}else{  
s.loadSound(sa[++cps].earl,true);  
}  
trackInfo.text = sa[cps].artist + " - "+ sa[cps].track;  
playPause.gotoAndStop(‘pause’);

}

function prevSong():Void {  
s = new Sound();  
s.onSoundComplete = playSong;  
if (cps == 0) {  
cps = sa.length - 1;  
s.loadSound(sa[cps].earl, true);  
} else {  
s.loadSound(sa[–cps].earl, true);  
}  
trackInfo.text = sa[cps].artist + " - " + sa[cps].track;  
playPause.gotoAndStop(“pause”);  
}

//Volume  
var dist:Number = 75;  
volScrub.\_xscale = dist;  
volPercent.text = volScrub.\_xscale;  
volBotton.onPress = function(){  
adjustSound();  
this.onMouseMove = adjustSound;  
}

volBotton.onRelease = volBotton.onReleaseOutside = function (){  
delete this.onMouseMove;  
volScrub.gotoAndStop(1);  
}

function adjustSound() {  
volScrub.gotoAndStop(2);  
dist = ((\_root.\_xmouse-volBotton.\_x)/volBotton.\_width)\*100;  
if (dist\>=0 && dist\<=100) {  
volScrub.\_xscale = dist;  
s.setVolume(dist);  
volPercent.text = Math.round(volScrub.\_xscale);  
//un comment to get the vol numbers moving  
//volPercent.\_x = Math.round(\_root.\_xmouse);  
}  
}

//Pauses the music  
function pauseIt():Void{  
pos = s.position;  
s.stop();  
}

//Plays the music  
function unPauseIt():Void{  
s.start(pos/1000);  
}

//Music Controls

//Play Pause toggle  
playPause.onRollOver = function(){  
if(this.\_currentframe == 1)this.gotoAndStop(‘pauseOver’);  
else this.gotoAndStop(‘playOver’);  
}

playPause.onRollOut = playPause.onReleaseOutside = function(){  
if(this.\_currentframe == 10)this.gotoAndStop(‘pause’);  
else this.gotoAndStop(‘play’);  
}

playPause.onRelease = function(){  
if(this.\_currentframe == 10)  
{  
this.gotoAndStop(‘playOver’);  
this.\_parent.pauseIt();  
}else{  
this.gotoAndStop(‘pauseOver’);  
this.\_parent.unPauseIt();  
}  
}

//Mute volume on and off toggle  
mute.onRollOver = function(){  
if(this.\_currentframe == 1)this.gotoAndStop(‘onOver’);  
else this.gotoAndStop(‘offOver’);  
}

mute.onRollOut = mute.onReleaseOutside = function(){  
if(this.\_currentframe == 10)this.gotoAndStop(‘on’);  
else this.gotoAndStop(‘off’);  
}

mute.onRelease = function(){  
if(this.\_currentframe == 10)  
{  
this.gotoAndStop(‘offOver’);  
s.setVolume(0);  
}else{  
this.gotoAndStop(‘onOver’);  
s.setVolume(75);  
}  
}

//Next Button  
next.onRollOver = function(){  
this.gotoAndStop(‘nextOver’);  
}

next.onRollOut = next.onReleaseOutside = function(){  
this.gotoAndStop(‘next’);  
}

next.onRelease = function(){  
this.\_parent.playSong();

}

//Previous Button  
prev.onRollOver = function(){  
this.gotoAndStop(‘nextOver’)  
}

prev.onRollOut = prev.onReleaseOutside = function(){  
this.gotoAndStop(‘next’);  
}

prev.onRelease = function(){  
this.\_parent.prevSong();  
}

//Audio Loader Bar / Scrubber  
var audioInterval = setInterval(audioStatus,100);  
var amountLoaded:Number;

function audioStatus(){  
amountLoaded = s.getBytesLoaded()/s.getBytesTotal()  
loader.loadbar.\_width = amountLoaded \* 72  
var scrubPos = s.position/(sa[cps].uime \* 1000) \* 72  
loader.scrub.\_x = scrubPos  
}

//Scrub Drag

loader.scrub.onPress = function():Void{  
pauseIt();  
clearInterval(scrubPos);  
clearInterval(audioInterval);  
loader.scrub.startDrag(false, 0, this.\_y,72, this.\_y);  
}

loader.scrub.onRelease = loader.scrub.onReleaseOutside = function():Void{  
pos = ((loader.scrub.\_x/72) \* (sa[cps].uime))  
scrubPos = ((pos / (sa[cps].uime)) \* 72)

```
if (((s.getBytesLoaded/s.getBytesTotal) * 72) &lt; scrubPos){
    pos = ((s.duration / 1000) / (sa[cps].uime) * 72)
    scrubPos = (((s.getBytesLoaded/s.getBytesTotal) * 72))
    
    unPauseIt();
    loader.scrub.stopDrag();
    audioInterval = setInterval(audioStatus,100);
    audioStatus();
}else{
    s.start(pos);
    loader.scrub.stopDrag();
    audioInterval = setInterval(audioStatus,100);
    audioStatus();
}

```

}
