
Well, for a while now, people have been asking me about using Xray with ActionScript3, so I thought I’d clear up the confusion with one post about it.
Yes – there is a version for AS3. That’s the good news. The bad news is, it doesn’t have all the bells and whistles that AS2 version had. It DOES do introspection of your objects at runtime with a snapshot, and the logger is as strong as ever. There’s also a Flex specific Xray class that works rather well.
The nice thing is, the logger and Xray work the same in either the Flash IDE, pure ActionScript project, Flex application or Air application. It doesn’t have an AS3 component yet, but it works very easily with a couple lines of code just the same way.
Let’s take a look at doing 2 things: 1) setting up an Xray instance for introspection and 2) just using the logger.
Xray Instance
To create an instance of Xray, you simply add the import to your class, then create an instance:
import com.blitzagency.xray.inspector.Xray;
// later in your property declarations:
public var xray:Xray = new Xray();
addChild(Xray); // you have to add it to the stage in a pure ActionScript application or Flash IDE app – thanks Dave!
// for you Flex users – it works for Flex2 or Flex3 or Air
import com.blitzagency.xray.inspector.flex.Flex2Xray;
public var xray:Flex2Xray = new Flex2Xray();
Yay me! we’re done and you can use the Flex Xray interface to take a look at your application.
Xray’s Logger
Xray’s logger has the same log levels that most do these days: debug, info, warn, error and fatal. To create an instance of the Xray logger, you simply add the import, then create an instance like so:
import com.blitzagency.xray.logger.XrayLog;
// later in your property declarations:
public var log:XrayLog = new XrayLog();
// later, when you want to log something:
log.debug(“StringMessage”, object [, object, object...]);
log.info(“StringMessage”, object [, object, object...]);
log.warn(“StringMessage”, object [, object, object...]);
log.error(“StringMessage”, object [, object, object...]);
log.fatal(“StringMessage”, object [, object, object...]);
You pass a string message as the first argument, then send as many objects as you like after that. The output is nice in that it includes a time stamp as well as the class and line number that made the log call:
(2793) com.electricsheepcompany.aspen.spaces::SpaceCreator/handleGroupLoaded()[/Users/NeoRiley/Documents/Infrared5/clients/clientName/source/johnBranch/src/1.0_jgrden/src/main/flex/com/clientName/clientAppName/spaces/SpaceCreator.as:102
GroupTest: group load complete
As you can see, you get the calling Class fine and line number. Nice huh?
Where do I get the code?!?
Glad you asked! It’s hosted on Google code and you can check it out with any SVN client at this URL:
http://osflash-xray.googlecode.com/svn/trunk/
And the snazy Xray Interface app??
You can download the SWF based Xray app here

The future of Xray?
As usual, I’m sure Xray’s development will be driven by need on projects and by people who request features. If anyone cries loud enough, I’m sure I’ll do what I can. As I come to need more features that AS2 used to support, I’ll get around to implementing them. But for now, it works well in AS3, and does what I need it to do, which is introspection and the ability to modify properties at runtime to see what’s going on with the application. Much of my work these days is being a consultant on new gigs every couple of months and Xray really helps me cut through the felgercarb in mere sentons.
Also, there’s XrayViewer by Marc Hughes
Marc’s the one that did the work on the filter component for Xray’s log output, and came up with a really VERY cool AIR app that lets you load a SWF and inspect it
http://rogue-development.com/xrayviewer.html