Monday, March 23, 2009

how to set up a sound

// set up a url request and link it to a sound
var musicURL:URLRequest = new URLRequest("xxx.mp3");
var sndMusic:Sound = new Sound(musicURL);
var channel1:SoundChannel;

// event handlers starts with a function, this one is to check that the sound load correct
function errorMsg(evt:IOErrorEvent):void{
trace("the sound could not be loaded");
}
sndMusic.addEventListener(IOErrorEvent.IO_ERROR, errorMsg);
function soundLoaded(evt:Event):void{
trace("music is loaded");
channel1 = sndMusic.play();
}
sndMusic.addEventListener(Event.COMPLETE, soundLoaded);

No comments: