Please help loadSound Randomly on initial start

Hey all,

I have an MP3 player that i want to put on my site, I would like to have the first song be played randomly so it dosent grow stale.

Here is the A.S. i’m using.

Any ideas?

var musicFolderName:String = "music/";
var curTrackNum:Number = 0;
var curPlaybackPos:Number;
var soundDLPercent:Number;
var mySound:Sound;
var trackInfoArray:Array;
var trackInfoTracker:Number = 0;
var infoChangerInterv:Number;
var soundDLDuration:Number;
var curTrackVolume:Number = 85;

this.trackInfo.autoSize = "center";
this.volumePercentText.autoSize = "left";
this.volumePercentText._visible = false;

function playMusicFunc() { 
    mySound = new Sound ();
    
    mySound.onSoundComplete = function() {
        if (curTrackNum == (myLV.totalTracks - 1)) {
            curTrackNum = 0;
            playMusicFunc();
        } else {
            curTrackNum ++;
            playMusicFunc();
        }
    }
    
    mySound.loadSound((musicFolderName + "mp3-" + curTrackNum + ".mp3"), true);
    mySound.setVolume(curTrackVolume);
    volumeControl.volumeMask._width = curTrackVolume/2;
    showDownloadProgress ();
    showPlaybackProgress();
    
    mySound.onID3 = function() {
        trackInfoArray = new Array();
        trackInfoArray[0] = "Track : " + (curTrackNum + 1) + " of " + myLV.totalTracks;
        trackInfoArray[1] = "Artist : " + mySound.id3.TPE1;
        trackInfoArray[2] = "Track : " + mySound.id3.TIT2;
        
        clearInterval(infoChangerInterv);
        infoChangerInterv = setInterval(infoChanger, 5000);
        infoChanger();
    }
    
    
    if (curTrackNum == (myLV.totalTracks - 1)) {
        nextTrack.enabled = false;
        nextTrack._alpha = 50;
    } else {
        nextTrack.enabled = true;
        nextTrack._alpha = 100;
    }
    
    if (curTrackNum == 0) {
        prevTrack.enabled = false;
        prevTrack._alpha = 50;
    } else {
        prevTrack.enabled = true;
        prevTrack._alpha = 100;
    }
}

function infoChanger() {
    trackInfo.text = trackInfoArray[trackInfoTracker];
    
    if (trackInfoTracker == (trackInfoArray.length - 1)) {
        trackInfoTracker = 0;
    } else {
        trackInfoTracker++;
    }
}

function restartTrackInfo() {
    infoChangerInterv = setInterval(infoChanger, 5000);
    infoChanger();
}

var myLV:LoadVars = new LoadVars();
myLV.load("total_tracks.txt");
myLV.onLoad = function(success) {
        if (success) {
            playMusicFunc();
        }
    }

// ___________[play/pause]____________ \\

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");
        curPlaybackPos = mySound.position;
        mySound.stop();
        clearInterval(infoChangerInterv);
        trackInfo._alpha = 50;
    }
    else
    {
        trackInfo._alpha = 100;
        restartTrackInfo();
        this.gotoAndStop("pauseOver");
        mySound.start((curPlaybackPos/1000), 9999);
    }
}

// ___________[/play/pause]____________ \\

// ___________[next track/previous track]____________ \\
this.nextTrack.onRelease = function() {
    trackInfo.text = trackInfoArray[0];
    playPause.gotoAndStop("pause");
    mySound.start((curPlaybackPos/1000), 9999);
    trackInfo._alpha = 100;
    if (curTrackNum < (myLV.totalTracks - 1)) {
        curTrackNum++;
        playMusicFunc();
        }
    }
this.prevTrack.onRelease = function() {
    trackInfo.text = trackInfoArray[0];
    playPause.gotoAndStop("pause");
    mySound.start((curPlaybackPos/1000), 9999);
    trackInfo._alpha = 100;
    if (curTrackNum > 0) {
        curTrackNum--;
        playMusicFunc();
        }
}
// ___________[/next track/previous track]____________ \\

// ___________[mute]____________ \\
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("on");
        mySound.setVolume(curTrackVolume=0);
        volumeControl.volumeMask._width = curTrackVolume/2;
    }
    else
    {
        this.gotoAndStop("onOver");
        mySound.setVolume(curTrackVolume=85);
        volumeControl.volumeMask._width = curTrackVolume/2;
    }
}
// ___________[/mute]____________ \\

// ___________[download progress]____________ \\
function showDownloadProgress () {
    progressBar.onEnterFrame = function() {
        var soundLoaded:Number = mySound.getBytesLoaded();
        var soundTotal:Number = mySound.getBytesTotal();
        soundDLPercent = ((soundLoaded/soundTotal)*100);
        progressBar.barTop._width = soundDLPercent;
        if (soundLoaded == soundTotal) {
            delete progressBar.onEnterFrame;
        }
    }
}
// ___________[/download progress]____________ \\

// ___________[playback progress]____________ \\

function showPlaybackProgress() {
    progressBar.playbackBarMask.onEnterFrame = function() {
        soundDLDuration = ((mySound.duration/soundDLPercent) * 100);
        progressBar.playbackProgSlider._x = ((mySound.position/soundDLDuration) * 100);
        progressBar.playbackBarMask._width = ((mySound.position/soundDLDuration) * 100);
    }
}
// ___________[/playback progress]____________ \\

// ___________[fast-forward/rewind]____________ \\
this.progressBar.barTop.onPress = function() {
    this.onEnterFrame = function() {
        if (_root._xmouse >= progressBar._x && _root._xmouse <= (progressBar._x + progressBar.barTop._width)) {
            var soundGoTo:Number = Math.round(_root._xmouse - progressBar._x);
            mySound.start(((soundDLDuration/1000)*(soundGoTo/100)));
            clearInterval(infoChangerInterv);
            trackInfo._alpha = 50;
            }
        }
}

this.progressBar.barTop.onRelease = function() {
    delete progressBar.barTop.onEnterFrame;
    restartTrackInfo();
    trackInfo._alpha = 100;
}
this.progressBar.barTop.onReleaseOutside = function() {
    delete progressBar.barTop.onEnterFrame;
    restartTrackInfo();
    trackInfo._alpha = 100;
}
// ___________[/fast-forward/rewind]____________ \\

// ___________[volume control]____________ \\
this.volumeControl.onPress = function() {
    this.onEnterFrame = function() {
        if (_root._xmouse >= volumeControl._x && _root._xmouse <= (volumeControl._x + volumeControl._width)) {
            curTrackVolume = Math.round((_root._xmouse - volumeControl._x) *2);
            mySound.setVolume(curTrackVolume);
            volumeControl.volumeMask._width = curTrackVolume/2;
            volumePercentText.text = curTrackVolume + "%";
            volumePercentText._visible = true;
            mute.gotoAndStop("on");
            }
    }
}

this.volumeControl.onRelease = function() {
    delete volumeControl.onEnterFrame;
    volumePercentText._visible = false;
}

this.volumeControl.onReleaseOutside = function() {
    delete volumeControl.onEnterFrame;
    volumePercentText._visible = false;
}

// ___________[/volume control]____________ \\

Hi,

I have tried to figure out your explanation without any luck, this is currently playing one song after the other and I would like to have it done randomly so when the user open is browser it will automatically choose a song that is in my xml list. Thanks in advance for the great help.

dd = new Sound();
mm = new Array();
// XMl code for loading URLs.
function loadXML(loaded) {
if (loaded) {
for (i2=0; i2<this.firstChild.childNodes.length; i2++) {
mm[i2] = this.firstChild.childNodes[i2].firstChild.nodeValue;
dd.loadSound(mm[0], true);
}
} else {
trace(“file not loaded!”);
}
}
xmlData = new XML();
xmlData.ignoreWhite = true;
xmlData.onLoad = loadXML;
xmlData.load(“list.xml”);