So close

Hi all,i made an mp3 player that generates a report about which songs were downloaded,with the click of a button it sends the vars to php which in turn writes to a local file.

There is a problem though,whenever i click next or prev more than once and hit the download button, all of the songs that were skipped will report as downloaded.i have come far with this so i cant give up on it.

Below is the code and will be glad if someone can point out what could be wrong.as my code wil show you, i am still a begginer in as3 but i do my best.the only way i could tap into xml and utilize the vars for tracks was through this current setup of the code.
Thanks.

//----------------------------xml-stuff--------------------------------------
var myXMLLoader:URLLoader = new URLLoader();
myXMLLoader.load(new URLRequest(“http://localhost/playlist.xml”));
myXMLLoader.addEventListener(Event.COMPLETE, processXML);
function processXML(e:Event):void
{
var myXML:XML=new XML(e.target.data);
my_songs=myXML.SONG;
my_total=my_songs.length();

myXMLLoader.removeEventListener(Event.COMPLETE, processXML);
myXMLLoader=null;
}
//--------------------play song--------------------------
function playSong(mySong:Number):void
{
var myAlbum=my_songs[mySong].@ALBUM;
var myTrack=my_songs[mySong].@TRACK;
var myArtist=my_songs[mySong].@ARTIST;
var myURL=my_songs[mySong].@URL;
album_txt.text=myAlbum;
artist_txt.text=myArtist;
track_txt.text=myTrack;
//removeEventListener(Event.COMPLETE, playSong);
//trace(myTrack);

if (my_channel)
{
my_channel.stop();
my_channel.removeEventListener(Event.SOUND_COMPLETE, onNext);
}
my_music = new Sound();
my_music.load(new URLRequest(myURL));
my_channel=my_music.play();
my_channel.addEventListener(Event.SOUND_COMPLETE, onNext);
addEventListener(Event.ENTER_FRAME, enterFrameHandler);
removeEventListener(Event.SOUND_COMPLETE, onNext);
//----------------------------------------------------------------------
//-----------------------------download btn + POST-----------------------------

dwnld_btn.addEventListener(MouseEvent.CLICK, post);
count++;
counter.text = count.toString();
function post(e:Event):void
{
//------------------------------------------------------------
//-------------------------------vars-------------------------------
var loader:URLLoader = new URLLoader();
var request:URLRequest = new URLRequest();
var variables:URLVariables = new URLVariables();
var date:Date = new Date();
//trace(date);
loader = new URLLoader();
loader.addEventListener(IOErrorEvent.IO_ERROR, errorHandler);
loader.addEventListener(SecurityErrorEvent.SECURITY_ERROR, errorHandler);

request = new URLRequest();
loadFromNetwork();
//----------------------------------------------------------------
//----------------------------php conn---------------------

function loadFromNetwork():void {
request.url = “http://localhost/t4.php”;

variables.date = new Date();
variables.artist = myArtist=my_songs[mySong].@ARTIST;
variables.count = count.toString();
variables.there = myURL=my_songs[mySong].@URL;
trace(variables.there);
request.data = variables;
request.method = URLRequestMethod.POST ;
loader.load(request);
loader.removeEventListener(Event.COMPLETE, loadFromNetwork);

//---------response from php--------------------
loader.addEventListener(Event.COMPLETE,t);
function t(evt:Event):void{

    trace(loader.data);
}

}//-----------------------------------------------------------------
//-------------------------error handler----------------------------
function errorHandler(event:ErrorEvent):void {
trace("errorHandler: " + event);
if(event is IOErrorEvent) {
loadFromNetwork();
}
}
}
}
//---------------------------buttons-------------------------------
next_btn.addEventListener(MouseEvent.CLICK, onNext);
function onNext(e:Event):void
{
current_song++;
if (current_song>=my_total)
{
current_song=0;

}

//-----------------time display-----next_btn----------------------
clearInterval(time_int);
time_int = setInterval(calculateTime, 100);
function calculateTime() {
var time:Number = my_channel.position / 1000;
var min = Math.floor(time / 60);
min = (min < 10) ? “0” + min : min;
var sec = Math.floor(time % 60);
sec = (sec < 10) ? “0” + sec : sec;
time_txt.text = min + “:” + sec;
if (my_channel.position >= my_music.length) {
clearInterval(time_int);
}
}
playSong(current_song);
next_btn.removeEventListener(Event.COMPLETE, onNext);
}
prev_btn.addEventListener(MouseEvent.CLICK, onPrev);
function onPrev(e:MouseEvent):void
{
current_song–;
if (current_song<0)
{
current_song=my_total-1;
}
//-------------------time-------------------------------
clearInterval(time_int);
time_int = setInterval(calculateTime, 100);
function calculateTime() {
var time:Number = my_channel.position / 1000;
var min = Math.floor(time / 60);
min = (min < 10) ? “0” + min : min;
var sec = Math.floor(time % 60);
sec = (sec < 10) ? “0” + sec : sec;
time_txt.text = min + “:” + sec;
if (my_channel.position >= my_music.length) {
clearInterval(time_int);
}
}
playSong(current_song);
prev_btn.removeEventListener(Event.COMPLETE, onPrev);
}
pause_btn.addEventListener(MouseEvent.CLICK, onPause);
function onPause(e:MouseEvent):void
{
if (my_channel)
{
song_position=my_channel.position;
my_channel.stop();
song_paused=true;
}
}
play_btn.addEventListener(MouseEvent.CLICK, onPlay);
function onPlay(e:MouseEvent):void
{
if (song_paused)
{
my_channel=my_music.play(song_position);
song_paused=false;
}
else if (!my_channel)
{

playSong(current_song);
play_btn.removeEventListener(Event.COMPLETE, onPlay);
//-------------------time-------------------------------
clearInterval(time_int);
time_int = setInterval(calculateTime, 100);
function calculateTime() {
var time:Number = my_channel.position / 1000;
var min = Math.floor(time / 60);
min = (min < 10) ? “0” + min : min;
var sec = Math.floor(time % 60);
sec = (sec < 10) ? “0” + sec : sec;
time_txt.text = min + “:” + sec;
if (my_channel.position >= my_music.length) {
clearInterval(time_int);
}
}

}
}