sanflynz
08-04-2007, 10:15 PM
Hi All
Im fiddling with an mp3 player I found a tutorial for online, and am really stuck with what I think should be a simple part of code. The basic problem is that after I pause the track, the play button wont play the track.
I dont know much about actionscript, but do code a little in php and javascript so Ive had a play around with the code as much as I am able, but to no avail.
This is the function to pause the song:
btn_pause.onRelease = function() { //pause button function
this._parent.sound_mc.sound_obj.stop(); //stop the current sound
posiP = _root.sound_mc.sound_obj.position / 1000; // save the current position in a new variable and divide by 1000 (ms -> sec)
pause = true; //set the variable pause to true
}
and this is the function to restart:
btn_play.onRelease = function() {
if (pause == true){ // no comment....
this._parent.sound_mc.sound_obj.start(posiP); // start sound from the previously saved position
}
else {
this._parent.sound_mc.songStarter(songfile[song_nr], songname[song_nr]);
}
}
Now, I know the function is being restarted, and the variable posiP is getting passed into the function, because I used a dynamic text box on the player to show me the value of posiP and it was fine, ie:
btn_play.onRelease = function() {
if (pause == true){ // no comment....
this._parent.display_txt.text = posiP;
this._parent.sound_mc.sound_obj.start(posiP); // start sound from the previously saved position
}
else {
this._parent.sound_mc.songStarter(songfile[song_nr], songname[song_nr]);
}
}
This is my entire actionscript if you need it
Can anyone help me? Thanks in advance :)
stop();
playlist = new XML();
playlist.ignoreWhite=true;
playlist.onload = function (success) {
if(success) {
_global.songname = [];
_global.songfile = [];
for (var i=0; i<playlist.firstChild.childNodes.length; i++) {
_global.songname[i] = playlist.firstChild.childNodes[i].attributes.name;
_global.songfile[i] = playlist.firstChild.childNodes[i].attributes.file;
trace(songname[i]+" "+songfile[i]);
}
_root.createEmptyMovieClip("sound_mc",1);
_root.sound_mc.sound_obj = new Sound();
_global.song_nr = random(songfile.length);
_root.sound_mc.songStarter(songfile[song_nr],songname[song_nr]);
}
else {
display_txt.text="Error Loading XML"
}
}
MovieClip.prototype.songStarter = function (file, name) {
this.sound_obj.loadSound(file,true)
this.onEnterFrame = function () {
if(this.sound_obj.position>0) {
delete this.onEnterFrame;
this._parent.display_txt.text=name;
}
else {
this._parent.display_txt.text="loading..."
}
}
this.sound_obj.onSoundComplete = function (){
(song_nr == songfile.length-1)? _global.song_nr=0 : _global.song_nr++;
_root.sound_mc.songStarter(songfile[song_nr],songname[song_nr]);
}
this._parent.volume1.dragger.onPress = function() {
startDrag(this, true, 0, this._y, this._parent.volBG._width, this._y);
this.onEnterFrame = function() {
var p = (this._x/this._parent.volBG._width)*100;
this._parent._parent.sound_mc.sound_obj.setVolume( p);
}
}
this._parent.volume1.dragger.onRelease = function() {
delete this.onEnterFrame;
stopDrag();
}
this._parent.volume1.dragger.onReleaseOutside = function() {
stopDrag();
}
}
btn_play.onRelease = function() {
if (pause == true){ // no comment....
this._parent.sound_mc.sound_obj.start(posiP); // start sound from the previously saved position
}
else {
this._parent.sound_mc.songStarter(songfile[song_nr], songname[song_nr]);
}
}
btn_stop.onRelease = function() {
this._parent.sound_mc.sound_obj.stop();
}
btn_pause.onRelease = function() { //pause button function
this._parent.sound_mc.sound_obj.stop(); //stop the current sound
posiP = _root.sound_mc.sound_obj.position / 1000; // save the current position in a new variable and divide by 1000 (ms -> sec)
pause = true; //set the variable pause to true
}
function soundStatus(){
var amountLoaded = _root.sound_mc.sound_obj.getBytesLoaded() / _root.sound_mc.sound_obj.getBytesTotal();
_root.loader.loadBar._width = amountLoaded * 162;
duration = _root.sound_mc.sound_obj.duration;
position = _root.sound_mc.sound_obj.position;
_root.playHead._x = position / duration * 162 + 72;
}
playlist.load("playlist.xml");
setInterval(soundStatus,100);
Im fiddling with an mp3 player I found a tutorial for online, and am really stuck with what I think should be a simple part of code. The basic problem is that after I pause the track, the play button wont play the track.
I dont know much about actionscript, but do code a little in php and javascript so Ive had a play around with the code as much as I am able, but to no avail.
This is the function to pause the song:
btn_pause.onRelease = function() { //pause button function
this._parent.sound_mc.sound_obj.stop(); //stop the current sound
posiP = _root.sound_mc.sound_obj.position / 1000; // save the current position in a new variable and divide by 1000 (ms -> sec)
pause = true; //set the variable pause to true
}
and this is the function to restart:
btn_play.onRelease = function() {
if (pause == true){ // no comment....
this._parent.sound_mc.sound_obj.start(posiP); // start sound from the previously saved position
}
else {
this._parent.sound_mc.songStarter(songfile[song_nr], songname[song_nr]);
}
}
Now, I know the function is being restarted, and the variable posiP is getting passed into the function, because I used a dynamic text box on the player to show me the value of posiP and it was fine, ie:
btn_play.onRelease = function() {
if (pause == true){ // no comment....
this._parent.display_txt.text = posiP;
this._parent.sound_mc.sound_obj.start(posiP); // start sound from the previously saved position
}
else {
this._parent.sound_mc.songStarter(songfile[song_nr], songname[song_nr]);
}
}
This is my entire actionscript if you need it
Can anyone help me? Thanks in advance :)
stop();
playlist = new XML();
playlist.ignoreWhite=true;
playlist.onload = function (success) {
if(success) {
_global.songname = [];
_global.songfile = [];
for (var i=0; i<playlist.firstChild.childNodes.length; i++) {
_global.songname[i] = playlist.firstChild.childNodes[i].attributes.name;
_global.songfile[i] = playlist.firstChild.childNodes[i].attributes.file;
trace(songname[i]+" "+songfile[i]);
}
_root.createEmptyMovieClip("sound_mc",1);
_root.sound_mc.sound_obj = new Sound();
_global.song_nr = random(songfile.length);
_root.sound_mc.songStarter(songfile[song_nr],songname[song_nr]);
}
else {
display_txt.text="Error Loading XML"
}
}
MovieClip.prototype.songStarter = function (file, name) {
this.sound_obj.loadSound(file,true)
this.onEnterFrame = function () {
if(this.sound_obj.position>0) {
delete this.onEnterFrame;
this._parent.display_txt.text=name;
}
else {
this._parent.display_txt.text="loading..."
}
}
this.sound_obj.onSoundComplete = function (){
(song_nr == songfile.length-1)? _global.song_nr=0 : _global.song_nr++;
_root.sound_mc.songStarter(songfile[song_nr],songname[song_nr]);
}
this._parent.volume1.dragger.onPress = function() {
startDrag(this, true, 0, this._y, this._parent.volBG._width, this._y);
this.onEnterFrame = function() {
var p = (this._x/this._parent.volBG._width)*100;
this._parent._parent.sound_mc.sound_obj.setVolume( p);
}
}
this._parent.volume1.dragger.onRelease = function() {
delete this.onEnterFrame;
stopDrag();
}
this._parent.volume1.dragger.onReleaseOutside = function() {
stopDrag();
}
}
btn_play.onRelease = function() {
if (pause == true){ // no comment....
this._parent.sound_mc.sound_obj.start(posiP); // start sound from the previously saved position
}
else {
this._parent.sound_mc.songStarter(songfile[song_nr], songname[song_nr]);
}
}
btn_stop.onRelease = function() {
this._parent.sound_mc.sound_obj.stop();
}
btn_pause.onRelease = function() { //pause button function
this._parent.sound_mc.sound_obj.stop(); //stop the current sound
posiP = _root.sound_mc.sound_obj.position / 1000; // save the current position in a new variable and divide by 1000 (ms -> sec)
pause = true; //set the variable pause to true
}
function soundStatus(){
var amountLoaded = _root.sound_mc.sound_obj.getBytesLoaded() / _root.sound_mc.sound_obj.getBytesTotal();
_root.loader.loadBar._width = amountLoaded * 162;
duration = _root.sound_mc.sound_obj.duration;
position = _root.sound_mc.sound_obj.position;
_root.playHead._x = position / duration * 162 + 72;
}
playlist.load("playlist.xml");
setInterval(soundStatus,100);