Client-Side Communication ActionScript > NetStream (object) > Constructor for the NetStream object

 

Constructor for the NetStream object

Availability

Flash Player 6.

Flash Communication Server MX.

Usage

new NetStream(myRTMPConnection)

Parameters

myRTMPConnection A NetConnection object that is using the Real-Time Messaging Protocol (RTMP) to communicate with the Flash Communication Server.

Returns

A NetStream object.

Description

Constructor; creates a stream that can be used for publishing (sending) or playing (receiving) data through the specified server connection.

You can't publish and play data over the same stream at the same time. For example, if you are publishing on a stream and then call NetStream.play, an implicit NetStream.close method is called; the publishing stream then becomes a subscribing stream.

However, you can create multiple streams that run simultaneously over the same connection: one stream publishes and another stream plays.

Example

The following example shows how a publishing client and a subscribing client can connect to the Flash Communication Server and then open an application stream for sending (publishing) or receiving (playing) data over this connection.

// Publishing client contains this code.
conn = new NetConnection();         // create NetConnection object
conn.connect("rtmp://myRTMPServer.myDomain.com/app"); // connect to server

myStream = new NetStream(conn);     // open app stream within conn
myStream.publish("myWeddingVideo");       // publish data over this stream

// Subscribing client contains this code.
// Note that the connection and stream names are the same as those
// used by the publishing client. This is neither required nor prohibited,
// because the scripts are running on different machines.
// However, the parameters used with connect() and play() below 
// must be the same as those used with connect() and publish() above.
conn = new NetConnection();
conn.connect("rtmp://myRTMPServer.myDomain.com/app");

myStream = new NetStream(conn);
myStream.play("myWeddingVideo");

For more examples, see the NetStream (object) entry and Video.attachVideo.

See also

NetConnection (object), NetStream.attachAudio, NetStream.attachVideo, NetStream.play, NetStream.publish, Video.attachVideo