Hi!
I need help with my code to my scroll list. What it does now is to just play the first song who comes in and then stops, and I got 12 songs total. What I want it to do is also when I click on a song at the list is to select that song and then play it. But instead of doing this know, I only got invalid things.
// Setup sound object
var s:Sound = new Sound();
s.onSoundComplete = playSong;
s.setVolume(75);
// Array of songs
var sa:Array = new Array();
// Currently playing song
var cps:Number = -1;
// Position of music
var pos:Number;
// Load the songs XML
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++)
{
sa.push(new Song(nodes*.attributes.url, nodes*.attributes.artist, nodes*.attributes.track));
}
playSong();
}
xml.load("songs.xml");
// Play the MP3 File
function playSong():Void
{
s = new Sound();
s.onSoundComplete = playSong;
s.setVolume(75);
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");
textPos = 0;
}
// Pauses the music
function pauseIt():Void
{
pos = s.position;
s.stop();
}
// Unpauses 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();
}
}
// Stop
Bstop.onRollOver = function()
{
this.gotoAndStop("stopOver");
}
Bstop.onRollOut = Bstop.onReleaseOutside = function()
{
this.gotoAndStop("stop");
}
Bstop.onRelease = function()
{
pos = 0;
s.stop();
_parent.playPause.gotoAndStop("stop");
}
// Next Button
next.onRollOver = function()
{
this.gotoAndStop("nextOver");
}
next.onRollOut = next.onReleaseOutside = function()
{
this.gotoAndStop("next");
}
next.onRelease = function()
{
this._parent.playSong();
}
// Prev Button
prevBtn.onRollOver = function()
{
this.gotoAndStop("backOver");
}
prevBtn.onRollOut = prevBtn.onReleaseOutside = function()
{
this.gotoAndStop("back");
}
prevBtn.onRelease = function() {
cps -=2;
if (cps < 0 ) {
cps = sa.length - cps;
}
playSong();
}
// Mute Button
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);
}
}
//Text scroller
var size:Number = 20;
var textPos:Number = 0;
var intervalID:Number = setInterval(scroller, 500);
function scroller():Void
{
var t:String = (sa[cps].artist + " - " + sa[cps].track);
if(textPos+size < t.length)
{
textPos++;
trackInfo.text = (sa[cps].artist + " - " + sa[cps].track).substring(textPos, textPos+size);
}
else
{
clearInterval(intervalID);
intervalID = setInterval(scroller2, 500);
}
}
function scroller2():Void
{
var t:String = (sa[cps].artist + " - " + sa[cps].track);
if(textPos > -1)
{
textPos--;
trackInfo.text = (sa[cps].artist + " - " + sa[cps].track).substring(textPos, size);
}
else
{
clearInterval(intervalID);
intervalID = setInterval(scroller, 500);
}
}
//Scroll List
//var vlist:XML = new XML();
//vlist.ignoreWhite = true;
//vlist.onLoad = function() {
// var videos:Array = this.firstChild.childNodes;
// for(i=0;1<videos.length;i++) {
// trackInfo.addItem(videos*.attributes.desc,videos*.attributes.url);
// }
// ns.play(videoList.getItemAt(0).data);
// Lista.Lista.selectedIndex = 0;
//}
var songListner:Object = new Object();
songListner.change = function() {
playSong()
trace(Lista.Lista.getItemAt(videoList.selectedIndex).data)
cps = Lista.Lista.getItemAt(videoList.selectedIndex).data;
}
Lista.Lista.addEventListener("change",songListner);
// vlist.load("songs.xml");