Hello Flash Kit Community. I have a pretty easy question for you Flash gurus regarding a script I am using to play mp3s via an XML file. The example I found does the job just fine, but it plays the 1st song right away when it loads. I would like to stop the song from playing on load and let the user activate it by pushing the play button instead.
This is the code:
actionscript Code:
title_txt.autoSize = "left";
timeDisplay_txt.autoSize = "left";
toolTip._visible = false;
var amountLoaded:Number;
var duration:Number;
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[i] = playlist.firstChild.childNodes[i].attributes.name;
_global.songband[i] = playlist.firstChild.childNodes[i].attributes.band;
_global.songfile[i] = playlist.firstChild.childNodes[i].attributes.file;
attachMovie("butTemp","but"+i,i+50);
eval("but"+i).id=i;
_root["but"+i]._x = 5;
_root["but"+i]._y = 40 + (i*15);
_root["but"+i].but_txt.text = songname[i];
if (i >= 3){
_root["but"+i]._x = 160
_root["but"+i]._y = -5 + (i*15);
}
_root["but"+i].onRelease = function(){
clearInterval(timeInterval);
_root.timeDisplay_txt.text = "00:00/00:00";
_root.sound_mc.songStarter(songfile[this.id]);
}
}
}
_root.createEmptyMovieClip("sound_mc", 1);
_global.song_nr = random(songfile.length);
_root.sound_mc.songStarter(songfile[song_nr]);
};
MovieClip.prototype.songStarter = function(file) {
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.sound_obj.setVolume(0);
this.onEnterFrame = function() {
if (this.sound_obj.position>0) {
delete this.onEnterFrame;
timeInterval = setInterval(timer, 1000, this.sound_obj);
track = this.sound_obj.id3.songname;
artist = this.sound_obj.id3.artist;
this._parent.title_txt.text =artist+" - "+track;
} else {
this._parent.title_txt.text = "loading...";
}
};
this.sound_obj.onSoundComplete = function() {
clearInterval(timeInterval);
_root.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]);
};
this._parent.volume1.dragger.onPress = function() {
startDrag(this, true, 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(p);
};
};
this._parent.volume1.dragger.onRelease = function() {
delete this.onEnterFrame;
stopDrag();
};
this._parent.volume1.dragger.onReleaseOutside = function() {
_root.toolTip._visible = false;
stopDrag();
};
};
btn_play.onRelease = function() {
clearInterval(timeInterval);
_root.timeDisplay_txt.text = "00:00/00:00";
this._parent.sound_mc.songStarter(songfile[song_nr]);
};
btn_stop.onRelease = function() {
clearInterval(timeInterval);
_root.timeDisplay_txt.text = "00:00/00:00";
this._parent.sound_mc.sound_obj.stop();
};
btn_fw.onRelease = function() {
clearInterval(timeInterval);
_root.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]);
};
btn_rev.onRelease = function() {
clearInterval(timeInterval);
_root.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]);
};
playlist.load("playlist.xml");
setInterval(duration,100);
setInterval(soundStatus,100);
I'm thinking it might be around these lines:
actionscript Code:
this.sound_obj = new Sound(this);
this.sound_obj.loadSound(file, true);
this.sound_obj.setVolume(0);
Can anyone help?