Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Does ActionScript have an equivalent of a "core dump"?

Here's my situation: I'm working on an AS3-based game and I'd like to have a "Report a problem!" function within the game so that users can submit feedback to me.

When my user reports a problem, I'd like to get as much information as I can about the state of their game; basically what objects are in memory, what the values are of all those variables inside all those objects; essentially the same information I can get when I hit a breakpoint in the debugger.

Is there a simple way of doing this? I'm afraid that I'll spend several days trying to write a bunch of functions that gets all this information for me, only to have somebody tell me afterwards, "Oh, why didn't you just call ASUtils.getSnapshot()"?

like image 597
Toddarooski Avatar asked Aug 20 '11 22:08

Toddarooski


2 Answers

There is no generic way in AS3 to dump the state of your variables, but there are several things we do that you might find useful:

  1. Capture a log of recent click activity. Use stage event listener to log clicks and trace the object "path" up the parent chain to the stage. The object path is just all the DisplayObject names, like: screenMain.dialogBuyItem.buttonBuy
  2. Capture a screenshot, reduce it to a small thumbnail, JPEG encode it, and upload it to your server along with their feedback. We also do this when there is an exception (see #4). as3corelib has JPEG encoding functions in com/adobe/images
  3. Write a command-line pearl or PHP script you can run on your AS3 code before you publish it that will inject call tracing at the top of each function call. This allows call history to be logged. While it's not as good as a full stack, it will give you some indication of what your code has been doing recently.
  4. Trap asserts and unhandled exceptions and log them to your server with click activity and call history trace. Unhandled exception listeners are new in flash 10.1, but most users have this feature. You can check for that support and add a listener like this:

    // Check for the presence of the Flash 10.1 global Error event (exception) handler class.
    // If it exists, we'll listen for it and it will allow us to report errors to our server.
    if ( loaderInfo.hasOwnProperty( 'uncaughtErrorEvents' ) )
        loaderInfo.uncaughtErrorEvents.addEventListener( "uncaughtError", onUncaughtError ); // UncaughtErrorEvent.UNCAUGHT_ERROR
    
  5. If you have global state variables that you want to log with feedback, you can write a function to dump them to a string for uploading with the user feedback. While you can enumerate class and object properties using for each, this only works for public members. Google around and you'll find some functions people have written to dump objects and array data recursively using this enumeration trick.

like image 121
Stu Avatar answered Oct 17 '22 06:10

Stu


i'd like to add it as a comment, but don't want to lose code formatting
this is what i'm using to trace complex objects:

    private function parseObject(o:Object, prefix:String = '>'):String {
        var retStr:String = '';
        for (var s:String in o) {
            retStr += prefix + s + ' = ' + o[s] + '\n';
            if (typeof(o[s]) == 'object') {
                retStr += parseObject(o[s], prefix + '>');
            }
        }
        return retStr; 
    }

hope it'd be helpful

like image 36
www0z0k Avatar answered Oct 17 '22 05:10

www0z0k