我正在尝试使用以下代码从外部 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 - 如何在从 if 加载样式(或捕获错误)之前测试 SWF URL?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/448777/