The following AS3 code is sometimes causing the audio to play multiple times, almost simultaneously like a crazy echo. It usually works ok with that URL but when I use a https://soundcloud.com url it always freaks out. On rare occasions I think the issue has happened with local files even. I copied this code from somewhere else so I don’t entirely understand it. Do you see a problem with this implementation or is Flash just crazy?
var url:String = "http://md9.ca/portfolio/music/seaforth.mp3";
var request:URLRequest = new URLRequest(url);
var s:Sound = new Sound();
s.addEventListener(Event.COMPLETE, completeHandler);
s.load(request); var song:SoundChannel = s.play();
song.addEventListener(Event.SOUND_COMPLETE, soundCompleteHandler);
var time:Timer = new Timer(20);
time.start();
function completeHandler(event:Event):void {
event.target.play();
}
function soundCompleteHandler(event:Event):void {
time.stop();
}
You are calling
play()twice on theSoundobject. Once when you create the variablesongand again when the file is done loading.You might want to structure your code differently.
I removed the
Timercode as it did not do anything functional.