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

I have a project with a bunch of external sounds for SWF. I want to play them, but at any time when I try to load a new URL into a sound object, it fails with "Error No. 2068: Invalid sound" or causes "ioError" with the error "Error No. 2032".

// Tried the path with the prefix "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);

+3
source share
4 answers

Well, I just passed the test by putting mp3 in the directory:, soundTest/assets/song.mp3then creating swf that calls mp3 in another directory: soundTest/swfs/soundTest.swfand when I use it var path:String = "../assets/song.mp3";, then it compiles without error.

What is your actual directory structure?

+2
source

If you are not going to provide the full URL, do not use http: // or the file: //

Sound can download mp3 file from 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 , the path "/assets/the_song.mp3" will work.

+2
source

httpfox FireFox. SNIFFER , browswer. , , , POST GET. , , .

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

:

, SWF, html, , SWF. , , AS3, FLV SWF, HTML-, SWF, . SNIFFERS - , , , URL- sniffer .

.

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 }

+2
source

In both protocols, RTMP and HTTP path must be - "path / to / mp3: file .mp3" or "path / to / mp3: file". I remember. Check both.

0
source

Source: https://habr.com/ru/post/1697259/


All Articles