I have some very short sound clips (less than a second) that will play on different events (hover, click, etc.). However, there is usually a significant lag between action and actual sound reproduction. I tried to embed the sound in .swf and load it from the outside at the beginning, but both of them produce the same results. Similarly, I tried compressed and uncompressed sound.
The sound buffers seem to be much longer than I need, as perhaps Flash is optimized more to play longer sounds without any stuttering due to a slightly longer delay when starting sounds. Could this be so? Is there any way to change them? Since what I'm working on will never need to play sounds for more than a second or so long and will always load completely from the very beginning, this will not hurt him to have really short buffers at all.
Another possible thing that could be the reason: if I use WAV files while using loadSound () ... I can't get it to actually play sounds. There are no errors, and everything returns as it should, but no real sound is reproduced, so I have them as .mp3 now. Perhaps when using .mp3 audio (or any compressed audio), there will simply be a lag in decoding it? The reason I still doubt it is that when embedding them in .swf as .wav files (when importing them into the library) they still have the same delay in playback.
Just to test the health, I will include the code that I have, minus the irrelevant parts and error checking. First load them at runtime:
var soundArray:Array = new Array(); loadSound( "click", "sounds/buttondroop4.mp3" ); loadSound( "hover", "sounds/Dink-Public_D-146.mp3" ); function loadSound( name:String, url:String ):void { var req:URLRequest = new URLRequest( url ); soundArray[ name ] = new Sound( req ); soundArray[ name ].addEventListener( Event.COMPLETE, soundLoaded ); } function soundLoaded( event:Event ):void { for( var name:String in soundArray ) { if( event.target == soundArray[name] ) { trace( "Loaded sound [" + name + "]" ); return; } } } function playSound( name:String ):void { for( var nameSrc:String in soundArray ) { if( name == nameSrc ) { var channel:SoundChannel = soundArray[ name ].play(); return; } } }
And an alternative way, introducing them into the library as classes and from there:
var sClick:soundClick = new soundClick(); var sHover:soundHover = new soundHover(); sClick.play(); sHover.play();
The sound files are tiny, less than 10 kb in total. The disadvantage is obvious enough that one of the first complaints that ever looked at him was that the sound effects on the buttons hung, seemed to linger, so not only was I picky. I feel that I just have to do something wrong; there are too many flash things that have instant sound effects without any close to this lag.
edit: In response to the first answer about the sound files themselves, I already checked, and the sound starts right at the beginning of the file (even cutting off everything except the very first millisecond of sound, I still hear the beginning of the βtickβ noise that it makes).