PDA

View Full Version : linking sound to button



FnyBoy4021
July 12th, 2002, 04:54 PM
hi.. i read the turorial on how to link the music usin layers and all.....but how do i make it so when u click it plays my song.... like a music on button...and when u click it music starts playing.... thx for thehelp

ptolemy
July 13th, 2002, 11:18 AM
Quite simple actually :)

First thing to do is export your sound to ActionScript from the library. Name it something relevant like "track_1" or "intro_song". Then, attach the following code to your button:



on(release) {
if(!mySound) {
mySound = new Sound();
mySound.attachSound("exported_name");
_root.soundInit == false
}

if(_root.soundInit == false) {
mySound.start(0, numberOfLoops);
_root.soundInit = true;
} else {
mySound.stop(("exported_name");
_root.soundInit = false;
}
}

brian monkey
July 15th, 2002, 01:03 AM
okay. I do what you said but it won't work unless I hit Export in First Frame . But, when I hit that my preloader doesn't even show up.
the sound button is in the second frame and the preloader is supposed to load it.
also, if you figure this out will you explain to me how to make the sound stop too.

_root.brian.thank_you

ptolemy
July 15th, 2002, 01:39 AM
This is prolly creating the error sorry...:



mySound.stop(("exported_name");


Should be



mySound.stop("exported_name");


There's no need to export in first frame as far as I know. I've done this many times beofre without exporting in first frame and it works fine.



} else {
mySound.stop(("exported_name");
_root.soundInit = false;
}


This will stop the sound if the sound is already playing.


-ptolemy

eilsoe
October 27th, 2002, 04:25 PM
I just learned how to attach sound! :P

Never tried that before :)


thx!!

pom
October 27th, 2002, 04:46 PM
I was wondering why you were posting in the F5 forum...

eilsoe
October 27th, 2002, 04:51 PM
hehe :)

Stumbled in here via the search...


tried to find the attachsound thingy... the flashMX help didn't do me much good...