PDA

View Full Version : Problem playing a sound effect


norfy
06-14-2006, 12:59 PM
I've got a space ship that moves to different _x positions and at each point it stops and fires a missle upwards, I'm trying to set a small sound effect against this fire function, but getting nothing out.

I've got a small mp3 file that I have imported to the library and I have called the linkage "laser". Is this all I have to do to get the sound into flash?

Then in my code I have a function that fires the missle so at the top of that function I call a function called playSound(). which looks like this
function playSound(){
trace("bang");
newSound = new Sound();
newSound.attachSound("laser");
newSound.start();
}

But nothing happens when the movie runs. I've tried using the same sound in a test movie and called it when I click on a button and that works, is there something I need to do to script a sound event happening from a function rather than a movie clip event??

Appreciate any help.
Mark

norfy
06-14-2006, 01:14 PM
Fixed it - I added 'this' into the new Sound() code and it worked.

billingsgate
06-14-2006, 02:53 PM
It would be slightly more efficient if you create the Sound object outside the script, so that the Sound object is created only once, not each time the function is called. You can then (if you want) use the same Sound object in another function as well.
var newSound:Sound = new Sound();
newSound.attachSound("laser");
function playSound(){
newSound.start(0,1);
}