3

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);
vimuth
  • 5,064
  • 33
  • 79
  • 116
tronster
  • 113
  • 2
  • 2
  • 9

4 Answers4

2

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
  • 547
  • 6
  • 17
  • 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 Sep 20 '08 at 19:56
2

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
  • 1,322
  • 3
  • 11
  • 19
  • 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 Error path = "../assets/the_song.mp3" // Error #2068: Invalid Sound – tronster Sep 22 '08 at 00:42
  • 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 Sep 22 '08 at 04:16
  • 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 Sep 22 '08 at 17:13
  • 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 Sep 25 '08 at 01:40
2

You should really download httpfox for FireFox. This SNIFFER allows you to see what data is flowing through the browswer. You can see the files its loading, including the paths to each, and you can even sniff POST and GET variables. This will show you where the files are being pulled from and based off of that you can fix your relative paths accordingly.

https://addons.mozilla.org/en-US/firefox/addon/6647

Important:

All external assets called from the SWF are relative to the html file loading them when loaded on the web, not the SWF. The only exception, and this is something that started with AS3, FLV's are relative to the SWF, not the HTML document loading the SWF like every other asset. This is why SNIFFERS are an important tool, I scratched my head for a while until I noticed the URL in the sniffer was calling a weird path.

Below is how you can load sound.

var soundRequest:URLRequest = "path/to/file.mp3";
var s:Sound = new Sound(soundRequest);
var sChannel = s.play(0, int.MAX_VALUE); //Causes it to repeat by the highest possible number to flash.
//Above starts the sound immediatly (Streaming);

//Now to wait for completion instead, pretend we didnt start it before. s.addEventLister(Event.SOUND_COMPLETE, onSComplete, false, 0, true); function onSComplete(e:Event):void { var sChannel = s.play(0, int.MAX_VALUE); //Causes it to repeat by the highest possible }

Will
  • 24,082
  • 14
  • 97
  • 108
Brian Hodge
  • 2,125
  • 2
  • 19
  • 29
0

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.