flash - 在IDE之外显示捕获的错误-过度杀伤/批评?

标签 flash actionscript-3 error-handling flash-cs3

我设计了以下方法来捕获整个AS3应用程序中的错误:

在Document类中,定义以下方法:

//This is the handler for listening for errors
protected function catchError(event:ErrorEvent):void 
{ 
  displayError('Error caught: ' + event.text);
}

//Creates a MovieClip with a TextField as the child.
//Adds the MC to the stage
protected function displayError(msg:String):void
{
  var errorMC:MovieClip = new MovieClip();
  errorMC.graphics.beginFill(0xffffff);
  errorMC.graphics.drawRect(0, 0, stage.stageWidth, stage.stageHeight);
  errorMC.graphics.endFill();

  var errorTxt:TextField = new TextField();
  errorTxt.multiline = true;
  errorTxt.width = stage.width;
  errorTxt.height = stage.height;
  errorTxt.selectable = true;
  addChild(errorMC);
  addChild(errorTxt);

  errorTxt.text = 'Error(s) Caught: \n' + msg;
}

为了处理Document类中使用的类,我添加了以下内容,以便可以注册前面提到的函数:
protected var errorCatcher:Function;
protected var displayError:Function;

public function setErrorDisplayer(f:Function):void
{
  displayError = f;
}

public function setErrorCatcher(f:Function):void
{
  errorCatcher = f;
}

现在,当在浏览器中测试应用程序时,我可以在运行时在SWF中显示错误。

例如:
(我没有测试以下内容,只是一个示例)
//Document class
package com
{
  import flash.display.MovieClip;
  import flash.event.ErrorEvent;
  import flash.text.TextField;
  import com.SomeClass;

  public class Document extends MovieClip
  {
    protected var someClass:SomeClass = new SomeClass();

    public function Document():void 
    {
      someClass.setErrorCatcher(catchError);
      someClass.setErrorDisplayer(displayError);
    }

    protected function catchError(event:ErrorEvent):void 
    { 
      displayError('Error caught: ' + event.text);
    }

    protected function displayError(msg:String):void
    {
      var errorMC:MovieClip = new MovieClip();
      errorMC.graphics.beginFill(0xffffff);
      errorMC.graphics.drawRect(0, 0, stage.stageWidth, stage.stageHeight);
      errorMC.graphics.endFill();

      var errorTxt:TextField = new TextField();
      errorTxt.multiline = true;
      errorTxt.width = stage.width;
      errorTxt.height = stage.height;
      errorTxt.selectable = true;
      addChild(errorMC);
      addChild(errorTxt);

      errorTxt.text = 'Error(s) Caught: \n' + msg;
    }
  }
}

这是矫kill过正,还是我错过了“最佳实践”?

最佳答案

您可以只使用FireBug在浏览器中调试和从SWF输出。只是Google的“firebug as3”,您就会看到大量的人正在这样做。

您也可以使用De MonsterDebugger之类的东西。它有很多很棒的功能。有关概述,请查看Lee Brimlows De MonsterDebugger video from GoToAndLearn

关于flash - 在IDE之外显示捕获的错误-过度杀伤/批评?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3258226/

相关文章:

java servlets 响应 - 保持在同一页面上

javascript - 获取正在播放 flash swf 文件的域

python-3.x - 如何使用子进程管道进行错误处理

python - Mechanize 时不时地随机出错?

android - 如何从 Android 应用程序运行 Flash

actionscript-3 - 在 Flash 中分析视频的像素数据

javascript - 有趣的项目——你能钩住闪光灯吗?

actionscript-3 - AS3 AIR : After stage. addEventListener(MouseEvent.CLICK,...舞台宽度和高度发生变化?

actionscript-3 - 场景结束后停止音乐

javascript - 检查该变量是否为 bool 值的 if 语句结果为 "boolean != boolean"