From de5f5c4aec6f7d2e6dd8121d80c2ab15f4d1dd21 Mon Sep 17 00:00:00 2001 From: Ray Greenwell Date: Tue, 29 Aug 2006 20:54:23 +0000 Subject: [PATCH] Follow new style, look for a function named COMMAND first. git-svn-id: svn+ssh://src.earth.threerings.net/narya/trunk@4348 542714f4-19e9-0310-aa3c-eee0fc999fb1 --- src/as/com/threerings/util/Controller.as | 64 ++++++++++++++---------- 1 file changed, 38 insertions(+), 26 deletions(-) diff --git a/src/as/com/threerings/util/Controller.as b/src/as/com/threerings/util/Controller.as index 0d71855bf..481e7b616 100644 --- a/src/as/com/threerings/util/Controller.as +++ b/src/as/com/threerings/util/Controller.as @@ -42,34 +42,46 @@ public class Controller public function handleAction (cmd :String, arg :Object) :Boolean { // fall back to a method named the cmd + var fn :Function = null; try { - var fn :Function = (this["handle" + cmd] as Function); - if (fn != null) { - try { - try { - // try calling it with the arg - fn(arg); - } catch (ae :ArgumentError) { - if (arg == null) { - // try calling it without the arg - fn(); - } else { - throw ae; - } - } - - } catch (e :Error) { - var log :Log = Log.getLog(this); - log.warning("Error handling controller " + - "command [error=" + e + ", cmd=" + cmd + - ", arg=" + arg + "]."); - log.logStackTrace(e); - } - // we "handled" the event, even if it threw an error - return true; - } + fn = (this[cmd] as Function); } catch (e :Error) { - // suppress, and fall through + // suppress + //Log.testing("Caught error finding '" + cmd + "()' [" + this + "]"); + } + if (fn == null) { + // try the old style with "handle" prepended + try { + fn = (this["handle" + cmd] as Function); + } catch (e :Error) { + // suppress + //Log.testing("Caught error finding 'handle" + cmd + "()' [" + + // this + "]"); + } + } + if (fn != null) { + try { + try { + // try calling it with the arg + fn(arg); + } catch (ae :ArgumentError) { + if (arg == null) { + // try calling it without the arg + fn(); + } else { + throw ae; + } + } + + } catch (e :Error) { + var log :Log = Log.getLog(this); + log.warning("Error handling controller " + + "command [error=" + e + ", cmd=" + cmd + + ", arg=" + arg + "]."); + log.logStackTrace(e); + } + // we "handled" the event, even if it threw an error + return true; } return false; // not handled