开发者

How to get error message and stack trace when you use normal version(not debug version) of flash player in actionscript?

I want to log errors of my flash application after I released it.

I will save the logs on files on the web server.

Do you know ho开发者_StackOverflow社区w to get error message and stack trace when you use normal version(not debug version) of flash player?


As far as I can find there's no way to get a stack trace from the release version of the Flash player before version 11.5. However, the 9/26/2012 Flash player beta 11.5 added a rudimentary stack trace to the release player. When using it, Error.getStackTrace tells you the class and function where the error was thrown, but does not include the classpath or line.

Announcement: http://forums.adobe.com/message/4732775

Example usage: http://renaun.com/blog/2012/09/getting-the-stack-trace-in-a-release-flash-player/

If you want to get stacktraces from a release SWF (one not built with debug=true) using debug Flash players prior to beta 11.5, you can build your app using the flag "-compiler.verbose-stacktraces".


Client Side Logging

If you want to access debugging tools in-browser (rather than in the Flash Debugger), there are a number of options.

The simplest option is to download a browser extension, and continue to use trace.

I do a bunch of cross-browser checking, so I've used a custom log function in my Utils package to access the JS console:

log.as

package com.zzzzbov.utils
{
  import flash.external.ExternalInterface;

  public function log(... args):void
  {
    CONFIG::DEBUG
    {
      trace(args);
      if (loggingEnabled && ExternalInterface.available)
      {
        try
        {
          if (init === null)
          {
            init = ExternalInterface.call('eval', 'if(window.flashlog){false;}else{window.flashlog=function(){if(window.console&&console.log){if(console.log.apply){console.log.apply(console,arguments);}else{for(var i=0;i<arguments.length;i++){console.log(arguments[i]);}}}};true;}');
          }

          if (init)
          {
            var values:Array = new Array('flashlog');
            ExternalInterface.call.apply(ExternalInterface, values.concat(args));
          }
        }
        catch (e:Error)
        {
          //nothing really can be done
        }
      }
    }
  }
}

init.as

package com.zzzzbov.utils
{
  internal var init:* = null;
}

loggingEnabled.as

package zfl.utils
{
  internal var loggingEnabled:Boolean = true;
}

There are a lot of things that can be improved, and a few things that are required to use this function. You'll need CONFIG::DEBUG defined, additionally you'll want to add an event listener to the stage for Event.ACTIVATE and Event.DEACTIVATE to toggle loggingEnabled on and off to prevent flash from crashing. You'll also need to provide script access to the flash video.

Server Side Logging

If you'd like to log messages on a server using Flash, send a simple Url Request using a URLLoader passing the message as a parameter to a server-side script. The logging script being called will need to be written in a server-side language such as PHP or ASP.NET.

Care should be taken to authenticate the request from Flash to prevent malicious access (you wouldn't want someone injecting some executable code into your filesystem).

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜