AS3.0 play sound without delay
I've got a couple of classes.
My document class (Ma开发者_开发问答in.as) instantiates the class player and Soundsloader.
In the player class when the player picks up an item in the game, i want to play a short sound. I do this with the following code: MovieClip(this.main_object.sound_loader).playPickUp();
In my document class i also instantiate the SoundsLoader which basically should load all the sounds. (just one in my sample code below)
package {
import flash.display.MovieClip;
public class SoundsLoader extends MovieClip{
private var pick_up_item:sound_pickup_item = new sound_pickup_item;
public function SoundsLoader() {
}
public function playPickUp(){
pick_up_item.play();
}
}
}
However when i use the methods my swf file freezes for a moment, plays the sound and then continues. So what's the best way of doing this ? (i'm using a .wav sound)
If this only happens the first time that you play the sound, maybe due to decompressing issues. I discard download latency because you told that you are already loading all the sounds, in a preloader or something like that.
Like I said, if this only happens the first time, a workaround would be to play all the sounds at the preload time, but muted.
Example:
public function SoundsLoader() {
var songController:SoundChannel = pick_up_item.play();
var volControl:SoundTransform = songController.soundTransform;
volControl.volume = 0;
songController.soundTransform = volControl;
}
Or
public function SoundsLoader() {
var songController:SoundChannel = pick_up_item.play();
songController.stop;
}
精彩评论