Question

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);
Was it helpful?

Solution

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?

OTHER TIPS

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.

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 }

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.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top