Permalink
Browse files

Get the error handler in place before starting to load sounds.

Otherwise, nothing's listening for the IOErrorEvent yet and things blow up
spectacularly if the file isn't there.

I'm a little freaked out that it's still going straight into calling onInit()
in case of a streaming sound, but hopefully anything using that is behaving
properly in the face of a streaming error.
  • Loading branch information...
1 parent bd0caee commit 813af4257747fb154240da7fd21abac4d907f657 @deadmoose deadmoose committed Jan 4, 2012
Showing with 7 additions and 2 deletions.
  1. +7 −2 src/main/as/com/threerings/flashbang/resource/SoundResource.as
@@ -104,7 +104,13 @@ public class SoundResource extends Resource
_pan = getLoadParam(PAN, 0);
if (hasLoadParam(URL)) {
- _sound = new Sound(new URLRequest(getLoadParam(URL)));
+ _sound = new Sound();
+
+ // Immediately set up the error listener to protect against blowing up
+ _sound.addEventListener(IOErrorEvent.IO_ERROR, onIOError);
+
+ // And THEN start it loading
+ _sound.load(new URLRequest(getLoadParam(URL)));
var stream :Boolean =
getLoadParam(STREAM, false) ||
@@ -117,7 +123,6 @@ public class SoundResource extends Resource
onInit();
} else {
_sound.addEventListener(Event.COMPLETE, onInit);
- _sound.addEventListener(IOErrorEvent.IO_ERROR, onIOError);
}
} else if (hasLoadParam(EMBEDDED_CLASS)) {

0 comments on commit 813af42

Please sign in to comment.