Hi all,
I’ve been struggling with this for a while and figured it would be better to seek some advice from the kirupa forums as you guys have much more knowledge of as3 than me.
I am trying to build a simple debug class so I can debug remotely on projects I create. I got my class working using the singleton pattern so that it is only instantated once and it will trace fine, but when I try to add a TextField to the stage I get errors. I can’t use addChild unless the class extends a DisplayObjectContainer, but if my class extends anything it throws an error.
The basic code is below for your thoughts? thanks?
package
{
import flash.display.DisplayObjectContainer
import flash.text.TextField;
public class Debug extends DisplayObjectContainer
{
private static var VERSION:String = "0.1";
private static var _instance:Debug; // enforce singleton pattern Debug instance
private var _textField:TextField;
// static function to trace to debugger console
public static function write(args)
{
if(_instance == null)
{
_instance = new Debug(arguments.callee);
}
// output arguments
trace(arguments);
// :TODO: send the arguments to the console
}
public function Debug(caller:Function = null)
{
if(caller != Debug.write)
{
throw new Error("Debug is a singleton pattern class, use write() instead");
}
if(Debug._instance != null)
{
throw new Error("Only one Debug instance should be instantiated");
}
// initialize the console
createConsole();
}
private function createConsole():void
{
// create Debug console here
trace("*** New Debugger - " + VERSION + " ***")
// :TODO: create the textfield and console
this._textField = new TextField();
this._textField.width = 200;
this._textField.height = 200;
//addChild(this._textField);
}
}
}