# XML MP3 player help with random selection corresponding to buttons

**URL:** https://forum.kirupa.com/t/xml-mp3-player-help-with-random-selection-corresponding-to-buttons/194322
**Category:** flash
**Created:** [July 22, 2006, 5:14am UTC](https://forum.kirupa.com/t/xml-mp3-player-help-with-random-selection-corresponding-to-buttons/194322 "2006-07-22T05:14:08Z")
**Posts on this page:** 1
**Page:** 1

<div class="post-metadata">

### Author: ![learntoreed](https://avatars.discourse-cdn.com/v4/letter/l/ecb155/32.png) [@learntoreed](https://forum.kirupa.com/u/learntoreed)
#### Post date: [July 22, 2006, 5:14am UTC](https://forum.kirupa.com/t/xml-mp3-player-help-with-random-selection-corresponding-to-buttons/194322/1 "2006-07-22T05:14:08Z")

</div>

So this is a bit of an unusual problem. I am building an XML based MP3 player. I’m fairly inexperienced with Actionscript, so I copied the code from a friends music player.

The code works great - but the player I am making also has ‘highlightable’ buttons for each song. It is easy enough to get these buttons to highlight when clicked. However, when first opening the player, it opens a song randomly but obviously the song’s button is not highlighted.

Is there a way to have the player highlight the corresponding button when opening?

The cop-out solution would be to just have it open the first song every time. But the random selection could really make returning to the site a new experience.

Here is the code I’m using for the XML player. Does anyone have any suggestions?

playlist = new XML();  
playlist.ignoreWhite = true;  
playlist.onLoad = function(success) {  
if (success) {  
\_global.songname = [];  
\_global.songfile = [];  
for (var i = 0; i\<playlist.firstChild.childNodes.length; i++) {  
\_global.songname\* = playlist.firstChild.childNodes\*.attributes.name;  
\_global.songfile\* = playlist.firstChild.childNodes\*.attributes.file;  
}  
}  
\_root.createEmptyMovieClip(“sound\_mc”, 1);  
\_root.sound\_mc.sound\_obj = new Sound();  
\_global.song\_nr = random(songfile.length);  
\_root.sound\_mc.songStarter(songfile[song\_nr], songname[song\_nr]);  
};  
MovieClip.prototype.songStarter = function(file, name) {  
this.sound\_obj.loadSound(file, true);  
this.onEnterFrame = function() {  
if (this.sound\_obj.position\>0) {  
delete this.onEnterFrame;  
this.\_parent.display\_txt.text = name;  
} else {  
this.\_parent.display\_txt.text = “loading…”;  
}  
};  
this.sound\_obj.onSoundComplete = function() {  
(song\_nr == songfiles.length-1) ? \_global.song\_nr=0 : \_global.song\_nr++;  
\_root.sound\_mc.songStarter(songfiles[song\_nr], songname[song\_nr]);  
};

that’s it… thank you,

Aaron :luigi:
