topical media & game development
professional-flex-code-26-LocalConnectionTraceTarget.ax
professional-flex-code-26-LocalConnectionTraceTarget.ax
[swf]
flex
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;
The <code>@ax-professional-flex-code-26-LocalConnectionTraceTarget</code> extends the
<code>LineFormattedTarget</code> class to provide
a basic output mechanism. This target uses
<code>LocalConnection</code> to output the trace
messages to any other application using
<code>LocalConnection</code> listening on
<code>_flex2tracepanel</code>.
see: mx.logging.targets.LineFormattedTarget
public class @ax-professional-flex-code-26-LocalConnectionTraceTarget extends LineFormattedTarget {
Constructor.
public function @ax-professional-flex-code-26-LocalConnectionTraceTarget() {
super();
lc = new LocalConnection();
lc.addEventListener(StatusEvent.STATUS, statusEventHandler);
}
@private
private var lc:LocalConnection;
@private
@internal Need to keep Flex 2 from throwing unhandled
status errors
private function statusEventHandler(event:StatusEvent):void {
; // Handles Event Status Calls
}
The <code>internalLog</code> method handles the
sending of messages.
parameter: event LogEvent
sent to a
<code>ILogger</code> from the <code>Log</code> class.
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);
}
The pad method adds leading 0's to single digit numbers.
returns: The string representation of two digit leading 0 number.
private function pad(num:Number):String
{
return num > 9 ? num.toString() : "0" + num.toString();
}
}
}
(C) Æliens
04/09/2009
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.