# Play immediately just by clicking on the song title

**URL:** <https://forum.kirupa.com/t/play-immediately-just-by-clicking-on-the-song-title/236065>\
**Category:** flash\
**Created:** [August 16, 2007, 9:26pm UTC](https://forum.kirupa.com/t/play-immediately-just-by-clicking-on-the-song-title/236065 "2007-08-16T21:26:39Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![lasse](https://avatars.discourse-cdn.com/v4/letter/l/96bed5/32.png) [@lasse](https://forum.kirupa.com/u/lasse)\
**Post date:** [August 16, 2007, 9:26pm UTC](https://forum.kirupa.com/t/play-immediately-just-by-clicking-on-the-song-title/236065/1 "2007-08-16T21:26:39Z")

</div>

Hey

Found this mp3 player in a tutorial [http://www.kirupa.com/web/xml/examples/MP3playlist.htm](http://www.kirupa.com/web/xml/examples/MP3playlist.htm) and it works fine, but I’m trying to get to play the song when you click the title of the song and not like it is now by first clicking on the title and then clicking on the Play btn.

I’ve tried replacing stop\_btn.onRelease with play\_btn.onRelease in the snd.loadSound function, and it does start when you click the title, but when you select another song the scrubber and position does not reset.

Can anybody help?

```auto
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;    
}

var snd = this.createEmptyMovieClip("SoundController", 1);

snd.init = function(){
    snd._sound = new Sound(this);
    this.isPlaying = false;
    this.position = 0;
    loadingbar_mc._xscale = 0;
    progressbar_mc._xscale = 0;
}
snd.loadSound = function(url){
    this._sound.loadSound(url, true);
    stop_btn.onRelease();
    this.updateTime();
    //play_btn.onRelease();
}
snd.updateTime = function(){
    var time = formatTime(snd.position);
    if (time_txt.text != time) time_txt.text = time;
}
snd._sound.onSoundComplete = function(){
    stop_btn.onRelease();
}
snd.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;
    scubber_mc._xscale = progressbar._mc._xscale;
    progressbar_mc._xscale = loadingbar_mc._xscale * this.position/this._sound.duration;
    this.updateTime();
}

play_btn.onRelease = function(){
    if (!isPlaying){
        snd._sound.start(snd.position/1000);    
        snd.isPlaying = true;
    }
}
pause_btn.onRelease = function(){
    if (!snd.isPlaying) return (0);
    snd.position = snd._sound.position;
    snd._sound.stop();
    snd.isPlaying = false;
}
stop_btn.onRelease = function(){
    snd.position = 0;
    snd._sound.stop();
    snd.isPlaying = false;
    
}

scrubber_mc.onPress = function(){
    if (!snd.loaded) return (0);
    var pos = this._xmouse/100;
    snd.position = Math.min(snd._sound.duration, pos * snd._sound.duration/snd.loaded);
    if (snd.isPlaying) snd._sound.start(snd.position/1000);
}

SetSong = function(node){
    snd.node = node;
    snd.loadSound(node.attributes.src);
    title_txt.text = node.attributes.title;    
}

snd.init();

```
