在AS3中更爽快地使用Flash Remoting
作者:Flying 日期:2008-02-22
在AS3中,目前我们只能使用NetConnection来调用Flash Remoting(http://www.riafan.com/article/flash/flash-remoting-actionScript-3.0.html),不过我总觉得用起来好像不方便,参照Flash Remoting ActionScript 2.0的API,我对NetConnection调用 Remoting服务进行了简单封装,大家可以参考一下。
类似地,这套类库也包括Service、PendingCall等类,主要是主了方便已经习惯使用Flash Remoting ActionScript 2.0 API的用户。
用法很简单。
package {
import flash.display.Sprite;
import flash.net.ObjectEncoding;
import com.riafan.remoting.PendingCall;
import com.riafan.remoting.Service;
import com.riafan.rpc.FaultEvent;
import com.riafan.rpc.ResultEvent;
/**
* Flash Remoting ActionScript 3.0
* @author Flying
*/
public class Main extends Sprite {
public function Main() {
//创建远程服务
var service : Service = new Service("tutorials.remoting.HelloWorld",
"http://www.riafan.com/Gateway.aspx",
ObjectEncoding.AMF3);
//调用远程方法
var rpc : PendingCall = service.sayHello("Flying");
//注册调用成功的事件侦听器对象
rpc.addEventListener(ResultEvent.RESULT, successHandler);
//注册调用成功失败的侦听器对象
rpc.addEventListener(FaultEvent.FAULT, resultHandler);
}
//声明处理调用成功的侦听器函数
private function resultHandler( re : ResultEvent ) : void {
// 您好,Flying。这是来自Fluorine Flash remoting的问候
trace(re.result);
}
//声明处理调用失败的侦听器函数
private function faultHandler( fe : FaultEvent ) : void {
trace(fe.fault.description);
}
}
}
是不是方便多了?点击此处下载源码。
上一篇: Adobe正式发布Director 11
下一篇: Flex Builder 3 Professional及AIR1.0下载
文章来自: 本站原创
Tags: Actionscript3 FlashRemoting Class
相关日志:
评论: 1 | 引用: 0 | 查看次数: -
发表评论


|
| 58.56.19.36 |
| 取消审核 |
回复]