import flash.net.NetConnection; import flash.net.Responder; var nc:NetConnection = new NetConnection(); nc.connect("rtmp://localhost/testapp"); nc.addEventListener(NetStatusEvent.NET_STATUS, netConnectionHandler); nc.addEventListener(SecurityErrorEvent.SECURITY_ERROR, securityErrorHandler); var nr:Responder = new Responder(netResponderHandler); nc.call("add", nr, 2, 3); function netConnectionHandler(evt:NetStatusEvent) { trace("status: " + evt.info.code); } function securityErrorHandler(evt:SecurityErrorEvent):void { trace("securityErrorHandler: " + evt); } function netResponderHandler(serverResult:Object) { trace("The result is " + serverResult); }
NetConnection
object, and then we connect to the server app using the path rtmp://localhost/testapp
(where testapp is the name of the contextPath inside red-web.properties of the server app). Then we add an event listener, NET_STATUS, that listens for status information of the connection (like Success, Failure, or InvalidApp. Then we add an event listener SECURITY_ERROR to listen for security errors.add()
function on the server app, so we use this syntax:
var nr:Responder = new Responder(netResponderHandler);
nc.call("add", nr, 2, 3);
nc.call("add", nr, 2, 3)
to call the server app function, and we pass it the nr
responder object. That object is created and passed an event handler called netResponderHandler()
which will recieve the results of the add()
function, as it's parameter. If we pass 2 and 3 to the add() function then netResponderHandler()
will receive 5 as its serverResult
parameter.
status: NetConnection.Connect.Success
The result is 5