我有一个带有一堆外部声音的项目到SWF。我想播放它们,但是每当我尝试将新URL加载到声音对象中时,它都会失败,

  

错误#2068:声音无效

或使用

引发ioError
  

错误#2032流错误

//尝试使用前缀为“http://..&quot ;; "文件://.." " //..& QUOT;和“..”")

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);
有帮助吗?

解决方案

嗯,我刚刚在一个目录中放了一个测试: soundTest / assets / song.mp3 然后在另一个目录中创建一个调用mp3的swf: soundTest /swfs/soundTest.swf 当我使用 var path:String =" ../ assets / song.mp3&quot ;; 时,它编译时没有错误。

您的实际目录结构是什么?

其他提示

除非您要填写完整的网址,否则请勿使用http://或file://

声音可以从完整或相对网址加载mp3文件。您只需要确保您的网址正确无误。

例如,如果文件的完整路径是 http://www.something。 com / assets / the_song.mp3 ,路径为“/assets/the_song.mp3"会工作的。

你应该真的为FireFox下载httpfox。此SNIFFER允许您查看正在浏览浏览器的数据。您可以看到它加载的文件,包括每个文件的路径,甚至可以嗅探POST和GET变量。这将显示文件的拉出位置,并根据您可以相应地修复相对路径。

https://addons.mozilla.org/en-US/firefox /插件/ 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 }

在两种协议中,RTMP& HTTP,路径应该是 - " path / to / mp3:file.mp3"或“path / to / mp3:file”。我能记住。请检查两者。

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top