From 2f2ffdabbeb9d5fa9eb28121d3da0378f3d2a856 Mon Sep 17 00:00:00 2001 From: Ray Greenwell Date: Thu, 9 Mar 2006 22:14:08 +0000 Subject: [PATCH] Notes, figured out how to make a static initializer. git-svn-id: svn+ssh://src.earth.threerings.net/narya/trunk@3932 542714f4-19e9-0310-aa3c-eee0fc999fb1 --- src/as/com/threerings/README.txt | 14 +++++++++++++ src/as/com/threerings/util/LogDaddy.as | 28 +++++++++++++------------- 2 files changed, 28 insertions(+), 14 deletions(-) diff --git a/src/as/com/threerings/README.txt b/src/as/com/threerings/README.txt index cd8295682..a4466016e 100644 --- a/src/as/com/threerings/README.txt +++ b/src/as/com/threerings/README.txt @@ -218,3 +218,17 @@ ActionScript error (grraah!). There is a compiler option "-compiler.warn-no-constructor" but it generates a flotilla of warnings from standard classes in the flash library, so it's slightly useless. + ***Update: What the heck. I noticed today that DSet has no constructor + and I've never had any trouble instantiating those. Why would not having + a constructor be an error for some classes and not others? Grraahh! + +- Static initializers can be emulated: + public class A + { + private static function staticInit () :void + { + // whatever + } + + staticInit(); // will be placed inside the real static initializer + } diff --git a/src/as/com/threerings/util/LogDaddy.as b/src/as/com/threerings/util/LogDaddy.as index 62230b42d..c062ceea3 100644 --- a/src/as/com/threerings/util/LogDaddy.as +++ b/src/as/com/threerings/util/LogDaddy.as @@ -19,22 +19,22 @@ public class LogDaddy */ public static function getLogger (pkg :String) :ILogger { - if (_targ == null) { - // goddamn I wish we could just have static initializers - _targ = new TraceTarget(); - _targ.filters = ["*"]; - _targ.level = LogEventLevel.DEBUG; - mx.logging.Log.addTarget(_targ); - // we could do some stuff here: set up different targets - // with different log levels... - } - return mx.logging.Log.getLogger(pkg); } - /** The logging target for all packages. Needed only because we - * cannot have static initializers, so we need to know in getLogger - * if we've set up the target yet or not. */ - private static var _targ :TraceTarget; + /** + * Our static (class) initializer. + */ + private static function staticInit () :void + { + var targ :TraceTarget = new TraceTarget(); + targ.filters = ["*"]; + targ.level = LogEventLevel.DEBUG; + mx.logging.Log.addTarget(targ); + // we could do some stuff here: set up different targets + // with different log levels... + } + + staticInit(); // call our static initializer } }