• Flex全局错误处理Global Error Handler代码兼容运行于低版本Flash Player


    Global Error Handler是从Flash Player 10.1.x开始才加入的功能,如果将其代码运行于Flash Player 10.0.x或更低版本的FP时,swf将会出错。
    那么用什么方法才能使Global Error Handler的代在Flash Player 10.1.x时能正常使用,而在低版本FP中又不使swf出错呢?

    请看如下代码:

    private function setGlobalErrorHandler(event:FlexEvent):void{
      if( !loaderInfo.hasOwnProperty("uncaughtErrorEvents") ) return;
      Object(loaderInfo).uncaughtErrorEvents.addEventListener("uncaughtError", onUncaughtError);
      function onUncaughtError(event:Event):void{
        var message:String = Object(event).error.getStackTrace();
        if(!message){
          if(Object(event).error is Error){
            message = Error(Object(event).error).message;
          }
          else if(Object(event).error is ErrorEvent){
            message = ErrorEvent(Object(event).error).text;
          }
         else{
            message = Object(event).error.toString();
          }
        }
      }
    }

    P.S.
    不能把.addEventListener("uncaughtError", onUncaughtError);改成.addEventListener(UncaughtErrorEvent.UNCAUGHT_ERROR, onUncaughtError);
    因为低版本FP中没有UncaughtErrorEvent,会使swf出错。

  • 相关阅读:
    因式分解
    插入排序算法
    小技巧(杂乱篇章)
    错误的模糊应用(类继承问题)
    同源策略和跨域解决方案
    Django admin源码剖析
    Python中该使用%还是format来格式化字符串?
    Django的认证系统
    Django中间件
    Django form表单
  • 原文地址:https://www.cnblogs.com/bmate/p/1868213.html
Copyright © 2020-2023  润新知