Tag Archives: debugging

utility.Debugger

Screen Shot of Debugger

Description:

A Flex application that I developed to print trace messages to a custom debugger panel.  I use it in all my projects since trace does not work on applications running out side the Flash’s IDE.  Some of the features include 3 message levels so that you can choose not to get flooded with debugging messages.  Secondly you can also highlight messages. This works great for error messages and looking for those hard to find variables.    Even if your compiling in Flash’s IDE, Debugger still sends out your message as trace. This is a life saver in time and debugging when your clients call say the live app is not working. This app is a must for any Flex or Flash project.

[ View  debugger panel ]

Download:

[ Debugger.zip 281 K ] The source files for both the output panel and the static class that you place into your project to send messages to the panel. Instructions on using debugger panel is in the class file.

?Download Debugger.as
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
/*
 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 {}

Future:

Documentation write up for implementation of Debugger class and using the panel. Any suggestions for future releases are greatly appreciated.