Flash CS3 Documentation |
|||
| Programming ActionScript 3.0 > Networking and communication > Basics of networking and communication | |||
When you build more complex ActionScript applications, you often need to communicate with server-side scripts, or load data from external XML or text files. The flash.net package contains classes to send and receive data across the Internet--for example, to load content from remote URLs, to communicate with other Flash Player instances, and to connect to remote websites.
In ActionScript 3.0, you can load external files with the URLLoader and URLRequest classes. You then use a specific class to access the data, depending on the type of data that was loaded. For instance, if the remote content is formatted as name-value pairs, you use the URLVariables class to parse the server results. Alternatively, if the file loaded using the URLLoader and URLRequest classes is a remote XML document, you can parse the XML document using the XML class's constructor, the XMLDocument class's constructor, or the XMLDocument.parseXML() method. This allows you to simplify your ActionScript code because the code for loading external files is the same whether you use the URLVariables, XML, or some other class to parse and work with the remote data.
The flash.net package also contains classes for other types of remote communication. These include the FileReference class for uploading and downloading files from a server, the Socket and XMLSocket classes that allow you to communicate directly with remote computers over socket connections, and the NetConnection and NetStream classes, which are used for communicating with Flash-specific server resources (such as Flash Media Server and Flash Remoting servers) as well as for loading video files.
Finally, the flash.net package includes classes for communication on the users' local computer. These include the LocalConnection class, which allows you to communicate between two or more SWF files running on a single computer, and the SharedObject class, which allows you to store data on a user's computer and retrieve it later when they return to your application.
The following list describes the most common things you'll want to do related to external communication from ActionScript; these tasks are described in this chapter:
The following reference list contains important terms that you will encounter in this chapter:
name=value. Each variable (that is, each name-value pair) is separated by ampersand characters, like this: variable1=value1&variable2=value2. In this way, an indefinite number of variables can be sent as a single message.While you're working through this chapter you might want to test the example code listings. Several of the code listings in the chapter load external data or perform some other type of communication; often these samples include trace() function calls, so the results of running the example are displayed in the Output panel. Other examples actually perform some function, such as uploading a file to a server. Testing those examples will involve interacting with the SWF and confirming that they perform the action they claim to perform.
The code examples fall into two categories. Some of the example listings are written assuming the code is in a standalone script, such as attached to a keyframe in a Flash document. To test those examples:
Other example code listings are written as a class; the expectation is that the example class will serve as the document class for the Flash document. To test those examples:
Finally, some of the examples in the chapter involve interacting with a program running on a server. These examples include code that can be used to create the necessary server program to test the example; you will need to set up the appropriate applications on a web server computer in order to test those examples.
Flash CS3
Send me an e-mail when comments are added to this page | Comment Report
Current page: http://livedocs.adobe.com/flash/9.0/main/00000315.html