When I run a Flex application in the debug flash player I get an exception pop up as soon as something unexpected happened. However when a customer uses the application he d
I'm using flex 4.
I tried loaderInfo.UncaughtErrorEvents,
but loaderInfo was not initialized so it gave me null reference error. Then i tried root.loaderInfo.UncaughtErrorEvents
and the same story.
I tried sprite.root.UncaughtErrorEvents
, but there was no sprite object, I created one, but it didn't work. Finally I tried
systemManager.loaderInfo.uncaughtErrorEvents.addEventListener(UncaughtErrorEvent.UNCAUGHT_ERROR,globalUnCaughtErrorHandler.hanleUnCaughtError);
And guess what, it works like magic. check this
It works in Flex 3.5 and flash player 10:
<?xml version="1.0" encoding="utf-8"?>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" addedToStage="application1_addedToStageHandler(event)">
<mx:Script>
<![CDATA[
import mx.events.FlexEvent;
protected function application1_addedToStageHandler(event:Event):void{
if(loaderInfo.hasOwnProperty("uncaughtErrorEvents")){
IEventDispatcher(loaderInfo["uncaughtErrorEvents"]).addEventListener("uncaughtError", uncaughtErrorHandler);
}
sdk.text = "Flex " + mx_internal::VERSION;
}
private function uncaughtErrorHandler(e:*):void{
e.preventDefault();
var s:String;
if (e.error is Error)
{
var error:Error = e.error as Error;
s = "Uncaught Error: " + error.errorID + ", " + error.name + ", " + error.message;
}
else
{
var errorEvent:ErrorEvent = e.error as ErrorEvent;
s = "Uncaught ErrorEvent: " + errorEvent.text;
}
msg.text = s;
}
private function unCaught():void
{
var foo:String = null;
trace(foo.length);
}
]]>
</mx:Script>
<mx:VBox>
<mx:Label id="sdk" fontSize="18"/>
<mx:Button y="50" label="UnCaught Error" click="unCaught();" />
<mx:TextArea id="msg" width="180" height="70"/>
</mx:VBox>
</mx:Application>
Thanks
Now you can, using loader info:
http://www.adobe.com/devnet/flex/articles/global-exception-handling.html
Checkout:
loaderInfo.uncaughtErrorEvents.addEventListener(UncaughtErrorEvent.UNCAUGHT_ERROR, onUncaughtError);
private function onUncaughtError(e:UncaughtErrorEvent):void
{
// Do something with your error.
}