0

i am trying to load a sound and play it when two nape bodies collide i have the collision detection working but cant play the sound the error is coming from the following code:

var collisionSound:Sound;


collisionSound = new Sound();
collisionSound.addEventListener(Event.COMPLETE, onSoundLoaded);
collisionSound.load(new URLRequest("bang.mp3"));


private function onSoundLoaded(e:event):void
{
    collisionSound.play();
}

i have sample code in another script very similar to this thaat works help would be greatly appreciated.

4

1 回答 1

5

Did you try playing it after it is loaded? Also add error handlers to see if there are any errors while loading the file.

collisionSound = new Sound();
collisionSound.addEventListener(Event.COMPLETE, onSoundLoaded);
collisionSound.addEventListener(IOErrorEvent.IO_ERROR, onSoundLoadError);
collisionSound.load(new URLRequest("bang.mp3"));


private function onSoundLoaded(e:Event):void
{
   collisionSound.play();
}

private function onSoundLoadError(e:IOErrorEvent):void
{
   trace(e.text);
}
于 2013-03-27T16:00:00.500 回答