diff --git a/src/as/com/threerings/util/CommandEvent.as b/src/as/com/threerings/util/CommandEvent.as index 38ff54eb0..fe963ef56 100644 --- a/src/as/com/threerings/util/CommandEvent.as +++ b/src/as/com/threerings/util/CommandEvent.as @@ -39,16 +39,34 @@ public class CommandEvent extends Event { if (cmdOrFn is Function) { var fn :Function = (cmdOrFn as Function); - var args :Array = (arg as Array); - if (args == null && arg != null) { + // build our args array + var args :Array; + if (arg is Array) { + // if we were passed an array, treat it as the arg array. + // Note: if you want to pass a single array param, you've + // got to wrap it in another array, so sorry. + args = arg as Array; + + } else { args = [ arg ]; } try { fn.apply(null, args); } catch (err :Error) { - var log :Log = Log.getLog(CommandEvent); - log.warning("Unable to call command callback, stack trace follows."); - log.logStackTrace(err); + if (arg == null) { + try { + // try with no args + fn(); + err = null; // on success, clear the error + } catch (err2 :Error) { + err = err2; + } + } + if (err != null) { + var log :Log = Log.getLog(CommandEvent); + log.warning("Unable to call command callback, stack trace follows."); + log.logStackTrace(err); + } } } else if (cmdOrFn is String) { diff --git a/src/as/com/threerings/util/Controller.as b/src/as/com/threerings/util/Controller.as index a193f30a9..98d8f1be1 100644 --- a/src/as/com/threerings/util/Controller.as +++ b/src/as/com/threerings/util/Controller.as @@ -78,32 +78,14 @@ public class Controller // 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; + if (fn == null) { + // never found it? + return false; } - return false; // not handled + // finally, dispatch it + CommandEvent.dispatch(_controlledPanel, fn, arg); + return true; } /**