3 Replies Latest reply: Aug 9, 2012 5:24 PM by Flex harUI RSS

    Help with code

    Zolotoj Community Member

      I am addaptnig some code I got from the Internet. It does what I want, but I need some help to fullly understand how it works. Here it is.

      // My main application file:

      .....

      <logging:GlobalExceptionHandler preventDefault="true" >

                                    <logging:LogHandlerAction/>

      </logging:GlobalExceptionHandler>

       

       

      package

      {

          import flash.display.LoaderInfo;

          import flash.events.UncaughtErrorEvent;

         

          import mx.managers.ISystemManager;

       

       

          [Mixin]

          [DefaultProperty("handlerActions")]

          public class GlobalExceptionHandler

          {

              private static var loaderInfo:LoaderInfo;

       

       

              public var handlerActions:Array;

       

       

              public var preventDefault:Boolean = false;

       

       

              public static function init(sm:ISystemManager):void

              {

                  loaderInfo = sm.loaderInfo;

              }

       

       

              public function GlobalExceptionHandler()

              {

                  loaderInfo.uncaughtErrorEvents.addEventListener(UncaughtErrorEvent.UNCAUGHT_ERROR,

                                                                  uncaughtErrorHandler);

              }

       

       

              private function uncaughtErrorHandler(event:UncaughtErrorEvent):void

              {

                                    for each (var action:GlobalExceptionHandlerAction in handlerActions)

                  {

                      action.handle(event.error);

                  }

       

       

                  if (preventDefault == true)

                  {

                      event.preventDefault();

                  }

              }

          }

      }

       

      package

      {

       

          public interface GlobalExceptionHandlerAction

          {

              function handle(error:Object):void;

          }

      }

       

      package stoneriver.util.logging

      {

                import stoneriver.util.logging.ErrorLogger;

          public class LogHandlerAction implements GlobalExceptionHandlerAction

          {

                          private var _log:ErrorLogger =  ErrorLogger.getInstance();

              public function handle(error:Object):void

              {

                  if (error is Error)

                  {

                                              var errorObj:Error = error as Error;

                                              // This will start logging errors

                                              _log.error(errorObj);

                  }

              }

          }

      }

       

       

      Basically my question is:

      How does handlerActions array get its elements?

       

      Thanks