我正在尝试使用以下代码从外部SWF加载样式,但是当URL无效时,我不断收到ActionScript错误:
Error: Unable to load style(Error #2036: Load Never Completed. URL: http://localhost/css/styles.swf): ../css/styles.swf.
at <anonymous>()[C:\autobuild\3.2.0\frameworks\projects\framework\src\mx\styles\StyleManagerImpl.as:858]
private function loadStyles(): void
{
try
{
var styleEvent:IEventDispatcher =
StyleManager.loadStyleDeclarations("../styles.swf");
styleEvent.addEventListener(StyleEvent.COMPLETE,
loadStyle_completeHandler);
styleEvent.addEventListener(StyleEvent.ERROR,
loadStyle_errorHandler);
}
catch (error:Error)
{
useDefault();
}
}
private function loadStyle_completeHandler(event:StyleEvent): void
{
IEventDispatcher(event.currentTarget).removeEventListener(
event.type, loadStyle_completeHandler);
goToNextStep();
}
private function loadStyle_errorHandler(event:StyleEvent): void
{
IEventDispatcher(event.currentTarget).removeEventListener(
event.type, loadStyle_errorHandler);
useDefault();
}
我基本上想继续使用默认样式,如果无法加载此文件,则用户不会看到错误-但我似乎找不到任何方法来执行此操作。
最佳答案
有趣的问题。尝试删除removeEventListener调用,或将其注释掉;在我的简短测试中,似乎事件处理程序被调用了两次(我不确定为什么会这样,尽管我怀疑它与样式继承有关),然后注释该行就可以了。
如果结果相同,则可以先尝试检查侦听器(使用hasEventListener),然后再将其附加到loadStyles()函数中。希望能帮助到你!
关于css - 在从中加载样式是否(或捕捉到错误)之前,如何测试SWF URL?,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/448777/