08JulBlazeDS - Remotoing(Client)

BlazeDSの主要な機能の一つであるRemotingのクライアントサイドの処理について。

  1. 「ファイル > 新規 > MXML アプリケーション」をクリックして、「ファイル名」にRemoting.mxmlと入力して、「終了」。

    ss_023 ss_024
  2. remoting.mxmlにクライアントの処理を書く。

    • ActionScript
    • remoting.mxml
    • Source
    1. <?xml version="1.0" encoding="utf-8"?>
    2. <mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="vertical" initialize="init()" viewSourceURL="srcview/index.html">
    3.    
    4.     <mx:Script>
    5.         <![CDATA[
    6.             import mx.rpc.remoting.RemoteObject;
    7.             import mx.rpc.events.ResultEvent;
    8.             import mx.rpc.events.FaultEvent;
    9.            
    10.             private var remoteObject:RemoteObject = new RemoteObject();
    11.            
    12.             private function init():void {
    13.                 initRemoteObject();
    14.                 initButtons();
    15.             }
    16.            
    17.             private function initRemoteObject():void {
    18.                 remoteObject.destination = "remotingTutorial";
    19.                 remoteObject.addEventListener("result", hdlROResult);
    20.                 remoteObject.addEventListener("fault", hdlROFault);
    21.             }
    22.            
    23.             private function hdlROResult(re:ResultEvent):void {
    24.                 var result:int = re.message.body.result;
    25.                 setResult(result.toString());
    26.             }
    27.            
    28.             private function hdlROFault(fe:FaultEvent):void {
    29.                 setResult("Fail to get responce.");
    30.             }
    31.            
    32.             private function setResult(str:String):void {
    33.                 tiResult.text = str;
    34.             }
    35.            
    36.             private function initButtons():void {
    37.                 btnCalc.addEventListener(MouseEvent.CLICK, hdlGetCalcClick);
    38.                 btnClear.addEventListener(MouseEvent.CLICK, hdlClearClick);
    39.                
    40.                 btnCalc.enabled = true;
    41.                 btnClear.enabled = true;
    42.             }
    43.            
    44.             private function hdlGetCalcClick(me:MouseEvent):void {
    45.                 var obj:Object = new Object();
    46.                
    47.                 obj.param0 = int(tiParam_0.text);
    48.                 obj.param1 = int(tiParam_1.text);
    49.                
    50.                 remoteObject.getCalcResult(obj);
    51.             }
    52.            
    53.             private function hdlClearClick(me:MouseEvent):void {
    54.                 setResult("");
    55.             }
    56.            
    57.         ]]>
    58.     </mx:Script>
    59.    
    60.     <mx:ApplicationControlBar>
    61.         <mx:TextInput id="tiParam_0" text="10"/>
    62.         <mx:Label text="+" textAlign="center"/>
    63.         <mx:TextInput id="tiParam_1" text="20"/>
    64.         <mx:Label text="=" textAlign="center"/>
    65.         <mx:TextInput id="tiResult"/>
    66.     </mx:ApplicationControlBar>
    67.     <mx:ApplicationControlBar>
    68.         <mx:Button label="getCalcResult" id="btnCalc" enabled="false"/>
    69.         <mx:Button label="clear" id="btnClear" enabled="false"/>
    70.     </mx:ApplicationControlBar>
    71.    
    72. </mx:Application>
    ss_025
  3. 「ファイル > エクスポート」より、「Flex Builder > リリースビルド」を選択して「次へ」。「書き出し先フォルダ」をtutorialにして、「終了」。

    ss_026 ss_027 ss_028
  4. これで、クライアントの開発は完了。ブラウザでhttp://localhost:8400/tutorial/remoting.htmlにアクセスして確認。

    ss_029

Return to page top