/* Copyright(c) 2008-09 Craig Simpson, Some rights reserved. Your reuse is governed by the Creative Commons Attribution 3.0 United States License */ package net.craigsimpson.utility{ import flash.net.LocalConnection; import flash.events.SecurityErrorEvent; import flash.events.StatusEvent; /* Debugger Singleton Class: Developed to be used in AS3 Flash & Flex applications. The class sends debug meessages to the custom built debugger panel. Kind of like looking trace commands in a browser. Great for both development and when application is live on the web. //Example actionscript to send messages to plane; var debugger:Debugger = Debugger.instance; debugger.connect("MyCoolApp"); debugger.send("Test 1...2....3"); Debugger Panel Application: The custom debugging panel source can be downloaded at www.craigsimpson.net/download/debugger.zip Also a live version is hosted on my site at www.craigsimpson.net/debugger.html Contact: Report any bugs, comments, or suggestions at www.craigsimpson.net/contact */ dynamic public class Debugger { private const CONNECTION_NAME:String = "_debugger"; private var debuggerLC:LocalConnection; private var _appName:String; private var _domain:String; private static var __instance:Debugger; public function Debugger(enforcer:SingletonEnforcer) { //Constructor } public static function get instance ():Debugger { if(Debugger.__instance == null) { Debugger.__instance = new Debugger(new SingletonEnforcer()); } return Debugger.__instance; } /* Send messages to output in the debugger window */ public function send(message:Object, level:Number = 0, hightlight:Boolean = false):void { debuggerLC.send( CONNECTION_NAME, "outputText", message, level, hightlight ); trace(message); } /* Connects application to debugger panel, must be called once in your application. Since multiple apps are allowed to connected to the debugger panel applicationName helps indenifty which apps are currently connected. */ public function connect(applicationName:String = null, domain:String = null):void { _appName = applicationName ? applicationName : "Unknown Application"; _domain = domain ? domain : "*"; debuggerLC = new LocalConnection(); debuggerLC.allowDomain(_domain); debuggerLC.addEventListener(SecurityErrorEvent.SECURITY_ERROR, onConnectionError); send( _appName + " Connected ", 1, false ); } /* Sends a message that is highlighted in red, for sending error messages that need to catch the endusers atttention. */ public function sendError(errorMessage:Object):void { send( errorMessage, 2, true ); } /* Sends highlighted message to panel. */ public function sendHighlighted(message:Object):void { send(message, 2, true); } /* * Event Listeners */ private function onConnectionError(event:SecurityErrorEvent):void { debuggerLC.removeEventListener(SecurityErrorEvent.SECURITY_ERROR, onConnectionError); debuggerLC = null; trace("LOCAL CONNECTION SECURITY ERROR!"); throw new Error("onConnectionError: "+event.toString); } } } internal class SingletonEnforcer {}