Search code examples
flashurlactionscriptaudiourlrequest

How to play a sound in Actionscript 3 that is not in the same directory as the SWF?


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);

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?