• Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers
Exit
0

Building an MP3 player in Actionscript - almost there I hope...

Community Beginner ,
Sep 25, 2009 Sep 25, 2009

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();
    }
}

TOPICS
ActionScript

Views

740

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Advocate ,
Sep 25, 2009 Sep 25, 2009

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?

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Beginner ,
Sep 27, 2009 Sep 27, 2009

Copy link to clipboard

Copied

LATEST

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

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines