XMLSocket.onClose( ) Event Handler | Flash 5 |
invoked when the server closes the connection |
The onClose( ) event handler is executed whenever an open connection to socket is closed by the server (not by Flash). Server-instigated closures usually result from a server application shutting down or deliberately "kicking off" the client.
To respond to an onClose( ) event, we must assign our own function (i.e., our callback handler) to the onClose property of an XMLSocket object. We use the callback handler to detect an external socket disconnection. The following code assigns the function handleClose( ) to mySocket's onClose property. The handleClose( ) function simply alerts the user that a closure has occurred by updating the value of the text field status_txt:
mySocket = new XMLSocket(); mySocket.onClose = handleClose; function handleClose () { status_txt.text += ("\nThe server has terminated the connection.\n"); }
XMLSocket.close( ); Chapter 10