Copy link to clipboard
Copied
Hi. I have the below actionscript almost working for playing mp3s. This isn't dynamic or anything. Just links to songs (from buttons) that should null each other out when clicked on. The first song loads fine. However, the second song will not load. I must be missing something. Or maybe I took the wrong approach? Any help would be great.
stop();
import flash.media.SoundMixer;
var cnl:SoundChannel = new SoundChannel ();
var SongNumber1:Sound = new Sound (new URLRequest ("song1.mp3"));
var SongNumber2:Sound = new Sound (new URLRequest ("song2.mp3"));
song1_btn.addEventListener(MouseEvent.CLICK, song1);
song2_btn.addEventListener(MouseEvent.CLICK, song2);
function song1(event:MouseEvent):void {
toggleSound(cnl);
cnl = SongNumber1.play ();
}
function song2(event:MouseEvent):void {
toggleSound(cnl);
cnl = SongNumber2.play ();
}
function toggleSound(c:SoundChannel):void {
if (c) {
c.stop();
c = null;
SoundMixer.stopAll();
}
}
Copy link to clipboard
Copied
I just created a quick fla with two buttons and grabbed a couple mp3's for testing. I used the exact code you posted. It worked without a glitch. Is the filename of the second song exactly as it should be? Are you seeing any errors in the output panel?
Copy link to clipboard
Copied
Hey thanks for doing that! I guess I have AS problems elsewhere in the document. I created a clean document and it worked for me. At least I posted some decent code for someone else to use