Skip navigation
m-invincible-j
Currently Being Moderated

problem with making a button please help

Aug 9, 2012 9:33 PM

hi guys

 

i have problem with making a button to play/stop music using the code snippets

 

first i imported a music file with mb3 format to the library then i dragged a button from the components panal

 

the thing is i want to make a button that when i hit it once the music starts and when i hit it again it stops

 

so, i went to code snippets i choose audio and video then i choose click to play/stop sound

 

 

 

and this is the actionscript

 

 

 

 

/* Click to Play/Stop Sound

Clicking on the symbol instance plays the specified sound.

Clicking on the symbol instance a second time stops the sound.

 

Instructions:

1. Replace "http://www.helpexamples.com/flash/sound/song1.mp3" below with the desired URL address of your sound file. Keep the quotation marks ("").

*/

 

btn.addEventListener(MouseEvent.CLICK, fl_ClickToPlayStopSound_5);

 

var fl_SC_5:SoundChannel;

 

//This variable keeps track of whether you want to play or stop the sound

var fl_ToPlay_5:Boolean = true;

 

function fl_ClickToPlayStopSound_5(evt:MouseEvent):void

{

    if(fl_ToPlay_5)

    {

        var s:Sound = new Sound(new URLRequest("http://www.helpexamples.com/flash/sound/song1.mp3"));

        fl_SC_5 = s.play();

    }

    else

    {

        fl_SC_5.stop();

    }

    fl_ToPlay_5 = !fl_ToPlay_5;

}

 

 

 

 

 

 

anyway in the instructions it says that i should replace the url with the music file but i have it in the library

 

not as url how can i put it in the actionscript without making errors cus i tried it hundreds of time and im

 

trying this for a month and it always has error .

 

im about to get mad so pleeeese  pleeeeeeese  help meee.

 
Replies

More Like This

  • Retrieving data ...

Bookmarked By (0)

Answers + Points = Status

  • 10 points awarded for Correct Answers
  • 5 points awarded for Helpful Answers
  • 10,000+ points
  • 1,001-10,000 points
  • 501-1,000 points
  • 5-500 points