How to Trace Messages From SPAS Applications

Difficulty: Beginner
How to Trace Messages From SPAS Applications

Problem

You need to trace out a message or the value of some data at runtime.

Solution

Define a Debugger object and pass data to the print() function to look for messages in the IDE console.

Discussion

The print statement allows developers to trace out messages or data from SPAS 3.0 applications. SPAS uses the UIManager.debugger object to trace out messages.

Default UIManager.debugger object is an instance of the org.flashapi.swing.framework.DebugObject class. The DebugObject is designed to trace out messages in the Flash IDE Output view.

If you use FlashDevelop, instead of the Flash IDE, to create SPAS applications, you must set a new FDTrace instance as default Debugger object:

package {

	import org.flashapi.swing.Application;
	import org.flashapi.swing.UIManager;
	import org.flashapi.swing.framework.FDTrace;

	public class ExampleApplication extends Application {
		
		UIManager.debugger = new FDTrace();
		
		public function ExampleApplication():void {
			super(init);
		}
		
		private function init():void {
			print("Hello world!");
		}
	}
}

You can also print traces within an embeded SPAS application, by using a DebugPanel object, as shown below:

package {

	import org.flashapi.swing.Application;
	import org.flashapi.swing.UIManager;
	import org.flashapi.swing.framework.DebugPanel;

	public class ExampleApplication extends Application {
		
		UIManager.debugger = new DebugPanel();
		
		public function ExampleApplication():void {
			super(init);
		}
		
		private function init():void {
			print("Hello world!");
		}
	}
}

The DebugPanel class automatically displays a basic text area, for tracing out messages and data values, on the top of an embeded SPAS application. It is useful for debugging online applications for example.

Of course, developers can use their own debugger objects by simply creating classes that implement the org.flashapi.swing.framework.Debugger interface. The following class shows how to design a custom Debugger object:

package  {
	
	import org.flashapi.swing.framework.Debugger
	
	public class CustomDebugObject implements Debugger {
		
		public function CustomDebugObject():void {
			super();
		}
		
		/**
		 * 	@inheritDoc
		 */
		public function print(... arguments):void {
			trace("Print statement called:");
			trace(arguments);
			trace("---------------------------------");
		}
	}
}

Share this article:

Comments:

There are no comments yet for this article.

Leave a reply

Your email is required but will not be displayed.

To prevent abusive emails, please enter the numbers you see in the image below:

Security code