public function MainForm():void{ init(); } private function init():void{remotingNc = new NetConnection(); remotingNc.connect(gateWayUrl); remotingNc.call("net.smilecn.helloWorld.Hello.sayHello",new Responder(getMsgResult,getMsgFault),"arrow"); } private function getMsgResult(re:*){ trace("从remoting返回信息成功:",re); } private function getMsgFault(fe:*){ trace("从remoting返回信息失败:",fe.code); } } } NetConnection 是一个网络连接的类,remoting可以用这个,连接FMS也可以用这个(在后面我还会写一些FMS的教程), connect方法是连接remoting服务器,其实就是我们之前测试的地址,call方法是调用java的方法,net.smilecn.helloWorld是包名,Hello是类名,sayHello是方法名,所以一般是包名+类名+方法名,如果没有包名,就不用加包名,getMsgResult是调用正确返回结果,re就是结果,getMsgFault是错误信息返回 如果调用正确,就会输出从remoting返回信息成功:hello! arrow 这就是最基本的remoting使用,我们可以很方便的调用JAVA的方法,并返回一些值. 下节继续! |