# Adding a stop button

**URL:** <https://forum.kirupa.com/t/adding-a-stop-button/307829>\
**Category:** Uncategorized\
**Created:** [April 11, 2010, 3:25pm UTC](https://forum.kirupa.com/t/adding-a-stop-button/307829 "2010-04-11T15:25:32Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![billy\_brown](https://avatars.discourse-cdn.com/v4/letter/b/f6c823/32.png) [@billy\_brown](https://forum.kirupa.com/u/billy_brown)\
**Post date:** [April 11, 2010, 3:25pm UTC](https://forum.kirupa.com/t/adding-a-stop-button/307829/1 "2010-04-11T15:25:32Z")

</div>

what as would i need to add to a stop button in my mp3 player?

Here is my as:

// Collecting track details from the xml file //  
////////////////////////////////////////////////  
var tracks\_array:Array = new Array();  
var totalTracks:Number;

///////////////////////////////////////////////////////////  
// Create the XML object and populate with track details //  
///////////////////////////////////////////////////////////  
var qPlayer\_xml:XML = new XML();  
qPlayer\_xml.ignoreWhite = true;  
var RootNode:XMLNode;

qPlayer\_xml.firstChild.childNodes.length;

qPlayer\_xml.onLoad = function(success:Boolean) {  
if (success) {  
RootNode = this.firstChild;  
totalTracks = RootNode.childNodes.length;  
populateTracksArray();  
} else {  
trace(“error loading xml file”);  
}  
};  
qPlayer\_xml.load(“data2.xml”);

function populateTracksArray():Void {  
for (var i:Number = 0; i\<totalTracks; i++) {  
tracks\_array\* = RootNode.childNodes\*;  
tracks\_array\*.source = RootNode.childNodes\*.attributes.source;  
tracks\_array\*.artist = RootNode.childNodes\*.attributes.artist;  
tracks\_array\*.album = RootNode.childNodes\*.attributes.album;  
tracks\_array\*.title = RootNode.childNodes\*.attributes.title;  
tracks\_array\*.cover = RootNode.childNodes\*.attributes.cover;  
}  
//playing first track  
//playTrack(tracks\_array[0].source,tracks\_array[0].artist,tracks\_array[0].album,tracks\_array[0].title,true);  
play\_btn.\_visible = true;  
pause\_btn.\_visible = false;

//loading first cover  
cover\_loader(0);  
//populating list with song titles  
populateList();  
}

//play track function  
function playTrack(source, artist, album, title, stream):Void {  
artist\_txt.text = artist;  
album\_txt.text = album;  
title\_txt.text = title;  
soundPlayer = new Sound();  
soundPlayer.onSoundComplete = function():Void {  
//lets play the next song  
if (selectedTrack\<(totalTracks-1)) {  
selectedTrack += 1;  
} else {  
selectedTrack = 0;  
}  
playTrack(tracks\_array[selectedTrack].source,tracks\_array[selectedTrack].artist,tracks\_array[selectedTrack].album,tracks\_array[selectedTrack].title,true);  
cover\_loader(selectedTrack);  
updatevolume();  
};  
soundPlayer.loadSound(source,stream);

clearInterval(songInterval);  
songInterval = setInterval(songProgress, 100);  
}

//populating list with songs  
function populateList():Void {  
for (var i:Number = 0; i\<totalTracks; i++) {  
//list\_mc.addItem(tracks\_array\*.title,tracks\_array\*.source);  
var item = list\_mc.items\_mc.attachMovie(“clip”, “clip”+i, i);  
item.\_y = (item.\_height+2)\*i;// This places our items on y axis

item.curNr = i;  
item.\_alpha = 50;

item.info\_txt.autoSize = “left”;  
item.info\_txt.text = tracks\_array\*.artist+" - "+tracks\_array\*.title;

item.onRollOver = function() {  
this.alphaTo(100,1,“easeOutExpo”);  
};  
item.onRollOut = function() {  
this.alphaTo(50,1,“easeOutExpo”);  
};  
item.onRelease = item.onReleaseOutside=function () {  
this.alphaTo(30,1,“easeOutExpo”);  
play\_btn.\_visible = false;  
pause\_btn.\_visible = true;  
playTrack(tracks\_array[this.curNr].source,tracks\_array[this.curNr].artist,tracks\_array[this.curNr].album,tracks\_array[this.curNr].title,true);  
artist\_txt.text = tracks\_array[this.curNr].artist;  
album\_txt.text = tracks\_array[this.curNr].album;  
title\_txt.text = tracks\_array[this.curNr].title;  
selectedTrack = this.curNr;  
updatevolume();  
cover\_loader(this.curNr);  
};

//next button  
next\_btn.onRollOver = function() {  
this.alphaTo(100,1,“easeOutExpo”);  
};  
next\_btn.onRollOut = function() {  
this.alphaTo(50,1,“easeOutExpo”);  
};  
next\_btn.onRelease = function() {  
if (selectedTrack\<totalTracks-1) {  
selectedTrack += 1;  
playTrack(tracks\_array[selectedTrack].source,tracks\_array[selectedTrack].artist,tracks\_array[selectedTrack].album,tracks\_array[selectedTrack].title,true);  
updatevolume();  
cover\_loader(selectedTrack);  
} else {  
selectedTrack = 0;  
playTrack(tracks\_array[selectedTrack].source,tracks\_array[selectedTrack].artist,tracks\_array[selectedTrack].album,tracks\_array[selectedTrack].title,true);  
}  
};

//previous button  
prev\_btn.onRollOver = function() {  
this.alphaTo(100,1,“easeOutExpo”);  
};  
prev\_btn.onRollOut = function() {  
this.alphaTo(50,1,“easeOutExpo”);  
};  
prev\_btn.onRelease = function() {  
if (selectedTrack\>0) {  
selectedTrack -= 1;  
playTrack(tracks\_array[selectedTrack].source,tracks\_array[selectedTrack].artist,tracks\_array[selectedTrack].album,tracks\_array[selectedTrack].title,true);  
updatevolume();  
cover\_loader(selectedTrack);  
} else {  
selectedTrack = totalTracks-1;  
playTrack(tracks\_array[selectedTrack].source,tracks\_array[selectedTrack].artist,tracks\_array[selectedTrack].album,tracks\_array[selectedTrack].title,true);  
}  
};

}  
}

//create a listener for the list\_mc  
var compListener:Object = new Object();  
list\_mc.addEventListener(“change”,compListener);

compListener.change = function(info:Object):Void {  
playTrack(info.target.value,tracks\_array[selectedTrack].artist,tracks\_array[selectedTrack].album,tracks\_array[selectedTrack].title,true);  
};

//controls download bar and playback  
function songProgress():Void {  
amountLoaded = (soundPlayer.getBytesLoaded()/soundPlayer.getBytesTotal());  
bar\_mc.downloadbar\_mc.\_width = amountLoaded\*200;  
bar\_mc.playback\_mc.\_x = (soundPlayer.position/soundPlayer.duration)_amountLoaded_200;  
var position:Number = soundPlayer.position;  
var duration:Number = soundPlayer.duration;  
duration\_txt.text = int(duration/position);  
playback\_txt.text = bar\_mc.playback\_mc.\_x;

//calculating minutes and seconds (played and total)  
var total\_seconds:Number = soundPlayer.duration/1000;  
var minutes:Number = Math.floor(total\_seconds/60);  
var seconds = Math.floor(total\_seconds)%60;  
var total\_current\_seconds:Number = soundPlayer.position/1000;  
var current\_minutes:Number = Math.floor(total\_current\_seconds/60);  
var current\_seconds = Math.floor(total\_current\_seconds)%60;  
time\_info.text = current\_minutes+":"+current\_seconds+" / “+minutes+”:"+seconds; //displaying time

}

//playback mc/slider  
bar\_mc.playback\_mc.onRollOver = function():Void {  
this.alphaTo(100,1,“easeOutExpo”);  
};

bar\_mc.playback\_mc.onRollOut = function():Void {  
this.alphaTo(50,1,“easeOutExpo”);  
};

bar\_mc.playback\_mc.onPress = function():Void {  
[//soundPlayer.stop](https://soundPlayer.stop)();  
clearInterval(songInterval);  
this.startDrag(true,1,this.\_y,bar\_mc.downloadbar\_m c.\_width+this.\_x,this.\_y);  
};

bar\_mc.playback\_mc.onRelease = bar\_mc.playback\_mc.onReleaseOutside=function ():Void {  
this.stopDrag();  
new\_position = soundPlayer.duration\*(this.\_x-bar\_mc.downloadbar\_mc.\_x)/(bar\_mc.downloadbar\_mc.\_width\*1000);  
soundPlayer.start(new\_position);  
songInterval = setInterval(songProgress, 100);  
this.alphaTo(50,1,“easeOutExpo”);  
};

//pause button  
pause\_btn.onRollOver = function():Void {  
this.alphaTo(100,1,“easeOutExpo”);  
};

pause\_btn.onRollOut = function():Void {  
this.alphaTo(50,1,“easeOutExpo”);  
};

pause\_btn.onRelease = function():Void {  
soundPosition = soundPlayer.position;  
paused = true;  
soundPlayer.stop();  
this.\_visible = false;  
play\_btn.\_visible = true;  
};

//play button  
play\_btn.onRollOver = function():Void {  
this.alphaTo(100,1,“easeOutExpo”);  
};

play\_btn.onRollOut = function():Void {  
this.alphaTo(50,1,“easeOutExpo”);  
};

play\_btn.onRelease = function():Void {  
if (paused) {  
soundPlayer.start(soundPosition/1000);  
paused = false;  
this.\_visible = false;  
pause\_btn.\_visible = true;  
}else{  
playTrack(tracks\_array[0].source,tracks\_array[0].artist,tracks\_array[0].album,tracks\_array[0].title,true);  
}  
};

////////////////////////  
// Scrolling function //  
////////////////////////  
scrolling = function () {  
this.onEnterFrame = function() {  
xval = \_xmouse;  
yval = \_ymouse;  
///  
if (list\_mc.maskara.hitTest(xval, yval, true) == true) {  
d = Math.cos(((list\_mc.maskara.\_ymouse)/list\_mc.maskara.\_height)\*Math.PI)\*5;  
if (d\<0) {  
if (list\_mc.maskara.\_height/2-items\_mc.\_y\>list\_mc.items\_mc.\_y) {  
trace(“0”);  
}  
} else {  
if (list\_mc.maskara.\_height/2-items\_mc.\_y\<list\_mc.items\_mc.\_y) {  
trace(“1”);  
}  
}  
} else {  
d = 0;  
}  
list\_mc.items\_mc.\_y += d;  
if (list\_mc.items\_mc.\_y\>list\_mc.maskara.\_y) {  
list\_mc.items\_mc.\_y = list\_mc.maskara.\_y;  
}  
if (list\_mc.items\_mc.\_y\<(list\_mc.maskara.\_y-(list\_mc.items\_mc.\_height-list\_mc.maskara.\_height))) {  
list\_mc.items\_mc.\_y = list\_mc.maskara.\_y-(list\_mc.items\_mc.\_height-list\_mc.maskara.\_height);  
}  
};  
};  
scrolling();

////////////////  
// Set Volume //  
////////////////  
function updatevolume() {  
//calculate the new volume for the player  
newvolume = Math.max(0, Math.min(100, volumecontrol.volumeslider.\_x\*4));  
//update the video’s volume  
soundPlayer.setVolume(newvolume);  
}

//start moving the volume slider on press  
volumecontrol.onPress = function() {  
volumecontrol.volumeslider.startDrag(true,-25,0,30,0);  
};

volumecontrol.onRollOver = function():Void {  
this.alphaTo(100,1,“easeOutExpo”);  
};  
volumecontrol.onRollOut = function():Void {  
this.alphaTo(50,1,“easeOutExpo”);  
};  
//stop dragging the volume slider on release, and update the volume  
volumecontrol.onRelease = function() {  
volumecontrol.volumeslider.stopDrag();  
//update the volume of the video  
updatevolume();  
};

volumecontrol.onReleaseOutside = function() {  
this.alphaTo(50,1,“easeOutExpo”);  
volumecontrol.volumeslider.stopDrag();  
updatevolume();  
};

/////////  
// End //  
/////////
