The NetConnection class creates a two-way connection between a client and
a server. The client can be a Flash Player or AIR application. The server
can be a web server, Flash Media Server, an application server running
Flash Remoting, or the <a
href="http://labs.adobe.com/technologies/stratus/" scope="external">Adobe
Stratus service. Call NetConnection.connect()
to establish the
connection. Use the NetStream class to send streams of media and data over
the connection.
For security information about loading content and data into Flash Player
and AIR, see the following:
- To load content and data into Flash Player from a web server or from a local location, see <a href="http://www.adobe.com/go/devnet_security_en" scope="external">Flash Player Developer Center: Security.
- To load content and data into Flash Player and AIR from Flash Media Server, see the <a href="http://www.adobe.com/support/flashmediaserver" scope="external">Flash Media Server documentation.
- To load content and data into AIR, see the <a href="http://www.adobe.com/devnet/air/" scope="external">Adobe AIR Developer Center.
To write callback methods for this class, extend the class and define the
callback methods in the subclass, or assign the client
property to an
object and define the callback methods on that object.
Events:
asyncError | Dispatched when an exception is thrown asynchronously × that is, from native asynchronous code. |
---|---|
ioError | Dispatched when an input or output error occurs that causes a network operation to fail. |
netStatus | Dispatched when a NetConnection object is reporting
its status or error condition. The |
securityError | Dispatched if a call to NetConnection.call() attempts to connect to a server outside the caller's security sandbox. |
Constructor
new()
Creates a NetConnection object. Call the connect()
method to make a
connection.
If an application needs to communicate with servers released prior to
Flash Player 9, set the NetConnection object's objectEncoding
property.
The following code creates a NetConnection object:
var nc = new NetConnection();
Methods
connect(command:String, ?p1:Unknown, ?p2:Unknown, ?p3:Unknown, ?p4:Unknown, ?p5:Unknown):Void
Creates a two-way connection to an application on Flash Media Server
or to Flash Remoting, or creates a two-way network endpoint for RTMFP
peer-to-peer group communication. To report its status or an error
condition, a call to NetConnection.connect()
dispatches a
netStatus
event.
Call NetConnection.connect()
to do the following:
- Pass "null" to play video and mp3 files from a local file system or from a web server.
- Pass an "http" URL to connect to an application server running Flash Remoting. Use the NetServices class to call functions on and return results from application servers over a NetConnection object. For more information, see the <a href="http://www.adobe.com/support/documentation" scope="external">Flash Remoting documentation.
- Pass an "rtmp/e/s" URL to connect to a Flash Media Server application.
- Pass an "rtmfp" URL to create a two-way network endpoint for RTMFP client-server, peer-to-peer, and IP multicast communication.
- Pass the string "rtmfp:" to create a serverless two-way network endpoint for RTMFP IP multicast communication.
Consider the following security model:
- By default, Flash Player or AIR denies access between sandboxes. A website can enable access to a resource by using a URL policy file.
- Your application can deny access to a resource on the server. In a Flash Media Server application, use Server-Side ActionScript code to deny access. See the <a href="http://www.adobe.com/go/learn_fms_docs_en" scope="external">Flash Media Server documentation.
- You cannot call
NetConnection.connect()
if the calling file is in the local-with-file-system sandbox. - You cannot connect to commonly reserved ports. For a complete list of blocked ports, see "Restricting Networking APIs" in the OpenFL Developer's Guide.
- To prevent a SWF file from calling this method, set the
allowNetworking
parameter of the theobject
andembed
tags in the HTML page that contains the SWF content.
However, in Adobe AIR, content in the application
security sandbox
(content installed with the AIR application) are not restricted by
these security limitations.
For more information about security, see the Adobe Flash Player Developer Center: Security.
Parameters:
command | Use one of the following values for the Use one of the following protocols: If the file is served from the same host where the
server is installed, you can omit the (Flash Player 10.1 or AIR 2 or later)To create
peer-to-peer applications, use the |
---|
Throws:
ArgumentError | The URI passed to the |
---|---|
IOError | The connection failed. This can happen if you
call |
SecurityError | Local-with-filesystem SWF files cannot communicate with the Internet. You can avoid this problem by reclassifying the SWF file as local-with-networking or trusted. |
SecurityError | You cannot connect to commonly reserved ports. For a complete list of blocked ports, see "Restricting Networking APIs" in the OpenFL Developer's Guide. |