onConnect (XMLSocket.onConnect handler)
onConnect = function(success:Boolean) {}
Invoked by Flash Player when a connection request initiated through
has succeeded or failed. If the connection succeeded, the
otherwise the
success
The default implementation of this method performs no actions. To override the default
implementation, you must assign a function containing custom actions.
Availability: ActionScript 1.0; Flash Player 5
Parameters
- A Boolean value indicating whether a socket connection is successfully
success:Boolean
established (
or
true
false
Example
The following example illustrates the process of specifying a replacement function for the
method in a simple chat application.
onConnect
After creating the XMLSocket object using the constructor method, the script defines the
custom function to be executed when the onConnect event handler is invoked. The function
controls the screen to which users are taken, depending on whether a connection is
successfully established. If the connection is successfully made, users are taken to the main
chat screen on the frame labeled
screen with troubleshooting information on the frame labeled
var socket:XMLSocket = new XMLSocket();
socket.onConnect = function (success) {
if (success) {
gotoAndPlay("startChat");
} else {
gotoAndStop("connectionFailed");
}
}
Finally, the connection is initiated. If
to the frame labeled
connectionFailed
returns
, the SWF file jumps to a frame labeled
true
"Please wait" screen. The SWF file remains on the
handler is invoked, which happens at some point in the future depending on
onConnect
network latency.
if (!socket.connect(null, 2000)) {
gotoAndStop("connectionFailed");
} else {
1346
ActionScript classes
parameter is
.
false
).
. If the connection is not successful, users go to a
startChat
connect()
, and
parameter is
success
connectionFailed
returns
, the SWF file is sent directly
false
is never invoked. If
onConnect
waitForConnection
waitForConnection
XMLSocket.connect()
;
true
.
connect()
, which is the
frame until the
Need help?
Do you have a question about the FLASH 8-ACTIONSCRIPT 2.0 LANGUAGE and is the answer not in the manual?