From 8a76c0de9fc569a053a1f03fc65e805df7f5291d Mon Sep 17 00:00:00 2001 From: Michael Bayne Date: Thu, 23 Oct 2008 20:08:47 +0000 Subject: [PATCH] Allow a custom error handler to be provided to the TableDirector. If ActionScript supported anonymous classes, TableDirector would not have to implement InvocationService_ResultListener and could instead define a calldown handleFailure() method that the client could override by anonymously extending TableDirector at the point of instantiation and customize the failure handling thusly. But it doesn't, and so we pollute TableDirector with yet more methods that many clients probably don't care about. git-svn-id: svn+ssh://src.earth.threerings.net/vilya/trunk@763 c613c5cb-e716-0410-b11b-feb51c14d237 --- .../threerings/parlor/client/TableDirector.as | 21 ++++++++++++++++++- 1 file changed, 20 insertions(+), 1 deletion(-) diff --git a/src/as/com/threerings/parlor/client/TableDirector.as b/src/as/com/threerings/parlor/client/TableDirector.as index 4efe1bc8..5af065ec 100644 --- a/src/as/com/threerings/parlor/client/TableDirector.as +++ b/src/as/com/threerings/parlor/client/TableDirector.as @@ -164,6 +164,18 @@ public class TableDirector extends BasicDirector return _ourTable; } + /** + * By default, failure is handled by reporting feedback via the chat director. Clients that + * require custom error handling can provide a function with the signature: + *
+     * function (cause :String) :void
+     * 
+ */ + public function setFailureHandler (handler :Function) :void + { + _failureHandler = handler; + } + /** * Sends a request to create a table with the specified game configuration. This user will * become the owner of this table and will be added to the first position in the table. The @@ -344,7 +356,11 @@ public class TableDirector extends BasicDirector // documentation inherited from interface public function requestFailed (reason :String) :void { - _pctx.getChatDirector().displayFeedback(_errorBundle, reason); + if (_failureHandler != null) { + _failureHandler(reason); + } else { + _pctx.getChatDirector().displayFeedback(_errorBundle, reason); + } } /** @@ -405,5 +421,8 @@ public class TableDirector extends BasicDirector /** An array of entities that want to hear about when we stand up or sit down. */ protected var _seatedObservers :ObserverList = new ObserverList(); + + /** A custom failure handler, or null. */ + protected var _failureHandler :Function; } }