
XMLSocket.onData()
779
Example
The following example illustrates the process of specifying a replacement function for the
onConnect
method in a simple chat application.
The function controls which screen users are taken to, 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
startChat
. If the connection is not successful, users go to a screen
with troubleshooting information on the frame labeled
connectionFailed
.
function myOnConnect(success) {
if (success) {
gotoAndPlay("startChat")
} else {
gotoAndStop("connectionFailed")
}
}
After creating the XMLSocket object using the constructor method, the script installs the
onConnect
method using the assignment operator:
socket = new XMLSocket();
socket.onConnect = myOnConnect;
Finally, the connection is initiated. If
connect()
returns
false
, the SWF file is sent directly to
the frame labeled
connectionFailed
, and
onConnect
is never invoked. If
connect()
returns
true
, the SWF file jumps to a frame labeled
waitForConnection
, which is the “Please wait”
screen. The SWF file remains on the
waitForConnection
frame until the
onConnect
handler is
invoked, which happens at some point in the future depending on network latency.
if (!socket.connect(null, 2000)) {
gotoAndStop("connectionFailed")
} else {
gotoAndStop("waitForConnection")
}
See also
function
,
XMLSocket.connect()
XMLSocket.onData()
Availability
Flash Player 5.
Usage
XMLSocket.onData = function(
src
) {
// your statements here
}
Parameters
src
A string containing the data sent by the server.
Returns
Nothing.
Содержание FLASH MX 2004 - ACTIONSCRIPT
Страница 1: ...ActionScript Reference Guide...
Страница 8: ...8 Contents...
Страница 12: ......
Страница 24: ...24 Chapter 1 What s New in Flash MX 2004 ActionScript...
Страница 54: ...54 Chapter 2 ActionScript Basics...
Страница 80: ...80 Chapter 3 Writing and Debugging Scripts...
Страница 82: ......
Страница 110: ...110 Chapter 5 Creating Interaction with ActionScript...
Страница 112: ......
Страница 120: ...120 Chapter 6 Using the Built In Classes...
Страница 176: ......
Страница 192: ...192 Chapter 10 Working with External Data...
Страница 202: ...202 Chapter 11 Working with External Media...
Страница 204: ......
Страница 782: ...782 Chapter 12 ActionScript Dictionary...
Страница 793: ...Other keys 793 221 222 Key Key code...
Страница 794: ...794 Appendix C Keyboard Keys and Key Code Values...
Страница 798: ...798 Appendix D Writing Scripts for Earlier Versions of Flash Player...
Страница 806: ...806 Appendix E Object Oriented Programming with ActionScript 1...
Страница 816: ...816 Index...