Adobe 65029121 - Flash Media Streaming Server Developer's Manual page 23

Developer's guide
Hide thumbs Also See for 65029121 - Flash Media Streaming Server:
Table of Contents

Advertisement

Write the class constructor, registering an event listener on each button:
9
public function HelloServer() {
// register listeners for mouse clicks on the two buttons
connectBtn.addEventListener(MouseEvent.CLICK, connectHandler);
closeBtn.addEventListener(MouseEvent.CLICK, closeHandler);
}
Use
addEventListener()
occurs on the Connect button. Likewise, call
button.
10
Write the
connectHandler()
public function connectHandler(event:MouseEvent):void {
trace("Okay, let's connect now");
nc = new NetConnection();
nc.addEventListener(NetStatusEvent.NET_STATUS, netStatusHandler);
nc.connect("rtmp://localhost/HelloServer");
}
In
connectHandler()
object. Then, connect to the application instance on the server by calling
correct URI. This URI connects to an application instance named HelloServer, where the server runs on the same
computer as the client.
11
Write the
closeHandler()
public function closeHandler(event:MouseEvent):void {
trace("Now we're disconnecting");
nc.close();
}
It's a best practice to explicitly call
Write the
12
netStatusHandler()
public function netStatusHandler(event:NetStatusEvent):void {
trace("connected is: " + nc.connected);
trace("event.info.level: " + event.info.level);
trace("event.info.code: " + event.info.code);
switch (event.info.code)
{
case "NetConnection.Connect.Success":
trace("Congratulations! you're connected" + "\n");
break;
case "NetConnection.Connect.Rejected":
trace ("Oops! the connection was rejected" + "\n");
break;
case "NetConnection.Connect.Closed":
trace("Thanks! the connection has been closed" + "\n");
break;
}
}
A
object contains an
netStatus
connection status.
Understand the connection messages
When you run the sample and click the Connect button, you see messages like this, as long as the connection is
successful:
to call an event handler named
closeHandler()
function to connect to the server when a user clicks the Connect button:
, add an event listener to listen for a
function to define what happens when a user clicks the Close button:
to close the connection to the server.
close()
function to handle
object, which in turn contains a
info
connectHandler()
when a
MouseEvent occurs on the Close
click
event returned by the NetConnection
netStatus
NetConnection.connect()
objects returned by the NetConnection object:
netStatus
and a
level
ADOBE FLASH MEDIA SERVER
Developer Guide
when a
MouseEvent
click
with the
that describes the
code
20

Advertisement

Table of Contents
loading

This manual is also suitable for:

Flash media server

Table of Contents