PDA

View Full Version : Somthing missing... MP3/php/mysql


vibetribe
09-18-2006, 10:25 PM
I AM SO close i feel it.... please review the enclosed file... Im sure im missing something so simple in the AS. If anyone could help me I'd be most greatfull...

This is a flash mp3 player that gets a list from mysql db and displays it for the viewer to select from ... i cant get the controls to work :(

thanks in advance...

here is the fla ... http://www.vibetribe.org/mp3Problem.zip

var mp3Array:Array = [];
mp3List.addItem("loading mp3 data..");
var receiver:LoadVars = new LoadVars();
receiver.onLoad = function(ok:Boolean):Void {
if (ok) {
mp3List.removeAll();
mp3List.addItem("Select your mp3");
for (var i:Number = 1; i<=receiver.total; i++) {
receiver["mp3DataPacket"+i] = receiver["mp3_data"+(i)].split("|");
var id:String = receiver["mp3DataPacket"+i][0];
var mp3name:String = receiver["mp3DataPacket"+i][1];
var downloadLink:String = receiver["mp3DataPacket"+i][2];
var mp3DataObj:Object = {};
mp3DataObj.id = id;
mp3DataObj.mp3name = mp3name;
mp3DataObj.downloadLink = downloadLink;
mp3Array.push(mp3DataObj);
mp3List.addItem(mp3DataObj.mp3name);
delete (receiver["mp3_data"+i]);
if (i == receiver.total) {
setup_mp3_list();
}
}
} else {
trace("error");
}
};
receiver.load("http://www.vibetribe.org/get_mp3_data.php");
setup_mp3_list = function ():Void {
var mp3ListObj:Object = {};
mp3ListObj.change = function():Void {
if (mp3List.selectedItem.label != "Select your mp3") {
var sIndex:Number = mp3List.selectedIndex-1;
show_mp3_specifics(sIndex);
} else {
serverMsg.htmlText = "";
}
};
mp3List.addEventListener("change", mp3ListObj);
};
show_mp3_specifics = function (sIndex:Number):Void {
serverMsg.htmlText = "mp3 name: "+mp3Array[sIndex].mp3name+"<br/>"+"download link: <a href='"+mp3Array[sIndex].downloadLink+"'>download this mp3</a>";
play_mp3(mp3Array[sIndex].downloadLink);
};
formatTime = function (millisecs) {
var secs = Math.floor(millisecs/1000);
var mins = Math.floor(secs/60);
secs %= 60;
if (secs<10) {
secs = "0"+secs;
}
if (mins<10) {
mins = "0"+mins;
}
return mins+":"+secs;
};
play_mp3 = function (playLink:String):Void {
var fullUrl:String = "http://www.vibetribe.org/";
var soundHolder = this.createEmptyMovieClip("SoundController", 1);
soundHolder.init = function() {
soundHolder._sound = new Sound(this); //or maybe just new Sound() ???
this.isPlaying = false;
this.position = 0;
loadingbar_mc._xscale = 0;
progressbar_mc._xscale = 0;
};
soundHolder.loadSound = function() {
this._sound.loadSound(fullUrl+playLink, true); //VERY VERY VERY IMPORTANT... BUT MAY BE MY PROBLEM....
stop_btn.onRelease();
this.updateTime();
};
soundHolder.updateTime = function() {
var time = formatTime(soundHolder.position);
if (time_txt.text != time) {
time_txt.text = time;
}
};
soundHolder._sound.onSoundComplete = function() {
stop_btn.onRelease();
};
soundHolder.onEnterFrame = function() {
if (this.isPlaying) {
this.position = this._sound.position;
}
this.loaded = this._sound.getBytesLoaded()/this._sound.getBytesTotal();
loadingbar_mc._xscale = scrubber_mc._xscale*this.loaded;
progressbar_mc._xscale = loadingbar_mc._xscale*this.position/this._sound.duration;
this.updateTime();
};
play_btn.onRelease = function() {
if (!isPlaying) {
soundHolder._sound.start(soundHolder.position/1000);
soundHolder.isPlaying = true;
}
};
pause_btn.onRelease = function() {
if (!soundHolder.isPlaying) {
return (0);
}
soundHolder.position = soundHolder._sound.position;
soundHolder._sound.stop();
soundHolder.isPlaying = false;
};
stop_btn.onRelease = function() {
soundHolder.position = 0;
soundHolder._sound.stop();
soundHolder.isPlaying = false;
};
scrubber_mc.onPress = function() {
if (!soundHolder.loaded) {
return (0);
}
var pos = this._xmouse/100;
soundHolder.position = Math.min(soundHolder._sound.duration, pos*soundHolder._sound.duration/soundHolder.loaded);
if (soundHolder.isPlaying) {
soundHolder._sound.start(soundHolder.position/1000);
}
};
soundHolder.init();
};