i have an MP3 player with a playlist using an external xml file. This all works fine but i also have dynamic textboxes showing what song title and artist is playing. These update fine when the user clicks back and forward buttons but the problem i am having is that i can not get the textBoxes to update when the user clicks on a song from the playlist. Here is my code -
import fl.events.ListEvent;
var my_songs:XMLList;
var my_total:Number;
var my_sound:Sound;
var my_channel:SoundChannel;
var current_song:Number = 0;
var song_position:Number;
var song_paused:Boolean;
var myXMLLoader:URLLoader = new URLLoader();
myXMLLoader.load(new URLRequest("playlist.xml"));
myXMLLoader.addEventListener(Event.COMPLETE, processXML);
function processXML(evt:Event):void
{
var myXML:XML = new XML(evt.currentTarget.data);
var item:Object;
my_songs = myXML.SONG;
playSong(0);
for each(var prop:XML in myXML.SONG){
item = new Object();
item.label = prop.@ARTIST;
item.data = prop.@URL;
playList.addItem(item);
}
my_sound = new Sound();
my_sound.load(new URLRequest(playList.getItemAt(0).data));
}
playList.addEventListener(ListEvent.ITEM_CLICK, onClick);
function onClick(evt:ListEvent):void
{
var item:Object = evt.item;
my_channel.stop();
my_sound = new Sound();
my_sound.load(new URLRequest(item.data));
my_channel = my_sound.play();
}
function playSong(mySong:Number):void
{
var myTitle = my_songs[mySong].@TITLE;
var myArtist = my_songs[mySong].@ARTIST;
var myURL = my_songs[mySong].@URL;
title_txt.text = myTitle;
artist_txt.text = myArtist;
if(my_channel)
{
my_channel.stop();
}
my_sound = new Sound();
my_sound.load(new URLRequest(myURL));
my_channel = my_sound.play();
my_channel.addEventListener(Event.SOUND_COMPLETE, nextSong);
}
next_btn.addEventListener(MouseEvent.CLICK, nextSong);
function nextSong(evt:Event):void
{
current_song++;
if(current_song > 9)
{
current_song = 0;
}
playSong(current_song);
}
prev_btn.addEventListener(MouseEvent.CLICK, prevSong);
function prevSong(evt:MouseEvent):void
{
current_song--;
if(current_song < 0)
{
current_song = 9;
}
playSong(current_song);
}
pause_btn.addEventListener(MouseEvent.CLICK, pauseSong);
function pauseSong(evt:MouseEvent):void
{
song_position = my_channel.position;
my_channel.stop();
song_paused=true;
}
play_btn.addEventListener(MouseEvent.CLICK, play_Song);
function play_Song(evt:MouseEvent):void
{
if (song_paused)
{
my_channel = my_sound.play(song_position);
song_paused = false;
}
else if (!my_channel)
{
playSong(current_song);
}
}
Any ideas?