精简的AS3 remoting
最精简的Flash Remoting实例“Helloworld”,另存为FlashCS3Remoting.as设为Document class即可测试。
- package
- {
- import flash.display.MovieClip;
- import flash.net.Responder;
- import flash.net.NetConnection;
- public class FlashCS3Remoting extends MovieClip
- {
- private var nc:NetConnection;
- private var rs:Responder;
- function FlashCS3Remoting()
- {
- var params:String = ' | Flash CS3 Remoting!';
- rs = new Responder(onResult, onFault);
- nc = new NetConnection;
- nc.connect("http://ubuntu/amfphp/gateway.php");
- nc.call("Helloworld.hello", rs, params);
- }
- private function onResult(result:*):void
- {
- trace(result);
- }
- private function onFault(fault:Object):void
- {
- for (var i in fault) {
- trace(i + ", " + fault[i]);
- }
- }
- }
- }
- <?php
- class Helloworld
- {
- function hello($param)
- {
- return "Hello World from amfphp" . $param;
- }
- }
- ?>