Actionscript woes....

Associate
Joined
18 Oct 2002
Posts
158
Location
Manchester, UK
Hi, apologies for creating another thread for this, could the powers that be please erase my old one? Thanks!

Right...so I got the listbox working, except for a small bug...if I click on a song it loads and plays fine, however if I click on the same song again it plays the next song in the list, which is wrong....it shouldn't be acting like a next button! :(

So again, if anyone can help it'd be much appreciated! Should all be around the xml loader area.... Thanks!

Code:
//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 sngList:XML = new XML();
sngList.ignoreWhite = true;
sngList.onLoad = function()
{
		var nodes:Array = this.firstChild.childNodes;
		for(var i=0;i<nodes.length;i++)
		{
			sa.push(new Song(nodes[i].attributes.url, nodes[i].attributes.artist, nodes[i].attributes.track));
			songList.addItem(nodes[i].attributes.display, nodes[i].attributes.url);
		playSong();
		}
}

// when xml is loaded play first item

playSong.play(songList.getItemAt(0).data);

// highlight first song in listbox

songList.selectedIndex = 0;

// create a listener that responds 
// to changes in the listbox

var sngListener:Object = new Object();
sngListener.change = function() {

// play the item selected in listbox

playSong.play(songList.getItemAt(songList.seletedIndex).data);
playSong();
};

// register the event listener to listbox

songList.addEventListener("change", sngListener);

// load xml file

sngList.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");
}

//Pauses the music
function pauseIt():Void
{
	pos = s.position;
	s.stop();
}

//Unpauses the music
function unPauseIt():Void
{
	s.start(pos/1000);
}

//Stops the music
function stopIt():Void
{
	s.stop();
}

//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();
		logo_anim_mov.gotoAndPlay(2);
	}
	else
	{
		this.gotoAndStop("pauseOver");
		this._parent.unPauseIt();
		logo_anim_mov.gotoAndPlay(2);
	}
}

//Next button
next.onRollOver = function()
{
	this.gotoAndStop("nextOver");
}

next.onRollOut = next.onReleaseOutside = function()
{
	this.gotoAndStop("next");
}

next.onRelease = function()
{
	this._parent.playSong();
	logo_anim_mov.gotoAndPlay(2);
}

//Stop button
stop.onRollOver = function()
{
	this.gotoAndStop("stopOver");
}

stop.onRollOut = stop.onReleaseOutside = function()
{
	this.gotoAndStop("stop");
}

stop.onRelease = function()
{
	this._parent.stopIt();
	playPause.gotoAndStop("play");
	logo_anim_mov.gotoAndPlay(2);
}

//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);
		logo_anim_mov.gotoAndPlay(2);
	}
	else
	{
		this.gotoAndStop("onOver");
		s.setVolume(75);
		logo_anim_mov.gotoAndPlay(2);
	}
}
 
only a very quick suggestion which might not work as i'm just on the way out but

Can you not set the current song that is playing to un-clickable, could put it in the function playSong so once it is selected it becomes un-clickable and stops any problems?
 
i don't think you can make a single item unselectable..

perhaps try something like:
Code:
var curLabel:String = songList.getItemAt(0).label;
var sngListener:Object = new Object();
sngListener.change = function() {
	if (curLabel != songList.getItemAt(songList.selectedIndex).label) {
		// play the item selected in listbox
		playSong.play(songList.getItemAt(songList.selectedIndex).data);
		curLabel = songList.getItemAt(songList.selectedIndex).label;
		playSong();
	}
};
although there should be no reason why it selects the next song when selecting the same song twice but i've not got time to have a good look through, i'm afraid, so this is a bit of a bodge..
 
Back
Top Bottom