Write the client-side script
This script provides two button actions, either connecting to or disconnecting from the server. When connecting,
the script calls the server with a string ("World"), which triggers a response that displays the returned string ("Hello,
World!").
Choose File > New > ActionScript File. Check that the Target field has HelloWorld.fla.
1
Declare the package and import the required Flash classes:
2
package {
import flash.display.MovieClip;
import flash.net.Responder;
import flash.net.NetConnection;
import flash.events.MouseEvent;
public class HelloWorld extends MovieClip {
}
}
Declare variables for the connection and the server responder (see the
3
nents
Reference):
private var nc:NetConnection;
private var myResponder:Responder = new Responder(onReply);
Define the class constructor. Set the label and button display values, and add an event listener to the button:
4
public function HelloWorld() {
textLbl.text = "";
connectBtn.label = "Connect";
connectBtn.addEventListener(MouseEvent.CLICK, connectHandler);
}
5
Define the event listener actions, which depend on the button's current label:
public function connectHandler(event:MouseEvent):void {
if (connectBtn.label == "Connect") {
trace("Connecting...");
nc = new NetConnection();
// Connect to the server.
nc.connect("rtmp://localhost/HelloWorld");
// Call the server's client function serverHelloMsg, in HelloWorld.asc.
nc.call("serverHelloMsg", myResponder, "World");
connectBtn.label = "Disconnect";
} else {
trace("Disconnecting...");
// Close the connection.
nc.close();
connectBtn.label = "Connect";
textLbl.text = "";
}
}
Define the responder function (see the
6
label's display value:
private function onReply(result:Object):void {
trace("onReply received value: " + result);
textLbl.text = String(result);
}
Save the file as HelloWorld.as.
7
ActionScript 3.0 Language and Components
ActionScript 3.0 Language and Compo-
Reference), which sets the
FLASH MEDIA SERVER
5
Developer Guide
Need help?
Do you have a question about the 65029121 - Flash Media Streaming Server and is the answer not in the manual?