尝试将声音元素捕获到 Flash CS5-as3 中
大家好——有人知道为什么这段代码不起作用吗?
与其他负载[示例图像]完美配合声音...不:(
mySoundURL = new URLRequest(var+".mp3");
mySoundURLDefault = new URLRequest("default.mp3");
try{
sound.load(mySoundURL);
}catch(e:IOErrorEvent){
trace("Can't load sound: "+e);
sound.load(mySoundURLDefault);
}
这是我收到的错误:
Error #2044: Unhandled IOErrorEvent:. text=Error #2032: Stream Error
谢谢,美好的一天!
Hi All—anyone has any idea why this code doesn’t work?
With other load [example image] work perfect with sound...no :(
mySoundURL = new URLRequest(var+".mp3");
mySoundURLDefault = new URLRequest("default.mp3");
try{
sound.load(mySoundURL);
}catch(e:IOErrorEvent){
trace("Can't load sound: "+e);
sound.load(mySoundURLDefault);
}
this is the error I’m getting:
Error #2044: Unhandled IOErrorEvent:. text=Error #2032: Stream Error
Thanks and good day!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您不将 try/catch 与加载器一起使用。下面是您要做的事情:
正如您所看到的,这样做的原因是,未捕获的错误不会告诉您任何有用的信息,例如哪个声音加载失败,或者您尝试联系的 URL 是什么。
我认为@Alexander Sobolev 的第一个猜测是正确的,因为你仍然会遇到错误。处理来自加载器的错误与处理来自同步代码的错误只是不同,try/catch 在这里不会为您提供帮助。
如果您想尝试在第一个声音失败时播放替代声音,您可以在 onIOErrorEvent 函数中执行此操作。
其他时候,您会在使用 Loader 加载 swf 或图像文件
或 URLLoader时监听 IOErrorEvent
You do not use try/catch with loaders. Here's what you do instead:
The reason for this is, as you've seen, the uncaught error does not tell you anything helpful, such as which sound failed to load, or what the URL you tried to contact was.
I think @Alexander Sobolev is on the right track with his first guess, based on the fact that you still get an error. Handling errors from loaders is just different than handling errors from synchronous code, and try/catch will not help you here.
If you want to try playing an alt sound on fail from the first one, you'd do that in the onIOErrorEvent function.
Other times you'd listen for IOErrorEvent are when using Loader to load a swf or image file
Or a URLLoader
帖子中的信息不多,我建议检查以下条件:
1)您的
var+".mp3"
是正确的 URI 吗?它是否指向现有文件?只需在浏览器中尝试一下 - 它应该找到该文件吗?如果您指向互联网上的文件,您应该使用类似 http://site.com/song.mp3
如果您尝试播放硬盘上的文件,您应该使用直接文件地址,例如 C:/audio/song.mp3
2) 如果 URI 没问题,则文件可能不是 mp3 格式。
3)你可以尝试像这样使用SoundLoaderContext
It is not much information in the post, i suggest to check following conditions:
1) Is your
var+".mp3"
a correct URI? Does it point to the existing file? Just try in the browser - should it find the file?If you are pointing to the file in internet you should use notation like http://site.com/song.mp3
If you are trying to play a file on your hard drive you should use direct file address like C:/audio/song.mp3
2) If its ok with the URI than maybe file is not in mp3 format.
3) You can try to play with SoundLoaderContext like