http://www.actionscripts.org/showMovie.php?id=734
I’ve been fiddling around with the above player and find it simple to use and personalise.
The only problem is that I can’t seem to find a way for the next track to play automatically. And I guess to start at the beginning again after the last track.
I’m sure it’s just a play/stop or true/false that I’ve over looked but I need a bit of help anyway.
Here’s the code on the MC that contains the player’s buttons:
onClipEvent(enterFrame) {
//trace(_root.s.position / 1000);
secondsPlayed=int(_root.s.position / 1000);
minutesPlayed=int((secondsPlayed / 60));
secondsP=(secondsPlayed % 60);
if (secondsP < 10) secondsP = "0" + secondsP;
secondsTotal=int(_root.s.duration / 1000);
minutes=int((secondsTotal / 60));
seconds=(secondsTotal % 60);
if (seconds < 10) seconds = "0" + seconds;
//trace(minutesPlayed + ":" + secondsP + "/" + minutes + ":" + seconds);
musicTimer=minutesPlayed + ":" + secondsP + "/" + minutes + ":" + seconds;
if (_root.s.getBytesLoaded() == _root.s.getBytesTotal()) {
if (_root.s.position == _root.s.duration && _root.s.position > 60000) { //err fix the bug
if (_root.pList == _root.pListNum) {
_root.pList=0;
} else {
_root.pList++;
}
}
}
}
Here’s the code on the MC that contains the player’s text field list:
onClipEvent(load) {
_root.pList=0;
_root.currentItem=0;
}
onClipEvent(enterFrame) {
if (_root.currentItem != _root.pList) {
if (_root.pList == _root.pListNum) {_root.pList=0;}
if (_root.pList < 0) {_root.pList=_root.pListNum -1;}
//trace("pList is " + _root.pList + " pListNum is " + _root.pListNum);
myList.setSelectedIndex(_root.pList);
_root.currentItem = _root.pList;
}
}
Here’s the code in the .AS file:
myList.setStyleProperty("textColor", 0x4d420a);
myList.setStyleProperty("textFont", "Verdana");
myList.setStyleProperty("textSize", 9);
iVars = new LoadVars();
iVars.load('songList.txt');
ivars.onLoad = function(success) {
if (!success) {
trace("failed to load");
} else {
_root.pListNum = iVars.num;
_root.songTitles = iVars.songTitles;
_root.songs = iVars.songs;
arLabel=new Array();
arData=new Array();
arLabel = _root.songTitles.split("|");
arData = _root.songs.split("|");
_root.songs = new Array();
for(x=0;x<arData.length;x++) {
_root.songs[arData[x]] = x;
//trace(_root.songs[arData[x]]);
}
//load the box with data/labels
for(var i=0;i<arLabel.length;i++){
myList.addItem(arLabel*,arData*);
}
//tell the list box to hide the scroll bar when the list is shorter than the box.
myList.setAutoHideScrollBar(true);
//set the change handler for the list box
//this tells the list box what function to run
//when an item is selected.
//if you use the suffix '_lb' in your instance name, you will get the dropdown
//box of all available methods for the listbox when writing your code.
myList.setChangeHandler("itemPicked");
_root.startIndex=0;
}
//myList.setSelectedIndex(0);
};
itemPicked=function() {
_parent.mp3Player.myConditionText = "loading...";
//an item has been selected:
//insert the data value in the box into the text box
var myVal=myList.getSelectedItem().data;
dotIndex = myVal.indexOf(".");
myXml = myVal.subString(0, dotIndex);
_root.xmlFile = myXml + ".xml";
_root.pList = myList.getSelectedIndex();
myList.setScrollPosition(myList.getSelectedIndex());
if (_root.startIndex == 0) {
//trace("creating new sound obj");
_root.s.stop();
_root.s = new Sound();
_root.s.loadSound(myVal, true);
_root.s.start(0,0);
} else {
//trace("_root.startIndex is " + _root.startIndex);
_root.s.start(_root.startIndex,0);
}
};