xray


30
Oct 07

XRay Logging with AS3

Using Xray you can utilize logging in your AS3 development in a nice clean manner. One of the great benefits here is that your logging/debugging process can be the same when developing locally and when you are running on your development and production servers.

To get started download the latest xray code from their SVN repository.
http://code.google.com/p/osflash-xray/source

Then create a new AS3 flash document using the code below as the document class:
Make sure that you add the ‘trunk’ directory that you downloaded to your class path (so flash can find the xray files)

Once you are compiling correctly, launch the xray viewer in a browser from http://www.rockonflash.com/xray/flex/Xray.html. You will get a notification about not finding a SWF to connect with, ignore this for now (full xray support is not yet therefor AS3 projects). Make sure that the Show Output checkbox along the bottom is checked.

Now if you click the red square in your swf player, you should see the following show up in the XRay viewer windows.

Congratulations you are now logging. Big thanks to John Grden and everyone else contributing to Flash development methodologies.

picture-4.png

package {
	import com.blitzagency.xray.logger.XrayLog;
 
	import flash.display.*;
	import flash.events.*;
 
	public class testLoggingAS extends MovieClip {
 
		private var log:XrayLog = new XrayLog();
		private var mc:MovieClip
 
		public function testLoggingAS() {
			log.debug("Application starting up");
			createClickableMovieClip()
			log.debug("Application has completed startup");
		}
 
		private function showTheClick(e:Event):void {
			log.debug("Square was clicked. Tracing out the Event", [e]);
		}
 
		private function createClickableMovieClip():void {
			mc = new MovieClip();
			mc.name = "ClickableMovieClip"
			mc.graphics.beginFill(0xFF0000);
			mc.graphics.drawRect(0, 0, 100, 80);
			mc.graphics.endFill();
			mc.x = 80;
			mc.y = 60;
			addChild(mc);
			mc.addEventListener(MouseEvent.CLICK, showTheClick)
		}
 
	}
}