尝试勾声音元素导入Flash CS5-AS3 [英] Try Catch With Sound Element into Flash CS5-as3

查看:144
本文介绍了尝试勾声音元素导入Flash CS5-AS3的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,任何人有任何想法,为什么这code不起作用?

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

这是我收到的错误:

Error #2044: Unhandled IOErrorEvent:. text=Error #2032: Stream Error

感谢和美好的一天!

Thanks and good day!

推荐答案

您做的没有的使用try / catch语句与装载机。这里是你做什么,而不是:

You do not use try/catch with loaders. Here's what you do instead:

sound.addEventListener(IOErrorEvent.IO_ERROR, onIOErrorEvent);
sound.load(mySoundURL); 

private function onIOErrorEvent(e:IOErrorEvent):void{
  trace(e);
  trace(e.message);

  // ^  This will show you the file it tried to load and failed at

  e.currentTarget.removeEventListener(IOErrorEvent.IOError, onIOErrorEvent);
  e.currentTarget.removeEventListener(Event.COMPLETE, onComplete;
  // ^ don't forget to clean up your listeners!
}

这样做的原因是,如您所见,未捕获的错误不会告诉你任何有帮助的,比如它的声音加载失败,或者你试图联系是URL。

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.

我觉得@Alexander索博列夫是在正确的轨道,他的第一个猜测,基于这样的事实,你还是会得到一个错误。从装载机处理错误仅比同步code处理错误不同,和try / catch不会帮助你在这里。

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.

如果你想尝试从第一个失败播放中高音的声音,你会做,在onIOErrorEvent功能。

If you want to try playing an alt sound on fail from the first one, you'd do that in the onIOErrorEvent function.

其他时候,你会用装载机当加载SWF或图像文件侦听IOErrorEvent

Other times you'd listen for IOErrorEvent are when using Loader to load a swf or image file

 loader.contentLoaderInfo.addEventListener(IOErrorEvent....

或者使用URLLoader

Or a URLLoader

 urlLoader.addEventListener(IOErrorEvent...

这篇关于尝试勾声音元素导入Flash CS5-AS3的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆