BlazeDSの主要な機能の一つであるRemotingのクライアントサイドの処理について。
-
「ファイル > 新規 > MXML アプリケーション」をクリックして、「ファイル名」にRemoting.mxmlと入力して、「終了」。
-
remoting.mxmlにクライアントの処理を書く。
- ActionScript
- remoting.mxml
- Source
- <?xml version="1.0" encoding="utf-8"?>
- <mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="vertical" initialize="init()" viewSourceURL="srcview/index.html">
- <mx:Script>
- <![CDATA[
- import mx.rpc.remoting.RemoteObject;
- import mx.rpc.events.ResultEvent;
- import mx.rpc.events.FaultEvent;
- private var remoteObject:RemoteObject = new RemoteObject();
- private function init():void {
- initRemoteObject();
- initButtons();
- }
- private function initRemoteObject():void {
- remoteObject.destination = "remotingTutorial";
- remoteObject.addEventListener("result", hdlROResult);
- remoteObject.addEventListener("fault", hdlROFault);
- }
- private function hdlROResult(re:ResultEvent):void {
- var result:int = re.message.body.result;
- setResult(result.toString());
- }
- private function hdlROFault(fe:FaultEvent):void {
- setResult("Fail to get responce.");
- }
- private function setResult(str:String):void {
- tiResult.text = str;
- }
- private function initButtons():void {
- btnCalc.addEventListener(MouseEvent.CLICK, hdlGetCalcClick);
- btnClear.addEventListener(MouseEvent.CLICK, hdlClearClick);
- btnCalc.enabled = true;
- btnClear.enabled = true;
- }
- private function hdlGetCalcClick(me:MouseEvent):void {
- var obj:Object = new Object();
- obj.param0 = int(tiParam_0.text);
- obj.param1 = int(tiParam_1.text);
- remoteObject.getCalcResult(obj);
- }
- private function hdlClearClick(me:MouseEvent):void {
- setResult("");
- }
- ]]>
- </mx:Script>
- <mx:ApplicationControlBar>
- <mx:TextInput id="tiParam_0" text="10"/>
- <mx:Label text="+" textAlign="center"/>
- <mx:TextInput id="tiParam_1" text="20"/>
- <mx:Label text="=" textAlign="center"/>
- <mx:TextInput id="tiResult"/>
- </mx:ApplicationControlBar>
- <mx:ApplicationControlBar>
- <mx:Button label="getCalcResult" id="btnCalc" enabled="false"/>
- <mx:Button label="clear" id="btnClear" enabled="false"/>
- </mx:ApplicationControlBar>
- </mx:Application>
-
「ファイル > エクスポート」より、「Flex Builder > リリースビルド」を選択して「次へ」。「書き出し先フォルダ」をtutorialにして、「終了」。
-
これで、クライアントの開発は完了。ブラウザでhttp://localhost:8400/tutorial/remoting.htmlにアクセスして確認。




