
Application Development Tips and Tricks 59
In addition to the specific onStatus methods provided for the objects listed above, Flash MX also
provides a “super function” called
System.onStatus. If onStatus is invoked for a particular
object in an error condition and there is no function assigned to respond to it, Flash processes a
function assigned to
System.onStatus if it exists.
By default, every information object has a
code property containing a string that describes the
result of the
onStatus method, and a level property containing a string that is either "status",
"warning", or "error". Some information objects have additional default properties, which
provide more information about the reason onStatus was invoked.
For more information about the values returned by various
onStatus handlers, see the Client-
Side Communication ActionScript Dictionary. The following table summarizes the information
objects returned by certain server-side calls; the server-side call on the left invokes the client-side
NetConnection.onStatus handler with the code value on the right. (This information is not
included in the Client-Side Communication ActionScript Dictionary.)
The next sections include additional recommendations on how to write applications to best
implement this feature.
Putting onStatus handlers in the right place in a script
Because of network and thread timing issues, it is best to place an
onStatus handler before a
connect method in a script. Otherwise, the connection might complete before the script executes
the
onStatus handler initialization. Also, all security checks are made within the connect
method, and notifications will be lost if the
onStatus handler is not yet set up.
Overriding onStatus
One of the first things your application should do, even if you don’t need to do anything in the
onStatus handler, is to override the generic onStatus handler for all of the Flash
Communication Server objects. One strategy is to override the
onStatus handler when you start
writing the application, as shown in the following example:
// Trace all the status info
function traceStatus(info) {
trace("Level: " + info.level + " Code: " + info.code);
}
NetConnection.prototype.onStatus = traceStatus;
NetStream.prototype.onStatus = traceStatus;
SharedObject.prototype.onStatus = traceStatus;
As you develop your application and determine that you need to actually override the handler for
a specific purpose, you can delete the code above, but in the meantime you will at least see all of
the messages related to your application.
Always check for status messages on both the client and server.
Server-side call Code value for client-side NetConnection.onStatus handler
application.acceptConnection() NetConnection.Connect.Success
application.rejectConnection() NetConnection.Connect.Rejected
application.disconnect() NetConnection.Connect.Closed
Comentarios a estos manuales