문제

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.

도움이 되었습니까?

해결책

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);
}
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top