IDEの外で捕獲されたエラーを表示する - オーバーキル/批評?
-
16-09-2020 - |
質問
AS3アプリケーション全体でエラーを引くための次の方法を考案しました:
文書クラスでは、次の方法を定義します。
//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;
}
.
ドキュメントクラス内で使用されているクラスに対処するために、前述の関数を登録できるように次のものを追加します。
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;
}
}
}
.
これは過虐殺ですか、それとも私はここに「ベストプラクティス」がありませんか?
解決
ブラウザ内のSWFからデバッグして出力するには、Firebugを使用するだけです。「Firebug AS3」のためだけにGoogleで、あなたはこれをやっている人々がいるのを見るでしょう。
de monsterdebugger のようなものを使うこともできます。それは多くの素晴らしい機能を持っています。概要の場合は、 Lee Brimlows de Monsterdebuggerビデオをgotoandlearn 。
所属していません StackOverflow