显示非调试AS3应用程序的跟踪

时间:2011-07-04 16:52:07

标签: flash actionscript-3 logging trace

客户端遇到应用程序的一些问题,无法安装调试Flash播放器,这意味着调试非常困难。

有没有人知道在舞台上的文本字段中显示系统跟踪消息的方法?通过这种方式,我可以通过跟踪到屏幕来找到错误。

我想一个解决方法是尝试/捕获整个应用程序,但这并不理想且非常麻烦。

谢谢

2 个答案:

答案 0 :(得分:0)

我最近开始做的是使用ExternalInterface调用来调试Flash,使用Firebug控制台或浏览器支持的任何控制台。

我们使用来自Html5Boilerplate的这段Javascript:

window.log = function(){
  log.history = log.history || [];
  log.history.push(arguments);
  arguments.callee = arguments.callee.caller;  
  if(this.console) console.log( Array.prototype.slice.call(arguments) );
};
(function(b){function c(){}for(var d="assert,count,debug,dir,dirxml,error,exception,group,groupCollapsed,groupEnd,info,log,markTimeline,profile,profileEnd,time,timeEnd,trace,warn".split(","),a;a=d.pop();)b[a]=b[a]||c})(window.console=window.console||{});

然后使用

ExternalInterface.call('window.log','Debug text goes here');

答案 1 :(得分:0)

我曾经在这种情况下做的是将隐藏的日志面板插入应用程序。按下某个密钥序列后,此面板应打开。当您需要某些信息时,您可以将序列发现给客户并要求复制并向您发送他在日志文本字段中看到的所有内容。在那之前,没有人知道它在那里。这适用于您可能开发的任何应用程序,不仅适用于Web应用程序。好吧,如果你正在开发一个网络应用程序,你甚至可以通过一些cgi脚本和屏幕截图向你发送报告来实现自动化。您只需要让您的客户按特定内容,然后检查您的邮件。

您也可能想要使用UncaughtErrorEvents:http://help.adobe.com/en_US/FlashPlatform/reference/actionscript/3/flash/events/UncaughtErrorEvents.html?filter_flash=cs5&filter_flashplayer=10.1&filter_air=2

下面是一些用于锁定调试输出的简单代码。

protected const inputHistory : Array = [];
private var lockPhrase : String;
private var isUnlocked : Boolean;

private function onKeyUp(event : KeyboardEvent) : void
{
    isUnlocked = checkLock();
    if (event.keyCode == Keyboard.SPACE) {
        if (event.shiftKey) {
            if (isUnlocked) {
                // log panel opens by Shift + Space shortcut
                // only if it was previously unlocked
                toggle(true);
            }
        }
    }
    if (lockPhrase && lockPhrase.length) {
        inputHistory.push(event.charCode);
        while (inputHistory.length > lockPhrase.length) {
            inputHistory.shift();
        }
    }
}

private function checkLock() : Boolean
{
    if (isUnlocked || lockPhrase == null || lockPhrase.length == 0) {
        return true;
    }
    if (inputHistory.length != lockPhrase.length) {
        return false;
    }
    var match:uint = 0;
    for (var i : uint = 0; i < lockPhrase.length; i+=1) {
        if (lockPhrase.charCodeAt(i) == inputHistory[i]) {
            match += 1;
        }
    }
    return (match == lockPhrase.length);
}