我有一个带有一堆外部声音的项目到SWF。我想播放它们,但是每当我尝试将新URL加载到声音对象中时,它都会失败,
错误#2068:声音无效
或使用
引发ioError错误#2032流错误
//尝试使用前缀为“http:// ..”的路径“file:// ..”“// ..”和“..”)
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);
答案 0 :(得分:2)
除非您要填写完整的网址,否则请勿使用http://或file://
声音可以从完整或相对网址加载mp3文件。您只需要确保您的网址正确无误。
例如,如果文件的完整路径为http://www.something.com/assets/the_song.mp3,则路径“/assets/the_song.mp3”将起作用。
答案 1 :(得分:2)
好吧,我刚刚做了一个测试,将mp3放在一个目录中:soundTest/assets/song.mp3
然后在另一个目录中创建一个调用mp3的swf:soundTest/swfs/soundTest.swf
当我使用var path:String = "../assets/song.mp3";
时然后它编译没有错误。
您的实际目录结构是什么?
答案 2 :(得分:2)
你应该真的为FireFox下载httpfox。此SNIFFER允许您查看正在浏览浏览器的数据。您可以看到它加载的文件,包括每个文件的路径,甚至可以嗅探POST和GET变量。这将显示文件的拉出位置,并根据您可以相应地修复相对路径。
https://addons.mozilla.org/en-US/firefox/addon/6647
重要:强>
从SWF调用的所有外部资源都是相对于加载到Web上的html文件,而不是SWF。唯一的例外,这是从AS3开始的,FLV是相对于SWF的,而不是像所有其他资产一样加载SWF的HTML文档。这就是为什么SNIFFERS是一个重要的工具,我抓了一会儿,直到我注意到嗅探器中的URL叫做一个奇怪的路径。
以下是加载声音的方法。
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 }
答案 3 :(得分:0)
在两种协议中,RTMP& HTTP,路径应该是 - “path / to / mp3:file.mp3”或“path / to / mp3:file”。我能记住。请检查两者。