On one frame in my flash project there are 6 buttons. When you click a button a different song plays. Simple. The problem is, the first song in the list is playing the second the project loads instead of waiting for someone to click the button!
import fl.events.SliderEvent;
var snd:Sound;
var channel:SoundChannel;
var trans:SoundTransform;
var currSong:String;
var currVol:Number = .5;
var currPan:Number = 0;
var songList:Array=new Array("Drifting.mp3","Push.mp3",
"Stupid.mp3","Train Wreck.mp3","World on Fire.mp3","Fallen.mp3");
panSlide.visible=false;
volSlide.visible=false;
song1.addEventListener(MouseEvent.CLICK, chooseSong);
song2.addEventListener(MouseEvent.CLICK, chooseSong);
song3.addEventListener(MouseEvent.CLICK, chooseSong);
song4.addEventListener(MouseEvent.CLICK, chooseSong);
song5.addEventListener(MouseEvent.CLICK, chooseSong);
song6.addEventListener(MouseEvent.CLICK, chooseSong);
panSlide.addEventListener(SliderEvent.CHANGE, panChange);
volSlide.addEventListener(SliderEvent.CHANGE, volumeChange);
function chooseSong(e:MouseEvent):void {
switch (e.currentTarget.name) {
case "song1":
currSong = "../MP3s/"+songList[0] as String;
break;
case "song2":
currSong = "../MP3s/"+songList[1] as String;
break;
case "song3":
currSong = "../MP3s/"+songList[2] as String;
break;
case "song4":
currSong = "../MP3s/"+songList[3] as String;
break;
case "song5":
currSong = "../MP3s/"+songList[4] as String;
break;
case "song6":
currSong = "../MP3s/"+songList[5] as String;
break;
}
if (snd != null) {
channel.stop();
}
snd = new Sound();
snd.load(new URLRequest(currSong));
channel = new SoundChannel ;
trans = new SoundTransform(currVol,currPan);
channel = snd.play();
channel.soundTransform = trans;
panSlide.visible = true;
volSlide.visible = true;
}
function volumeChange(e:SliderEvent):void {
currVol = e.target.value;
trans.volume = currVol;
channel.soundTransform = trans;
}
function panChange(e:SliderEvent):void {
currPan = e.target.value;
trans.pan = e.target.value;
channel.soundTransform = trans;
}
Are you sure you haven´t accidentally added a sound to the timeline? If not you should add a trace inside the method chooseSong and check if it is triggered when you load the project.
I created a new file with a mc (song1) on stage and this script. Does this work for you?