
Sending messages to and from Flash Player
185
You can use the
connect()
and
send()
methods of the XMLSocket class to transfer XML to and
from a server over a socket connection. The
connect()
method establishes a socket connection
with a web server port. The
send()
method passes an XML object to the server specified in the
socket connection.
When you invoke the
connect()
method, Flash Player opens a TCP/IP connection to the server
and keeps that connection open until one of the following happens:
•
The
close()
method of the XMLSocket class is called.
•
No more references to the XMLSocket object exist.
•
Flash Player exits.
•
The connection is broken (for example, the modem disconnects).
The following example creates an XML socket connection and sends data from the XML object
myXML
. To understand the script, read the commented lines (indicated by the characters
//
):
// Create a new XMLSocket object
sock = new XMLSocket();
// Call its connect() method to establish a connection with port 1024
// of the server at the URL
sock.connect("http://www.myserver.com", 1024);
// Define a function to assign to the sock object that handles
// the server’s response. If the connection succeeds, send the
// myXML object. If it fails, provide an error message in a text
// field.
function onSockConnect(success){
if (success){
sock.send(myXML);
} else {
msg="There has been an error connecting to "+serverName;
}
}
// Assign the onSockConnect() function to the onConnect property
sock.onConnect = onSockConnect;
For more information, see the
XMLSocket class
entry in
Chapter 12, “ActionScript Dictionary,”
on page 205
.
Sending messages to and from Flash Player
To send messages from a SWF file to its host environment (for example, a web browser, a
Macromedia Director movie, or the stand-alone Flash Player), you can use the
fscommand()
function. This function lets you extend your SWF file by using the capabilities of the host. For
example, you could pass an
fscommand()
function to a JavaScript function in an HTML page
that opens a new browser window with specific properties.
To control a SWF in Flash Player from web browser scripting languages such as JavaScript,
VBScript, and Microsoft JScript, you can use Flash Player methods—functions that send
messages from a host environment to the SWF. For example, you could have a link in an HTML
page that sends your SWF file to a specific frame.
Содержание 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...