Question

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.

Était-ce utile?

La solution

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);
}
Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top