topical media & game development
[] readme course(s) preface I 1 2 II 3 4 III 5 6 7 IV 8 9 10 V 11 12 afterthought(s) appendix reference(s) example(s) resource(s) _

talk show tell print

professional-flex-code-25-LocalConnectionTraceTarget.ax

professional-flex-code-25-LocalConnectionTraceTarget.ax (swf ) [ flash ]


  package
  {
  
  import flash.events.StatusEvent;
  import flash.net.LocalConnection;
  
  import mx.controls.TextArea;
  import mx.core.mx_internal;
  import mx.logging.ILogger;
  import mx.logging.LogEvent;
  import mx.logging.targets.LineFormattedTarget;
  
  use namespace mx_internal;
  
  public class professional-flex-code-25-LocalConnectionTraceTarget extends LineFormattedTarget {
  
    public function professional-flex-code-25-LocalConnectionTraceTarget() {
      super();
      
      lc = new LocalConnection();
      lc.addEventListener(StatusEvent.STATUS, statusEventHandler);  
    }
      
    private var lc:LocalConnection;
   
    private function statusEventHandler(event:StatusEvent):void {
      ; // Handles Event Status Calls
    }
   
    override public function logEvent(event:LogEvent):void
    {
      var level:int = event.level;   
  
      var date:String = ""
      if (includeDate || includeTime)
      {
        var d:Date = new Date();
        if (includeDate)
        {
          date = Number(d.getUTCMonth() + 1).toString() + "/" +
          d.getUTCDate().toString() + "/" + 
          d.getUTCFullYear() + fieldSeparator;
        } 
        if (includeTime)
        {
          date = pad(d.getUTCHours()) + ":" +
          pad(d.getUTCMinutes()) + ":" +
          pad(d.getUTCSeconds()) + "." +
          pad(d.getUTCMilliseconds()) + fieldSeparator;
        }
      }
  
      var category:String = includeCategory ?
          ILogger(event.target).category + fieldSeparator : "";
          
      // Connection and Method specific to C# .Net applicaton Flex2TracePanel
      lc.send( "_flex2tracepanel", "logMessage", date + category + event.message, level);
    }
  
    private function pad(num:Number):String
    {
      return num > 9 ? num.toString() : "0" + num.toString();
    }    
      
  }
  }


(C) A. Eliëns 2/9/2007

You may not copy or print any of this material without explicit permission of the author or the publisher.
In case of other copyright issues, contact the author.