Attaching Sound Files
What if we wanted a sound to play upon a certain event - even if the frame hasnt changed. Well we can call upon sounds from the library providing they have a linkage.
So import a sound file into flash and give the library element a linkage name of 'soundfile'. Now on the first frame write this:
- Code: Select all
s = new Sound();
s.attachSound("soundfile");
This declares that we want to make a new sound that plays our sound. Now use this to trigger the sound whenever you like:
- Code: Select all
_root.s.start();
Linking to external Sound Files
We can also link to a sound file outside of the flash movie using the following method:
- Code: Select all
mySound = new Sound();
mySound.onLoad = function(success) {
if (success == true) {
mySound.start();
}
};
mySound.loadSound("mySoundFile.wav");
This will locate your sound file from whichever path you specified and then when it has fully loaded it - it will start to play.
To stop all sounds at any time simply use:
- Code: Select all
stopAllSounds();


