Linking sound to button

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

Quite simple actually :slight_smile:

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();
    _root.soundInit == false

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

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.


This is prolly creating the error sorry…:


Should be


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 {
_root.soundInit = false;

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


I just learned how to attach sound! :stuck_out_tongue:

Never tried that before :slight_smile:


I was wondering why you were posting in the F5 forum…

hehe :slight_smile:

Stumbled in here via the search…

tried to find the attachsound thingy… the flashMX help didn’t do me much good…