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)amountLoaded200;
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();
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 //
/////////