Flex 4.0/4.5 全局错误处理
我正在尝试使用新的 AS3 全局错误处理类。我正在尝试在 Flex mxml 应用程序中使用它。我根本无法让它工作。下面是显示问题的完整程序。我将其设置为使用 Flash Player 10.2 并使用 Flex 4.5 SDK 进行编译。
我尝试过使用 Flex SDK 4.0 和 4.5,但在任何一种情况下都会出现错误。我一定在这里遗漏了一些明显的东西。这是将在网页上显示的普通 Flex SWF 文件。假设我可以导入 UncaughtErrorEvent,然后我会执行类似的操作来设置事件处理程序:
if(systemManager.loaderInfo.hasOwnProperty("uncaughtErrorEvents")) {
IEventDispatcher(
systemManager.loaderInfo["uncaughtErrorEvents"]).addEventListener(
"uncaughtError", uncaughtErrorHandler);
}
这一切看起来都非常混乱,但我可以接受,除了它不起作用!我搜索过网络,但找不到任何文档或示例来解释如何在我的上下文中实现此功能。有什么建议吗?
完整程序:
<?xml version="1.0" encoding="utf-8"?>
<s:Application xmlns:fx="http://ns.adobe.com/mxml/2009"
xmlns:s="library://ns.adobe.com/flex/spark"
xmlns:mx="library://ns.adobe.com/flex/mx" minWidth="955" minHeight="600" applicationComplete="onApplicationComplete();"
>
<fx:Declarations>
<!-- Place non-visual elements (e.g., services, value objects) here -->
</fx:Declarations>
<fx:Script>
<![CDATA[
private function onApplicationComplete() : void {
systemManager.loaderInfo.uncaughtErrorEvents.addEventListener("uncaughtError", uncaughtErrorHandler);
}
private function uncaughtErrorHandler(event:Event) : void {
trace(event.toString());
}
]]>
</fx:Script>
<s:Button x="153" y="64" label="Trigger Error" id="triggerButton" click="throw new Error('myError')"/>
</s:Application>
I'm trying to use the new(ish) AS3 global error handling class. I am trying to use it within a Flex mxml application. I can't get it to work at all. Below is an entire program that shows the problem. I set this to use Flash Player 10.2 and compiled with the Flex 4.5 SDK.
I've tried using Flex SDK 4.0 and 4.5 but I get the error in either case. I must be missing something obvious here. This is a normal Flex SWF file that will be shown on a web page. Assuming I could import the UncaughtErrorEvent, I would then do something like this to setup the event handler:
if(systemManager.loaderInfo.hasOwnProperty("uncaughtErrorEvents")) {
IEventDispatcher(
systemManager.loaderInfo["uncaughtErrorEvents"]).addEventListener(
"uncaughtError", uncaughtErrorHandler);
}
this all seems horribly kludgy but I could live with that except that it doesn't work! I've scoured the web and cannot find any docs or examples that explain how to make this work in my context. Any advice?
Complete program:
<?xml version="1.0" encoding="utf-8"?>
<s:Application xmlns:fx="http://ns.adobe.com/mxml/2009"
xmlns:s="library://ns.adobe.com/flex/spark"
xmlns:mx="library://ns.adobe.com/flex/mx" minWidth="955" minHeight="600" applicationComplete="onApplicationComplete();"
>
<fx:Declarations>
<!-- Place non-visual elements (e.g., services, value objects) here -->
</fx:Declarations>
<fx:Script>
<![CDATA[
private function onApplicationComplete() : void {
systemManager.loaderInfo.uncaughtErrorEvents.addEventListener("uncaughtError", uncaughtErrorHandler);
}
private function uncaughtErrorHandler(event:Event) : void {
trace(event.toString());
}
]]>
</fx:Script>
<s:Button x="153" y="64" label="Trigger Error" id="triggerButton" click="throw new Error('myError')"/>
</s:Application>
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
最简单的方法...
The easy way...
取自 API (我建议您仔细查看下次):
Take from the API (which I recommend you look through next time):