Dave Carabetta Blog Banner


March 8, 2007

A Trick For Dumping the Event Object in Flex 2


I know there are third-party tools out there that some people use to debug their Flex applications, and I'm personally a huge fan of the Flash Tracer plugin for viewing trace() statements and dumping out objects without having to use the Debug mode option in Flex Builder 2. However, one issue that I run into a lot is the need to dump out an event object in a given function. My personal choice for doing this is a combination of the trace() function and the uber-handy ObjectUtil class, like so:

import mx.utils.ObjectUtil;

private function onChangeItem( event : ListEvent ) : void
{
trace( ObjectUtil.toString(event.target) );
}

However, the problem with the above code is that it throws a not-so-clear run-time exception:

Error: Error #2099: The loading object is not sufficiently loaded to provide this information.

Yeah, that's really helpful! This error prevents you from being able to see the event object except for actually setting a breakpoint in the Flex Builder UI and re-running the application in debug mode. However, there's a workaround that you can use to get the object to dump out correctly:

import mx.utils.ObjectUtil;

private function onChangeItem( event : ListEvent ) : void
{
trace( ObjectUtil.toString(event.target, null, ['loaderInfo']) );
}

The key to the above modification is the last argument, which is an array of options to exclude when dumping the object. In this case, since the loading object info isn't available, just get rid of it!

I certainly recognize that there are several ways to inspect an object at runtime, and using ObjectUtil.toString() is just one of them. However, in the case that you use the above approach, remember to exclude the loaderInfo data from the dump, and you'll be all set.



Comments
Clint's Gravatar I use this all the time as well.. so much infact, that we IE mainly here at work that I built a .Net app that will read the flashlog.txt that FlashTracer reads.
# Posted By Clint on 3/8/07 at 4:33 PM
Cliff Meyers's Gravatar I just ran into this error the other day; talk about an unhelpful error message! Excellent tip and workaround. Thanks Dave.
# Posted By Cliff Meyers on 3/8/07 at 7:50 PM
Ill's Gravatar You wouldn't know where there is a list of possible options to exclude would you?
# Posted By Ill on 11/5/07 at 9:40 PM

© Dave Carabetta, 2005-2009. This blog licensed under the Creative Commons License. Some rights reserved. This is a personal weblog. The opinions expressed here represent my own and not those of my employer. Blog software provided by Raymond Camden.