View Full Version : Adding Sound to MovieClip Button
skelebunny
10-23-2008, 08:20 PM
Hi Everyone. I'm having trouble adding a sound to a movieclip button. I know I have to use the sound class but I really have no idea how to phrase it with actionscript. All I want to happen is when you click the button it makes a sound. I'm using actionscript 3.0.
Thanks a lot!
runtime
10-23-2008, 10:30 PM
off the top of my head try:
var snd:Sound = new Sound();
snd.load(new URLRequest("my.mp3"));
myMovieClip.addEventListener(MouseEvent.CLICK, playSound, false, 0, true);
function playSound(evt:MouseEvent):void {
snd.play();
}
Check my syntax. I've been exclusively writing AS2 for the last few months so my AS3 is rusteh :/
skelebunny
10-24-2008, 03:50 PM
Hey Runtime. I tried that code but didn't have any luck. Am I supposed to do something with my sound file after I import into my library?
Thanks
runtime
10-24-2008, 04:03 PM
yes, there are a couple of things you will have to do. (i tested this just now and it does work).
edit:
there is no need to import the sound to your library.
embedding the sound will increase your file size/load time.
simply put your mp3 in the same folder as your swf.
first, the obvious:
did you change my code to match the names of your movie clip and your mp3?
secondly:
make sure you name your MC in the properties window.
make sure the mp3 is in the same folder as your SWF.
for remote:
if you are posting this remotely, you will need to change the string "my.mp3" to "http://www.yourwebsite.com/yourflashprojectfolder/my.mp3"
skelebunny
10-24-2008, 10:29 PM
So this is the code that I used:
var soundBtn:Sound = new Sound();
soundBtn.load(new URLRequest("click.wav"));
button_mc.addEventListener(MouseEvent.CLICK, playSound, false, 0, true);
function playSound(evt:MouseEvent):void
{
soundBtn.play();
}
I placed my click.wav file in the same folder as my swf file but it's still not working. Does it have to be an mp3?
Thanks again.
runtime
10-27-2008, 03:47 PM
hmm, good question. I am not sure if .wav is supported. I cannot convert mp3 to wav with the computer I am at. If you are on PC, i'm sure you can find a .wav to .mp3 converter for free.
Btw, when you paste code, use the "[AS]" tags around your code so it's easier for others to read. its activated by clicking on the flash icon above your post.
good luck.
atomic
10-27-2008, 04:04 PM
You cannot dynamically load a .wav, only mp3's.
|
vBulletin® v3.8.4, Copyright ©2000-2009, Jelsoft Enterprises Ltd.