flash或是Flex客户端调用服务器端的方法
时间:2011-04-01 来源:Mark Dzone
在Flash或是Flex客户端,我们可以通过NetConnectin.call()调用应用程序适配器的方法。如下示例代码块:
{
public string Echo(string msg)
{
return "Echo: " + msg;
}
}
private function CallServerMethod():void
{
nc = new NetConnection();
nc.connect("rtmp://localhost:1974/application");
nc.onResult = function(obj)
{
trace("The result is " + obj);
}
nc.call("Echo", nc, "Hello");
}
服务器端应用适配器所定义的代码:
public class Application : ApplicationAdapter{
public string Echo(string msg)
{
return "Echo: " + msg;
}
}
Flash/Flex客户端可以通过以下代码块调用服务器端的方法:
private var ns:NetConnection;private function CallServerMethod():void
{
nc = new NetConnection();
nc.connect("rtmp://localhost:1974/application");
nc.onResult = function(obj)
{
trace("The result is " + obj);
}
nc.call("Echo", nc, "Hello");
}
相关阅读 更多 +