This is the Title of the Book, eMatter Edition
Copyright © 2007 O’Reilly & Associates, Inc. All rights reserved.
The Communication Classes
wrong keyframe. If the client did, the video image would be made up of a mosaic of 8
x 8 pixel blocks from two different frames. RTMP also prioritizes data. Audio is
given the highest priority because it is so essential for real-time conversations. Video
is given the lowest priority, and ActionScript is given a priority in between audio and
The Communication Classes
While RTMP conveniently manages the flow of multiple streams of data across a net-
work, the real power of Flash and FlashCom for developers is realized in the high-
level classes that make connecting to the server, sharing information, and streaming
audio and video so easy and flexible. I’ll briefly review the major classes, which will
be explored in more detail and used in examples throughout the remainder of the
Connecting to the Server
The NetConnection class connects a client to an application instance on a server. In
the simplest case, you can create a connection by invoking NetConnection.connect( )
with the URI of the remote application:
nc = new NetConnection( );
To determine if the connection was established successfully, define an onStatus( )
method on the NetConnection object before invoking connect( ):
nc = new NetConnection( );
nc.onStatus = function (info) {
trace("The connection code is: " + info.code);
In this example, the RTMP address includes the host (, the applica-
tion name (campusCameras), and the instance name (
connector). If you’ve ever
developed network applications using other application programming interfaces,
you’ll likely agree that creating a network connection between Flash and FlashCom
is ridiculously easy. Chapter 3 goes into greater detail on the NetConnection class and
how to use NetConnection objects.
Streaming Audio, Video, and ActionScript Data
Once you establish a connection using a NetConnection object in the client, you can
use it to send or receive a stream containing audio and/or video. Suppose you know
that a recorded Flash video file named Ryerson_High_Speed.flv is available in the
instance’s public directory. You can attach the video stream to a video object, here
videoArea, using Video.attachVideo( ) and play it using ). The

Get Programming Flash Communication Server now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.