So, for a little game that I have been destructing I was in the need of loading some simple sound effects. I grabbed an audio file from Flashkit.com and created this extremely simple/basic package:
package {
import flash.display.Sprite;
import flash.media.Sound;
import flash.net.URLRequest;
import flash.media.SoundChannel;
public class LoadAudio extends Sprite {
private var snd:Sound = new Sound();
private var channel:SoundChannel = new SoundChannel();
public function LoadAudio() {
var req:URLRequest = new URLRequest("audio/PowerUp.mp3");
snd.load(req);
channel = snd.play();
}
}
}
I placed the above code in a file appropriately named: LoadAudio.as and set LoadAudio as the document class of my .fla file.
…and for looping audio (as an alternative to snd.play(0,xNumofTimes), add the following:
channel.addEventListener(Event.SOUND_COMPLETE,loopSound);
function loopSound(e:Event):void{
channel = snd.play();
}
if I put a web url it says Error opening URL ‘http://www.newgrounds.com/audio/download/245921′
Error #2044: Unhandled IOErrorEvent:. text=Error #2032: Stream Error.
at LoadAudio()
it is a download url however
I get this same error if I use it in flash. Any Ideas as to what is wrong?
Daniel & Fred,
This may be because of a the Flash Security Settings – try and use a relative path to the audio file rather than an absolute one.
-M