Click a Button Symbol to play an .mp3 clip

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • flash15
    New Member
    • Aug 2008
    • 1

    Click a Button Symbol to play an .mp3 clip

    What actionscript do I need to add to have a user click on a button symbol to play a 30 second music clip (mp3 file) in Flash MX 2004?
  • nomad
    Recognized Expert Contributor
    • Mar 2007
    • 664

    #2
    what version of flash are you using.
    and do you want to stream the mp3 clip or have it embed in flash.

    nomad

    Comment

    • maximillion511
      New Member
      • Jul 2008
      • 22

      #3
      go here

      if i read what youre saying correctly, go to the URL above

      Comment

      • bnashenas1984
        Contributor
        • Sep 2007
        • 257

        #4
        Here is the code you need for AS3 to be able to play a mp3 file when a button is clicked

        Lets say we have a button on the stage called "myButton_b tn"


        Code:
        myButton_btn.addEventListener(MouseEvent.CLICK, buttonIsClicked);
        
        function buttonIsClicked(event:Event):void
        {
        var sndcontext:SoundLoaderContext = new SoundLoaderContext(4000);
        var snd:Sound = new Sound(new URLRequest("http://www.yourdomain.com/yoursound.mp3"), sndcontext);
        var sndchannel:SoundChannel = snd.play(0,1000);
        sndchannel.soundTransform = new SoundTransform(0.2, 1);
        }
        And here are details for this script

        SoundLoaderCont ext(4000) is the limit of your buffer. This means that your sound must be buffered at least 4000 milliseconds (4 seconds) to be played.

        snd.play(0,1000 ) shows how many times your music should be played

        SoundTransform( 0.2, 1) the fist number shows the volume of your sound and the second one shows the balance on your speakers . Between -1 and 1 for left and right balance on your speakers

        Hope it helps

        Good luck

        Comment

        Working...