PackageTop Level
Classpublic dynamic class NetConnection
InheritanceNetConnection Inheritance Object

Player version: Flash Player 7

The NetConnection class provides the means to play back streaming FLV files from a local drive or HTTP address.

Note: This class is also supported in Flash Player 6 when used with Flash Media Server. For more information, see your Flash Media Server documentation.



Public Properties
 Property
  isConnected : Boolean
[read-only]A Boolean value that indicates whether Flash Player is connected to Flash Media Server.
  protocol : String
[read-only]The protocol used to establish the connection.
  uri : String
[read-only]The target Uniform Resource Identifier (URI) that was passed in by NetConnection.connect().
 Properties inherited from class Object
 __proto__, __resolve, constructor, prototype
Public Methods
 Method
  
Creates a NetConnection object that you can use in conjunction with a NetStream object to play back local streaming video (FLV) files.
  
call(remoteMethod:String, resultObject:Object):Void
Used with Flash Media Server to invoke a method defined on a client object in server-side ActionScript.
  
close():Void
Used with Flash Media Server to close the connection with the server.
  
connect(targetURI:String):Boolean
With Flash Media Server, creates a connection between Flash Player and an application on Flash Media Server and without Flash Media Server opens a local connection.
 Methods inherited from class Object
 addProperty, hasOwnProperty, isPropertyEnumerable, isPrototypeOf, registerClass, toString, unwatch, valueOf, watch
Events
 EventSummaryDefined by
  
onResult = function(infoObject:Object) {}
Invoked when a result object is returned by a Flash Media Server method.NetConnection
  
onStatus = function(infoObject:Object) {}
Invoked when a status change or error is posted for the NetConnection object.NetConnection
Property detail
isConnectedproperty
isConnected:Boolean  [read-only]

Language version: ActionScript 2.0
Player version: Flash Player 6

A Boolean value that indicates whether Flash Player is connected to Flash Media Server. Whenever a connection is established or closed, this property is set.

Implementation
    public function get isConnected():Boolean

See also

protocolproperty 
protocol:String  [read-only]

Language version: ActionScript 2.0
Player version: Flash Player 10

The protocol used to establish the connection. Used with Flash Media Server. Possible values are: rtmp, rtmpt, rtmps, rtmpe, and rtmpte.

For details, see the Flash Media Server documentation.

Implementation
    public function get protocol():String

See also

uriproperty 
uri:String  [read-only]

Language version: ActionScript 2.0
Player version: Flash Player 6

The target Uniform Resource Identifier (URI) that was passed in by NetConnection.connect(). Used with Flash Media Server. This value is undefined if NetConnection.connect() hasn’t been called or if no URI was passed.

For details, see the Flash Media Server documentation.

Implementation
    public function get uri():String

See also

Constructor detail
NetConnection()constructor
public function NetConnection()

Player version: Flash Player 7 — Note: This class is also supported in Flash Player 6 when used with Flash Media Server. For more information, see your Flash Media Server documentation.

Creates a NetConnection object that you can use in conjunction with a NetStream object to play back local streaming video (FLV) files. After creating the NetConnection object, use NetConnection.connect() to make the actual connection.

Playing external FLV files provides several advantages over embedding video in a Flash document, such as better performance and memory management, and independent video and Flash frame rates. The NetConnection class provides the means to play back streaming FLV files from a local drive or HTTP address.

See also


Example
See the example for NetConnection.connect().

Method detail
call()method
public function call(remoteMethod:String, resultObject:Object):Void

Language version: ActionScript 2.0
Player version: Flash Player 6

Used with Flash Media Server to invoke a method defined on a client object in server-side ActionScript.

For more information, see the Flash Media Server documentation.

When using this method with the AMF message format, you cannot connect to commonly reserved ports. This limitation doean't apply when connecting using RTMP. For a complete list of blocked ports, see the system.Security.loadPolicyFile() entry.

Parameters
remoteMethod:String — The method to invoke on the server.
 
resultObject:Object — An object to handle any value returned by the remote method. Define a handler on the result object named onResult. If the remote method doesn’t return a value, pass null.

See also

close()method 
public function close():Void

Language version: ActionScript 2.0
Player version: Flash Player 6

Used with Flash Media Server to close the connection with the server. Invokes NetConnection.onStatus() with NetConnection.Connect.Closed.

This method disconnects all NetStream objects running over this connection. Discards any queued data that has not been sent.

For more information, see the Flash Media Server documentation.

See also

connect()method 
public function connect(targetURI:String):Boolean

Language version: ActionScript 2.0
Player version: Flash Player 6 — Note: This method is also supported in Flash Player 6 when used with Flash Media Server. The RTMPE and RTMPTE protocols are available in in Flash Media Server 3, Flash Player 9 Update 3. For more information, see the Flash Media Server documentation.

With Flash Media Server, creates a connection between Flash Player and an application on Flash Media Server and without Flash Media Server opens a local connection.

With Flash Media Server, connects using a version of Real-Time Messaging Protocol (RTMP). See the Flash Media Server documentation for details about the various RTMP protocols.

Without a media server, opens a local connection through which you can play back video (FLV) files from an HTTP address or from the local file system.

When using this method with the RTMP protocol, you cannot connect to commonly reserved ports. This limitation doean't apply when using the AMF message format. For a complete list of blocked ports, see the system.Security.loadPolicyFile() entry.

When using this method, consider the Flash Player security model and the following security considerations:

For more information related to security, see the following:

Parameters
targetURI:String — If not connecting to Flash Media Server, pass null for this parameter.

If connecting to a Flash Media Server, pass the Uniform Resource Identifier (URI) of the application on the Flash Media Server that runs when the connection is made. Use the following syntax: protocol:[//host][:port]/appname/[instanceName]. For protocol, specify rtmp, rtmpt, rtmps, rtmpe, or rtmpte. For more details, see the Flash Media Server documentation.

Returns
Boolean — A Boolean value of true if you passed in a valid URI. To determine if the connection was successfully completed, use NetConnection.onStatus().

See also


Example
The following example opens a connection to play the video2.flv file. Select New Video from the Library panel's options menu to create a new video object, and give it the instance name my_video.
var connection_nc:NetConnection = new NetConnection();
connection_nc.connect(null);
var stream_ns:NetStream = new NetStream(connection_nc);
my_video.attachVideo(stream_ns);
stream_ns.play("video2.flv");

Event detail
onResultevent handler

public onResult = function(infoObject:Object) {}

Language version: ActionScript 2.0
Player version: Flash Player 6

Invoked when a result object is returned by a Flash Media Server method. You can create a function to process the result object sent by the remote method.

Parameters
infoObject:Object — The object passed by NetConnection.call() from a remote method running on Flash Media Server.

See also

onStatusevent handler 

public onStatus = function(infoObject:Object) {}

Language version: ActionScript 2.0
Player version: Flash Player 6

Invoked when a status change or error is posted for the NetConnection object. To respond to the status change or error, create a function to process the information object sent by the server.

For more information about the status codes to process, see the Flash Media Server documentation.

Parameters
infoObject:Object — An object containing code and level properties that provide information about the status of a NetConnection object.

See also