views:

3886

answers:

5

I have a project with a bunch of external sounds to a SWF. I want to play them, but any time I attempt load a new URL into the sound object it fails with either "Error #2068: Invalid Sound" or raises an ioError with "Error #2032 Stream Error".

// Tried with path prefixed with "http://.." "file://.." "//.." and "..")

var path:String = "http://../assets/the_song.mp3";

var url:URLRequest = new URLRequest( path );

var sound:Sound = new Sound();

sound.addEventListener( IOErrorEvent.IO_ERROR, ioErrorHandler);

sound.addEventListener( SecurityErrorEvent.SECURITY_ERROR, secHandler);

sound.load(url);

+1  A: 

Unless you're going to put a full url, don't use http:// or file://

Sound can load an mp3 file from a full or relative url. You just need to make sure your url is correct and valid.

For example, if the full path to the file is http://www.something.com/assets/the_song.mp3, a path of "/assets/the_song.mp3" would work.

ZorroDeLaArena
Sorry I wasn't clear in the example at the top. If I try your suggestion of path = "../assets/the_song.mp3" I receive and error of "Error #2068: Invalid Sound". (I also just tried "/../assets/the_song.mp3" which resulted in the same error.)
tronster
A: 

Are you sure the sound-file itself is not the problem?

2068    Invalid sound

Sure seems like less of an empty path and more of a format munge.

defmeta
Yes, because if I put the sound file in the same path as the SWF and set path="the_song.mp3" it works find. I also don't see what you say I'm munging.
tronster
+1  A: 

Well, I've just done a test by putting an mp3 in a directory: soundTest/assets/song.mp3 then creating a swf that calls the mp3 in another directory: soundTest/swfs/soundTest.swf and when I use var path:String = "../assets/song.mp3"; then it compiles with no errors.

What is your actual directory structure?

defmeta
I don't have any compile-time errors either but I get a run-time error (and the sound doesn't play) when I try either of the following:path = "http://../assets/the_song.mp3" // ioErrorEvent, Error #2032 Stream Errorpath = "../assets/the_song.mp3" // Error #2068: Invalid Sound
tronster
Note those are two samples, looks like returns don't get put into comments. Just want to stress I'm receiving a run-time error, not a compile time error.
tronster
Hmmm, I am also NOT getting any run-time errors. The only difference between my example code and yours, is that I am not listening for any IO or Security errors. Could you try it with those stripped out?
defmeta
I realized in doing this test that I need to move back the MP3. After it worked, I tried adding the sercurity events back in and it worked as well. That makes sense... there was a stream error because there was no stream. Thank you.
tronster
Hey, I'm glad we got this worked out!
defmeta
+1  A: 
Brian Hodge
A: 

In both protocol, RTMP & HTTP, the path should be -- "path/to/mp3:file.mp3" or "path/to/mp3:file". I can remember. Please check both.