Cairngorm框架应用

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

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> 

你可能感兴趣的:(html,PHP,框架,webservice,Blog)