Ir para conteúdo

POWERED BY:

Arquivado

Este tópico foi arquivado e está fechado para novas respostas.

cahe

AS2 - MP3 player com vários XML. Como fazer?

Recommended Posts

Olá amigos do fórum!

 

Estou fazendo um MP3 player em AS2, e tenho 3 botões. Cada botão irá chamar um XML com uma lista diferente de músicas, que deverá substituir as músicas que estão tocando. Tentei fazer isso colocando xml.load("nomedalista.xml") no botão, mas ao chamar uma nova lista de músicas, essa é acrescentada a lista atual que já está tocando, ao invés de substitui-la.

 

Como posso deletar os dados do XML atual e substituir pelos do novo XML?

 

Já tentei delete xml e xml.firstChild.removeNode(); mas nada funcionou.

 

Abaixo copio o meu código:

 

// 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[i].attributes.url, nodes[i].attributes.artist, nodes[i].attributes.track));
	}
	playSong();
}

botao1.onRelease = function  () {
	xml.load("playlist1.xml");
}

botao2.onRelease = function  () {
	xml.load("playlist2.xml");
}

botao3.onRelease = function  () {
	xml.load("playlist3.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();
}

// Pauses 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();
	}
}

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

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

next.onRelease = function()
{
	this._parent.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 bonus code

var size:Number = 32;
var textPos:Number = 0;
var intervalID:Number = setInterval(scroller, 1000);

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, 1000);
	}
}

function scroller2():Void
{
	var t:String = (sa[cps].artist + " - " + sa[cps].track);
	if(textPos > 0)
	{
		textPos--;
		trackInfo.text = (sa[cps].artist + " - " + sa[cps].track).substring(textPos, size);
	}
	else
	{
		clearInterval(intervalID);
		intervalID = setInterval(scroller, 1000);
	}
}

Obrigado

Compartilhar este post


Link para o post
Compartilhar em outros sites

só um teste, não sei se vai funcionar, altera essa função:

 

xml.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));
	}
	playSong();
}

para essa:

 

 

xml.onLoad = function()
{
	var nodes:Array = this.firstChild.childNodes;
	sa = [] // zera o array
	for(var i=0;i<nodes.length;i++)
	{
		sa.push(new Song(nodes[i].attributes.url, nodes[i].attributes.artist, nodes[i].attributes.track));
	}
	playSong();
}

 

[]´s

Compartilhar este post


Link para o post
Compartilhar em outros sites

×

Informação importante

Ao usar o fórum, você concorda com nossos Termos e condições.