PrettyAMF
PrettyAMF.as
package org.flexcoder.flex2.rpc.remoting{ import flash.events.Event; import flash.net.NetConnection; import flash.net.ObjectEncoding; import flash.net.Responder; import flash.util.trace; import mx.events.EventDispatcher; import mx.rpc.AbstractService; import mx.rpc.events.FaultEvent; import mx.rpc.events.ResultEvent; import mx.managers.CursorManager; /** * PrettyAMF * @description nodさんの作っているSimpleAMFと違うため名前を変更 * 実は近いかもしれない・・? * @author sato-shi **/ dynamic public class PrettyAMF extends AbstractService { [DefaultTriggerEvent("result")] [Event("fault")] [Event("result")] private var _con:NetConnection; [Inspectable(type="String")] public var gatewayUrl:String; [Inspectable(type="Boolean")] public var showBusyCursor:Boolean = true; public function PrettyAMF(){ super(); } private function initConnection(){ _con = new NetConnection(); _con.objectEncoding = ObjectEncoding.AMF0; _con.connect(this.gatewayUrl); } public function remoteCall(methodName:String, ...args){ trace("> SimpleAMF#remoteCall"); if(_con==null){ initConnection(); } if(showBusyCursor)CursorManager.setBusyCursor(); var responder:Responder = new Responder(this.onResult,this.onFault); var callMethod:String = this.destination+"."+methodName; if(args.length>0){ _con.call(callMethod,responder,args); }else{ _con.call(callMethod,responder); } } public function onResult(resultData:Object){ trace("> SimpleAMF#onResult"); if(showBusyCursor)CursorManager.removeBusyCursor(); var resultEvent:ResultEvent=new ResultEvent(resultData,null,null); dispatchEvent(resultEvent); } public function onFault(faultData:Object){ trace("> SimpleAMF#onFault"); if(showBusyCursor)CursorManager.removeBusyCursor(); var faultEvent:FaultEvent = new FaultEvent(faultData,null,null); dispatchEvent(faultEvent); } } }
ApplicationServices.mxml
<cairngorm:ServiceLocator xmlns:mx="http://www.macromedia.com/2005/mxml" xmlns:cairngorm="org.nevis.cairngorm.business.*" xmlns:s2="org.flexcoder.flex2.rpc.remoting.*" > <s2:PrettyAMF id="phoneServiceSeaser" destination="addService" gatewayUrl="http://localhost:8080/flex2_example/gateway" showBusyCursor="true" /> <mx:RemoteObject id="phoneService" destination="ColdFusion" result="event.call.resultHandler(event)" fault="event.call.faultHandler(event)" showBusyCursor="true" source="com.mycompany.phones.service.PhoneService" /> <mx:HTTPService id="dummyDelegate" url="../assets/dummy.xml" result="event.call.resultHandler( event )" fault="event.call.faultHandler( event )" showBusyCursor="true" useProxy="false" /> </cairngorm:ServiceLocator>
勢いで作ったから微妙かも・・・。