Using XTrace and the dubug Class with a Logger Class

This post details a further experiment in improving Flash tracing using XTrace.

See my previous post: XTrace, MTASC and TextMate

This project uses:

1. Mac OSX.

2. Flash 8

3. AS2

My aims for this project are:

1. Use XTrace from the Flash IDE.

2. Improve upon the Trace Output, specially the annoying [object Object]

3. Not rely on using other tools like FlashTracer to see trace Trace Output whilst viewing Flash content in a Browser.

Preamble:

The normal Flash Trace will be output something like:

videoChoiceRelease: [object Object],

whilst what we would prefer would be something like:

videoChoiceRelease: {“id”:”building_futures.flv”,”position”:0,”target”:null,”type”:”videoChoice”}

Whilst working for a project for the now defunct BBC Jam our team used a bespoke Logger Class which had a handy way of outputting an object in more detail than Flash’s IDE somewhat like the second output above.

This Class used a method stringify(arg) from the JSON Class to serialize an Object.

I didn’t notice until after I started the project when I viewed a XTrace tutorial that there was a pre-existing method in the debug Class, dumpObject(). Which would output using the same example as above:

{
url:undefined
id:building_futures.flv
position:0
target:_level0.asset_vnv_mc.bgd.videoCarousel
type:videoChoice
}

The trace: target:_level0.asset_vnv_mc.bgd.videoCarousel is an improvement on: “target”:null, but I’ll have to come back to that later.

Project:

The project incorporates the use of 3 new Classes: JSON, debug and Logger.

1. Download the JSON Class. I placed the Class in its own Package: com.designvox.serialisation.json and changed the Class line to: class com.designvox.serialisation.json.JSON.

2. Download the debug Class and XTrace, if you have not already done so.

3. Create new Class Logger into Package: com.factornine.shared.utilities .

class com.factornine.shared.utilities.Logger {
	
	/*
	 * Constructor should not be called
	 */
	private function Logger(){ throw new Error("Logger should not be instantiated"); }
	
	
	/*
	 * @method log
	 * Static Method for Callee to trace via the XTrace window
	 *
	 * @param message (String) Message to be traced
	 * @param payload (Object) Optional Object - serialized by JSON Class
	 *
	 */
	public static function log(message:String, payload:Object)	: Void{
		
		if (typeof(payload) == "movieclip")
				{
					message += ": " + payload;
				}
				else
				{
					message = (payload != undefined) ? message + ": " + JSON.stringify(payload) : message;
				}
		
		debug.trace(message);
		
	}
}

4. Add a method call in Class where you want to replace the standard Flash trace() .
See my example:

	private function videoChoiceRelease(event : IDEvent) : Void {
		
		// trace("videoChoiceRelease "+event); // previous call
		
		Logger.log("Application.videoChoiceRelease", event);
}

5. Launch the XTrace application.

6. Test Movie.

Which should resulted in something like the following:

Picture 3.png

Conclusion:

I’m pretty happy that I’ve got a more helpful Trace output, which also works in Firefox and Safari.

More To do:

1. Look further into using the set up with MTASC.

2. See what happens in AS3.

3. See PC alternatives.

4. Have the option to use the rather dumpObject(obj) than the stringify(arg) method.

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s