1 Reply Latest reply on Sep 30, 2009 12:58 PM by danpearce.me

    Creating my own Media Player and Linking .mp3 Songs to Different Instances of the Same Button

    danpearce.me

      Hi there, I am pretty new to Flash so bear with me! Any help will be greatly appreciated.

       

      Please go here to see what I’m trying to do: http://www.danpearce.me. This is a little webpage I'm building as I learn more and more flash. I am at a point where I need help linking .mp3 files to the buttons on the "Dan's Top Songs Playlist".

       

      If you like, you can download my flash file here: http://www.danpearce.me/fbar.zip.

       

      I am working with ActionScript 3.0.

      The buttons in the Media Player are all instances of the same button. How do I tie each button to a different .mp3 song to play when clicked (and stop when another song is clicked or the pause button is clicked)? Because of the size of song files, I'd like to stream it.

      Also, is there any way to use the “repeat” symbol to just play all the songs in order and the “shuffle” symbol to play them in random order?

      Sorry, I’ve searched the internet high and low and can’t seem to figure out how to do this. I’m sure I’m just typing in the wrong things.

        • 1. Re: Creating my own Media Player and Linking .mp3 Songs to Different Instances of the Same Button
          danpearce.me Level 1

          Okay, I figured it out myself, so thought I'd post the answer to my original question...

           

          For the first song/button, this was my ActionScript (3.0):

           

           

          //1.
          var my_sound:SoundId = new SoundId();
          var my_channel:SoundChannel = new SoundChannel();

          //2.
          mb1.addEventListener(MouseEvent.CLICK, playSound);
          stop_btn.addEventListener(MouseEvent.CLICK, stopSound);

          //3.
          function playSound(event:MouseEvent):void{
          SoundMixer.stopAll();
          my_channel = my_sound.play();
          }

          //4.
          function stopSound(event:MouseEvent):void{
          SoundMixer.stopAll();
          my_channel.stop();
          }
          //END OF SONG

           

           

           

          Then, to make the second button link, here was my code for the next one:

           

          //NEW SONG

          //1.
          var my_sound_rs:SoundId2 = new SoundId2();

          //2.
          function playSoundrs(event:MouseEvent):void{
          SoundMixer.stopAll();
          my_channel = my_sound_rs.play();
          }

          //3.

          rs.addEventListener(MouseEvent.CLICK, playSoundrs);

           

          //END OF SONG

           

           

           

          Note the red shows what I changed from one section to the next. Hope this helps anybody else trying to do this.

           

          Dan