Hi, I'm new to flash and this is my first attempt at the makings of a game. At
the moment it's just the beginning of a shooter. Here's my problem:
I imported an audio file (gunshot.wav) to play when you shoot. Without the
sound it runs very smoothly, but with it, it experences a bit of lag. I don't
think it's the sound file itself, because it's not that big. It could be my
unorthodox method of playing the sound... I attached the sound to a symbol
beacause I wasn't sure how to play it any other way. Could someone tell me the
different ways of attaching an audio file, AND the reason for the lag? Please?
Here's the fla and the swf:
http://gds.ceege.net/flashgames/firstgame.swf
http://gds.ceege.net/downloads/firstgame.fla
PS: Im using a rather old version of flash - Flash MX (not the 2004 version)
Noelbaland - 04 Jul 2008 05:25 GMT
Hello there,
I looked at your FLA and have come up with some simple changes that might help
with it's performance.
1) Delete your gunshotWv movieclip from the stage. We'll use some
actionscript to create a sound object.
2) Go into the Library and right click on your gunshot.wav file. Choose
Linkage. Check the box with Export for Actionscript and give it an Identifier
of just gunshot. Click OK to close.
3) Go to your actionscript code and at the top type in the following code.
var shotSound = new Sound();
shotSound.attachSound("gunshot");
We're creating a sound object and attaching the gunshot sound to this object.
It's faster than having to go to frame in a movieclip to play a sound.
4) Come down the script till you get to the useGun function. Change the
following line from
gunshotWv.gotoAndPlay(2);
to
shotSound.start();
This will play the sound object and cut the lag in the time it takes to press
the SPACE bar.
Try that and see if that makes a difference to you. You might also want to
try trimming the gunshot.wav file with an external audio tool (like Audacity).
Hope that helps