Saturday, February 08, 2003

Debugging Flash Remoting Interfaces without Opening Flash

Did you know that you can run the Flash Remoting NetConnection Debugger without opening Flash? You can. And you may want to reconsider your use of the Flash Trace() statement, using NetServices.Trace instead. This tip will explain both points.

A little background first: If you're exploring Flash and Flash remoting, you'll soon get familiar with the NetConnection Debugger (more at macromedia).

While many see it as a tool for debugging a move while testing it within the Flash environment, the truth is that you can use it to test ANY movie running on your workstation--as long as that movie has included the NetDebug.as file in its script, that is. You can run the SWF or the file that loads the SWF and if debugging is enabled within it, you'll see that you get the netconnection debugging info for that movie.

One challenge with using it, though, is that it's kind of annoying to have to open Flash just to enable it in order to test movies running outside of Flash this way. You may not have noticed but the NetConnection Debugger is itself a Flash movie. It's located in the Flash program directory such as \Program Files\Macromedia\Flash MX\First Run\WindowSWF, at NetConnection Debugger.swf.

You may want to create a shortcut for it on your desktop, or set it as a favorite in your browser, so that you can easily open it whenever you want to debug a debuggable movie.

Sadly, while it's possible to see this form of debugging info without Flash open, you will not see the output window that's typically opened inside Flash when you have Trace() statements in your ActionScript code. And the result of such traces are NOT written to the NetConnection Debugger.

But all is not lost: if you simply change to using NetServices.trace() instead, you'll see that you get two benefits: first, such traces will still be written to the output window in Flash, if you have it open. More important, the difference with these traces is that they WILL be written to the NetConnectionDebugger. It will be listed as an event called "NetServicesTrace". Curiously, the information about the trace shown in the "summary" window of the debugger window will show whatever value being traced using a header of "who". See below, showing the result of NetServices.trace("test of trace");.



Chris Kief has offered this useful additional information:

As a CFer, I’ve become pretty reliant on to let me see what is going on. But in Flash you can’t just dump things that easily. Try tracing an object using trace() and you receive [Object] [Object]. That is where the NetConnect Debugger comes in. It is able to handle complex objects. So a simple NetDebug.trace(myObj) will allow you to see the details of the object. Here’s a simple demonstration:

#include "NetDebug.as"

myObj = [];
myObj.push({foo:"bar0", bar:"foo0"});
myObj.push({foo:"bar1", bar:"foo1"});
myObj.push({foo:"bar2", bar:"foo2"});
myObj.push({foo:"bar3", bar:"foo3"});

// a string trace
NetDebug.trace("hello");
// an associative array trace
NetDebug.trace(myObj);

I just noticed your blog about NetServices.trace and the fact that it traces with a header of “who” every time. I would recommend using NetDebug.trace() instead as it does not exhibit this behavior.

No comments: