<p>I am seeing strange behaviour with the flash.media.Sound class in Flex 3.</p>

<pre><code>var sound:Sound = new Sound();
try{
sound.load(new URLRequest("directory/file.mp3"))
} catch(e:IOError){
 ...
}
</code></pre>

<p>However this isn't helping. I'm getting a stream error, and it actually sees to be in the Sound constructor.</p>

<blockquote>
  <p>Error #2044: Unhandled IOErrorEvent:.
  text=Error #2032: Stream Error.   at... ]</p>
</blockquote>

<p>I saw one example in the Flex docs where they add an event listener for IOErrorEvent, SURELY I don't have to do this, and can simply use try-catch? Can I set a null event listener?</p>

[{'answer_id': 81447, 'author': 'grapefrukt', 'author_id': 914, 'author_profile': 'https://Stackoverflow.com/users/914', 'pm_score': 1, 'selected': False, 'text': '<p>You will need to add a listener since the URLRequest is not instantaneous. It will be <strong>very</strong> fast if you\'re loading from disk, but you will still need the Event-listener. \nThere\'s a good example of how to set this up (Complete with IOErrorEvent handling) in the <a href="http://livedocs.adobe.com/flash/9.0/ActionScriptLangRefV3/flash/media/Sound.html#load()" rel="nofollow noreferrer">livedocs</a>.</p>\n'}, {'answer_id': 83236, 'author': 'Antti', 'author_id': 6037, 'author_profile': 'https://Stackoverflow.com/users/6037', 'pm_score': 4, 'selected': True, 'text': '<p><a href="http://livedocs.adobe.com/flex/3/langref/flash/errors/IOError.html" rel="noreferrer">IOError</a> = target file cannot be found (or for some other reason cannot be read). Check your file\'s path.</p>\n\n<p>Edit: I just realized this may not be your problem, you\'re just trying to catch the IO error? If so, you can do this:</p>\n\n<pre>var sound:Sound = new Sound();\nsound.addEventListener(IOErrorEvent.IO_ERROR, ioErrorHandler);\nsound.load(new URLRequest("directory/file.mp3"));\n\nfunction ioErrorHandler(event:IOErrorEvent):void {\n    trace("IO error occurred");\n}\n</pre>\n'}, {'answer_id': 86120, 'author': 'davr', 'author_id': 14569, 'author_profile': 'https://Stackoverflow.com/users/14569', 'pm_score': 1, 'selected': False, 'text': "<p>try...catch only applies for errors that are thrown when that function is called. Any kind of method that involves loading stuff from the network, disk, etc will be asynchronous, that is it doesn't execute right when you call it, but instead it happens sometime shortly after you call it. In that case you DO need the addEventListener in order to catch any errors or events or to know when it's finished loading. </p>\n"}]
['https://Stackoverflow.com/questions/80863', 'https://Stackoverflow.com', 'https://Stackoverflow.com/users/13220/']