Fixup.
If there's an error when calling the callback function, we were assuming it was an argument-related error and trying again. However, this is sorta bad behavior as we don't want to call twice into a callback. In the case I was seeing, the first time in caused an NPE, but popped up a panel, and the second try was no-opping because the panel was already up (but misconfigured). So: don't even try a second call, because it looks like flash will accept args to an argless function. We'll have to try this out for a while and see if it works. If so, I can neaten this code. If not, I'll uncomment some of this and try a more surgical approach (only catch ArgumentError, only retry if we had 1 boolean arg.) git-svn-id: svn+ssh://src.earth.threerings.net/narya/trunk@5585 542714f4-19e9-0310-aa3c-eee0fc999fb1
This commit is contained in:
@@ -35,7 +35,7 @@ public class CommandEvent extends Event
|
|||||||
* Use this method to dispatch CommandEvents.
|
* Use this method to dispatch CommandEvents.
|
||||||
*/
|
*/
|
||||||
public static function dispatch (
|
public static function dispatch (
|
||||||
disp :IEventDispatcher, cmdOrFn :Object, arg :Object = null) :void
|
disp :IEventDispatcher, cmdOrFn :Object, arg :Object = null) :void
|
||||||
{
|
{
|
||||||
if (cmdOrFn is Function) {
|
if (cmdOrFn is Function) {
|
||||||
var fn :Function = (cmdOrFn as Function);
|
var fn :Function = (cmdOrFn as Function);
|
||||||
@@ -53,23 +53,31 @@ public class CommandEvent extends Event
|
|||||||
} else {
|
} else {
|
||||||
args = [ arg ];
|
args = [ arg ];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// now trying calling it
|
||||||
|
var err :Error = null;
|
||||||
try {
|
try {
|
||||||
fn.apply(null, args);
|
fn.apply(null, args);
|
||||||
} catch (err :Error) {
|
|
||||||
if (arg == null) {
|
// Commented out 2008-12-09 by Ray. I'm not sure we need this, it seems you can pass args
|
||||||
try {
|
// to an argless function without error.
|
||||||
// try with no args
|
// } catch (ae :ArgumentError) {
|
||||||
fn();
|
// if (arg is Boolean) {
|
||||||
err = null; // on success, clear the error
|
// // try with no args
|
||||||
} catch (err2 :Error) {
|
// try {
|
||||||
err = err2;
|
// fn();
|
||||||
}
|
// } catch (e2 :Error) {
|
||||||
}
|
// err = e2;
|
||||||
if (err != null) {
|
// }
|
||||||
var log :Log = Log.getLog(CommandEvent);
|
// } else {
|
||||||
log.warning("Unable to call command callback, stack trace follows.");
|
// err = ae;
|
||||||
log.logStackTrace(err);
|
// }
|
||||||
}
|
|
||||||
|
} catch (e :Error) {
|
||||||
|
err = e;
|
||||||
|
}
|
||||||
|
if (err != null) {
|
||||||
|
Log.getLog(CommandEvent).warning("Unable to call callback.", err);
|
||||||
}
|
}
|
||||||
|
|
||||||
} else if (cmdOrFn is String) {
|
} else if (cmdOrFn is String) {
|
||||||
@@ -80,8 +88,8 @@ public class CommandEvent extends Event
|
|||||||
// Dispatch it. A return value of true means that the event was
|
// Dispatch it. A return value of true means that the event was
|
||||||
// never cancelled, so we complain.
|
// never cancelled, so we complain.
|
||||||
if (disp == null || disp.dispatchEvent(event)) {
|
if (disp == null || disp.dispatchEvent(event)) {
|
||||||
Log.getLog(CommandEvent).warning("Unhandled controller command " +
|
Log.getLog(CommandEvent).warning("Unhandled controller command",
|
||||||
"[cmd=" + cmd + ", arg=" + arg + ", disp=" + disp + "].");
|
"cmd", cmd, "arg", arg, "disp", disp);
|
||||||
}
|
}
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
@@ -92,7 +100,8 @@ public class CommandEvent extends Event
|
|||||||
/**
|
/**
|
||||||
* Configure a bridge from something like a pop-up window to an alternate target.
|
* Configure a bridge from something like a pop-up window to an alternate target.
|
||||||
*/
|
*/
|
||||||
public static function configureBridge (source :IEventDispatcher, target :IEventDispatcher) :void
|
public static function configureBridge (
|
||||||
|
source :IEventDispatcher, target :IEventDispatcher) :void
|
||||||
{
|
{
|
||||||
source.addEventListener(COMMAND,
|
source.addEventListener(COMMAND,
|
||||||
function (event :CommandEvent) :void {
|
function (event :CommandEvent) :void {
|
||||||
|
|||||||
Reference in New Issue
Block a user