PDA

View Full Version : flashamp


purplefish32
10-28-2004, 02:51 PM
i downloaded an xml driven mp3 player from somewhere on actionscrips.org that i unfortunatly cant remember at the moment, (flashamp) annyway killer little app, perfect for what i need, except that i would like to make it autoplay the first song when it is loaded... i just cant seem to get it to do so. :eek:
here is the main code :


// Load the song list available on the server
MovieClip.prototype.loadSongList = function(URL) {
// create new XML
this.mySongList = new XML();
this.mySongList.ignoreWhite = true;
this.mySongList.load(URL);
// init the preLoader
// startPreload("_root");
// callback function creates a playlist
this.mySongList.myClip = this;
// onLoad is referenced to the XML so first create a reference to self
this.mySongList.onLoad = function() {
// this now refers to the XML and myClip is used to pass the movieclip reference
//trace(this.myClip);
this.myClip.makePlayList(this);
};
};
//
// make a songlist
MovieClip.prototype.makePlayList = function(myPlayListXML) {
// Hardwired XML reader to read the XML playlist.
// First get the number of songs
this.songNos = myPlayListXML.firstChild.firstChild.childNodes.len gth;
//trace("Number of songs = "+this.songNos);
// create playlist object
this.PlayList = {};
// new object created
this.PlayList.Songs = new Array();
// new array created in the songs object
// songlist is xml with only songs
this.songList = new XML();
this.songList = myPlayListXML.firstChild.firstChild;
this.mySong = this.songList.firstChild;
// trace (mySong);
// trace (songList);
for (var i = 0; i<this.songNos; i++) {
// PlayList.Songs[i] = "Song" + i;
this.PlayList.Songs["name"+i] = this.mySong.firstChild.firstChild.nodeValue;
this.PlayList.Songs["src"+i] = this.mySong.firstChild.nextSibling.firstChild.node Value;
this.PlayList.Songs["artist"+i] = this.mySong.firstChild.nextSibling.nextSibling.fir stChild.nodeValue;
this.mySong = this.mySong.nextSibling;
//trace("song name "+i+" = "+this.PlayList.Songs["name"+i]);
//trace("song src "+i+" = "+this.PlayList.Songs["src"+i]);
//trace("song artist "+i+" = "+this.PlayList.Songs["artist"+i]);
}
this.displayPlayList();
};
// Display songlist
MovieClip.prototype.displayPlayList = function(myPlayListObj) {
myDisplay = "";
for (i=0; i<this.songNos; i++) {
if (i == this.currentSong) {
myColor = "#993300";
} else {
myColor = "#556682";
}
var myArtistName = this.PlayList.Songs["artist"+i];
var mySongName = this.PlayList.Songs["name"+i];
// var displayLength = 15
// if (myArtistName.length >= displayLength){
// myArtistName = myArtistName.substring(0, displayLength);
// }else{
// for (var j=0; i< (displayLength-myArtistName.length); j++){
// myArtistName += " ";
// }
// }
myArtistName += " - ";
// if (mySongName.length >= displayLength){
// mySongName = mySongName.substring(0, displayLength);
// }else{
// for (var j=0; i< (displayLength-mySongName.length); j++){
// mySongName += " ";
// }
// }
mySongName += "";
if (i<9) {
myDisplay += "<font color=\""+myColor+"\"><a href=\"asfunction:playSong,"+i+"\">"+myArtistName+" "+mySongName+"</a></font><br>";
} else if (i<99) {
myDisplay += "<font color=\""+myColor+"\"><a href=\"asfunction:playSong,"+i+"\">"+myArtistName+" "+mySongName+"</a></font><br>";
} else {
myDisplay += "<font color=\""+myColor+"\"><a href=\"asfunction:playSong,"+i+"\">"+myArtistName+" "+mySongName+"</a></font><br>";
}
}
this.myDisplayText.htmlText = myDisplay;
//trace(this.scroller.getScrollPosition());
if (this.currentSong>6 && this.songNos>6) {
if (this.scroller.getScrollPosition()<this.currentSong-5) {
this.scroller.setScrollPosition(this.currentSong-5);
} else if (this.scroller.getScrollPosition()>(this.currentSong+1)) {
this.scroller.setScrollPosition(this.currentSong-5);
}
} else {
this.scroller.setScrollPosition(1);
}
};
// ***************plays the song passed in the argument**************************
MovieClip.prototype.playSong = function(songNo) {
//trace("Now playing song: "+songNo);
var songURL = this.PlayList.Songs["src"+songNo];
if (this.streamSound) {
var stream = true;
} else {
var stream = true;
}
mySong = new Sound();
mySong.stop();
mySong.loadSound(songURL, stream);
mySong.baseClip = this;
mySong.onLoad = function() {
this.start();
};
mySong.onSoundComplete = function() {
this.baseClip.getNextSong();
};
this.currentSong = songNo;
this.displayPlayList();
this.playPause.gotoAndStop(2);
};
// ***************plays the next song **************************
MovieClip.prototype.getNextSong = function() {
if (this.currentSong<(this.songNos-1)) {
this.currentSong++;
} else {
this.currentSong = 0;
}
this.playSong(this.currentSong);
};
// ***************plays the previous song **************************
MovieClip.prototype.getPrevSong = function() {
if (this.currentSong>0) {
this.currentSong--;
} else {
this.currentSong = (this.songNos-1);
}
this.playSong(this.currentSong);
};
// **********pauses the song*******************
MovieClip.prototype.stopSong = function() {
mySong.stop();
};
// preloader function
MovieClip.prototype.startPreLoad = function(objectToLoad) {
//trace("**************start loading "+objectToLoad);
preLoader.loadBar.myObject = objectToLoad;
preLoader.loadBar.onEnterFrame = function() {
trace("myObj="+[this.myObject]+" | nowloaded="+[[this.myObject]+".getBytesLoaded"]());
this._xscale = ([[this.myObject]+".getBytesLoaded"]()/[[this.myObject]+".getBytesTotal"]())*100;
if ([[this.myObject]+".getBytesLoaded"]() == [[this.myObject]+".getBytesTotal"]() && [[this.myObject]+".getBytesTotal"]() != 0) {
trace("done loading");
this.onEnterFrame = null;
}
};
};
this.display.loadSongList("playlist.xml");

stop();



can someone please give me a little light. :p
here are the attached files:

purplefish32
10-28-2004, 02:53 PM
sorry for the smilies... :p = ": P"