Cairngorm框架应用

Cairngorm Webservice & HTTPService Examples
[url]http://nwebb.co.uk/blog/?p=118[/url]
Cairngorm中的SequenceCommand 用法
[url]http://dmh2002.com/post/54.html[/url]

IResponder的用法:

//ONE OPTION FOR DECLARING RESPONDER METHODS:
public class SomeDelegate implements IResponder
{
public function doSomething(){
var token:AsyncToken = this.service.send( {//send in stuff} );
token.addResponder(this); //YOU CAN DO THIS BECAUSE CLASS IMPLEMENTS IRESPONDER INTERFACE, AND SO RESULT/FAULT WILL GET CALLED
}

public function result(obj:Object):void{ //do something if server request is successful }
public function fault(obj:Object):void{ //do something if server request fails }
}

//=====================================================================

//ANOTHER OPTION FOR DECLARING RESPONDER METHODS:
public class SomeDelegate
{
public function doSomething(){
var token:AsyncToken = this.service.send( {//send in stuff} );
var responder:mx.rpc.Responder = new mx.rpc.Responder( loginResult, loginFault );
token.addResponder(responder); //CLASS DOESN'T IMPLEMENT INTERFACE, SO YOU NEED THE LINE ABOVE
}

public function loginResult(obj:Object):void{ //do something if server request is successful }
public function loginFault(obj:Object):void{ //do something if server request fails }
}



//Constructor function for class LoginDelegate
public function LoginDelegate( responder : IResponder )
{
this.service = ServiceLocator.getInstance().getHTTPService( "aaa" ); //note: getHTTPService specifically called
this.responder = responder; //the responder is a reference to your Command class
}

public function login( loginVO : LoginVO ): void
{
var token:AsyncToken = this.service.send( {username:loginVO.username, password:loginVO.password} );
token.addResponder(this); //the LoginDelegate class implements mx.rpc.IResponder and so it will declare "result" and "fault" methods
}



<!-- HTTPService declared in Services.mxml -->
<mx:httpservice id="aaa">
url="http://someurl/login.php"
showBusyCursor="true"
method="POST"
resultFormat="text"
/>


//Constructor function for class LoginDelegate
public function LoginDelegate( responder : IResponder )
{
this.service = ServiceLocator.getInstance().getWebService("bbb"); //note: getWebService specifically called
this.responder = responder; //the responder is a reference to your Command class
}

public function login( loginVO : LoginVO ): void
{
var token:AsyncToken = this.service.doLogin(loginVO);
token.addResponder(this); //the LoginDelegate class implements mx.rpc.IResponder and so it will declare "result" and "fault" methods
}


<!-- WebService declared in Services.mxml -->
<mx:webservice>
id="bbb"
wsdl="{model.config.someWsdlUrl}"
useProxy="false"
>
<mx:operation concurrency="multiple" name="doLogin" resultformat="e4x" />
<mx:operation concurrency="multiple" name="doSomethingElse" resultformat="e4x" />
</mx:webservice>
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值