# Mp3 player playhead progressbar not dragging

**URL:** <https://forum.kirupa.com/t/mp3-player-playhead-progressbar-not-dragging/290095>\
**Category:** Uncategorized\
**Created:** [June 9, 2009, 6:25pm UTC](https://forum.kirupa.com/t/mp3-player-playhead-progressbar-not-dragging/290095 "2009-06-09T18:25:38Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![trueascention](https://avatars.discourse-cdn.com/v4/letter/t/48db29/32.png) [@trueascention](https://forum.kirupa.com/u/trueascention)\
**Post date:** [June 9, 2009, 6:25pm UTC](https://forum.kirupa.com/t/mp3-player-playhead-progressbar-not-dragging/290095/1 "2009-06-09T18:25:38Z")

</div>

I’ve been working on a Mp3 play for the last month and at the last minute i decided to make it to where you could drag the playHead anywhere on the progress bar(loader.loadBar) MC and it would play where you dropped the playHead.

Well after a week of failed attempts, i decided to come to the masters and ask for advice or to see where i am screwing up. Here is my actionscript:

stop();  
artist\_txt.autoSize = “left”;  
song\_txt.autoSize = “left”;  
timeDisplay\_txt.autoSize = “left”;  
toolTip.\_visible = false;  
var amountLoaded:Number;  
var duration:Number;  
var pauseTime:Number = 0;  
var stopped:Boolean = false;  
playlist = new XML();  
playlist.ignoreWhite = true;  
playlist.onLoad = function(success) {  
if (success) {  
\_global.songname = [];  
\_global.songband = [];  
\_global.songfile = [];  
for (var i = 0; i\<playlist.firstChild.childNodes.length; i++) {  
\_global.songname\* = playlist.firstChild.childNodes\*.attributes.name;  
\_global.songband\* = playlist.firstChild.childNodes\*.attributes.band;  
\_global.songfile\* = playlist.firstChild.childNodes\*.attributes.file;  
// trace(songname\*+" “+songfile\*+” “+songband\*);  
}  
}  
\_root.createEmptyMovieClip(“sound\_mc”,1);  
\_global.song\_nr = random(0);  
\_root.sound\_mc.songStarter(songfile[song\_nr],songname[song\_nr],songband[song\_nr]);  
};  
function timer(sound\_obj) {  
time = sound\_obj.position/1000;  
min = Math.floor(time/60);  
min = (min\<10) ? “0”+min : min;  
sec = Math.floor(time%60);  
sec = (sec\<10) ? “0”+sec : sec;  
timeDisplay\_txt.text = min+”:"+sec+" - “+totalDuration;  
}  
function duration() {  
timed = \_root.sound\_mc.sound\_obj.duration/1000;  
mind = Math.floor(timed/60);  
mind = (mind\<10) ? “0”+mind : mind;  
secd = Math.floor(timed%60);  
secd = (secd\<10) ? “0”+secd : secd;  
totalDuration = mind+”:"+secd;  
}  
MovieClip.prototype.songStarter = function(file, name, band) {  
if (this.sound\_obj) {  
this.sound\_obj.stop();  
delete this.sound\_obj;  
}  
this.sound\_obj = new Sound(this);  
this.sound\_obj.loadSound(file,true);  
this.onEnterFrame = function() {  
if (this.sound\_obj.position\>0) {  
delete this.onEnterFrame;  
this.\_parent.artist\_txt.text = band;  
this.\_parent.song\_txt.text = name;  
timeInterval = setInterval(timer, 1000, this.sound\_obj);  
} else {  
this.\_parent.artist\_txt.text = “loading…”;  
this.\_parent.song\_txt.text = “Please wait…”;  
}  
};  
this.sound\_obj.onSoundComplete = function() {  
clearInterval(timeInterval);  
this.\_parent.timeDisplay\_txt.text = “00:00 - 00:00”;  
(song\_nr == songfile.length-1) ? \_global.song\_nr=0 : \_global.song\_nr++;  
\_root.sound\_mc.songStarter(songfile[song\_nr],songname[song\_nr],songband[song\_nr]);  
};  
this.\_parent.volume1.dragger.onPress = function() {  
startDrag(this, false, 0, this.\_y, this.\_parent.volBG.\_width, this.\_y);  
\_root.toolTip.\_visible = true;  
setInterval(draggableTip,100);  
function draggableTip() {  
\_root.toolTip.\_x = \_root.\_xmouse;  
}  
this.onEnterFrame = function() {  
var p = (this.\_x/this.\_parent.volBG.\_width)_100;  
this.\_parent.\_parent.sound\_mc.sound\_obj.setVolume§;  
};  
};  
this.\_parent.volume1.dragger.onRelease = function() {  
delete this.onEnterFrame;  
stopDrag();  
};  
this.\_parent.volume1.dragger.onReleaseOutside = function() {  
\_root.toolTip.\_visible = false;  
stopDrag();  
};  
};  
function soundStatus() {  
var amountLoaded = (\_root.sound\_mc.sound\_obj.getBytesLoaded()/\_root.sound\_mc.sound\_obj.getBytesTotal());  
\_root.loader.loadBar.\_width = amountLoaded_393;  
duration = \_root.sound\_mc.sound\_obj.duration;  
position = \_root.sound\_mc.sound\_obj.position;  
\_root.playHead.\_x = position/duration_411+326;  
}  
function pauseTrack():Void {  
stopped = false;  
pauseTime = \_root.sound\_mc.sound\_obj.position/1000;  
\_root.sound\_mc.sound\_obj.stop();  
updateAfterEvent();  
}  
playHead.onPress = function() {  
\_root.sound\_mc.sound\_obj.stop();  
startDrag(this, false, 0, this.\_y, this.\_root.loader.loadBar.\_x, this.\_y);  
onMouseMove = function () {  
pauseTime = Math.floor(((this.\_root.loader.loadBar.\_x/this.\_root.loader.loadBar.\_width)_\_root.sound\_mc.sound\_obj.duration)/1000);  
updateAfterEvent();  
};  
};  
playHead.onRelease = function() {  
delete this.onEnterFrame;  
stopDrag();  
this.\_parent.sound\_mc.sound\_obj.start(pauseTime);  
this.\_parent.sound\_mc.sound\_obj.play();  
updateAfterEvent();  
};  
playHead.onReleaseOutside = function() {  
this.stopDrag();  
delete this.onMouseMove;  
this.\_parent.sound\_mc.sound\_obj.start(pauseTime);  
this.\_parent.sound\_mc.sound\_obj.play();  
updateAfterEvent();  
};  
//Buttons  
btn\_play.onRelease = function() {  
stopped = false;  
if (pauseTime\>0) {  
stopped = false;  
\_root.sound\_mc.sound\_obj.play();  
posiP = \_root.sound\_mc.sound\_obj.position/1000;  
pause = false;  
this.\_parent.sound\_mc.sound\_obj.start(pauseTime);  
btn\_pause.\_visible = true;  
btn\_unpause.\_visible = false;  
}  
if (stopped == true) {  
this.\_parent.sound\_mc.sound\_obj.start(pauseTime);  
clearInterval(timeInterval);  
this.\_parent.timeDisplay\_txt.text = “00:00 - 00:00”;  
this.\_parent.sound\_mc.songStarter(songfile[song\_nr],songname[song\_nr],songband[song\_nr]);  
}  
if (play == true) {  
void(stopped);  
}  
};  
btn\_stop.onRelease = function() {  
clearInterval(timeInterval);  
this.\_parent.timeDisplay\_txt.text = “00:00 - 00:00”;  
this.\_parent.sound\_mc.sound\_obj.stop();  
};  
btn\_fw.onRelease = function() {  
clearInterval(timeInterval);  
this.\_parent.timeDisplay\_txt.text = “00:00 - 00:00”;  
(song\_nr == songfile.length-1) ? \_global.song\_nr=0 : \_global.song\_nr++;  
\_root.sound\_mc.songStarter(songfile[song\_nr],songname[song\_nr],songband[song\_nr]);  
this.\_parent.sound\_mc.sound\_obj.start(pauseTime);  
};  
btn\_rev.onRelease = function() {  
clearInterval(timeInterval);  
this.\_parent.timeDisplay\_txt.text = “00:00 - 00:00”;  
(song\_nr == 0) ? \_global.song\_nr=songfile.length-1 : \_global.song\_nr–;  
\_root.sound\_mc.songStarter(songfile[song\_nr],songname[song\_nr],songband[song\_nr]);  
this.\_parent.sound\_mc.sound\_obj.start(pauseTime);  
};  
btn\_pause.onRelease = function() {  
stopped = false;  
pauseTrack();  
btn\_pause.\_visible = false;  
btn\_unpause.\_visible = true;  
};  
btn\_unpause.onRelease = function() {  
\_root.sound\_mc.sound\_obj.play();  
posiP = \_root.sound\_mc.sound\_obj.position/1000;  
pause = false;  
this.\_parent.sound\_mc.sound\_obj.start(pauseTime);  
btn\_pause.\_visible = true;  
btn\_unpause.\_visible = false;  
};  
btn\_mute.onRelease = function() {  
this.\_parent.sound\_mc.sound\_obj.setVolume(0);  
btn\_unmute.\_visible = true;  
btn\_mute.\_visible = false;  
};  
btn\_unmute.onRelease = function() {  
this.\_parent.sound\_mc.sound\_obj.setVolume(100);  
btn\_unmute.\_visible = false;  
btn\_mute.\_visible = true;  
};  
playlist.load(“playlist.xml”);  
setInterval(duration,100);  
setInterval(soundStatus,100);

if you need the fla file, let me know and i’ll upload it.

Thanks.
