MXMLでHTTPServiceを実行してみました。

構築してみたいプログラムがあるのですが、実現する為にデスクトップアプリケーション構築が必須です。
最近actionscriptに興味があるので、その流れでAIRを使いデスクトップアプリケーションを構築することにしました。

まず練習として、MXMLでHTTPServiceというのを実行してみました。

サンプルソースgoogleへhttp通信し、レスポンスをhtml表示するサンプルです。

<?xml version="1.0" encoding="utf-8"?>
  <mx:WindowedApplication xmlns:mx="http://www.adobe.com/2006/mxml">
    <mx:Script>
      <![CDATA[ 
        import mx.rpc.events.ResultEvent;
        import mx.rpc.events.FaultEvent;
        import mx.controls.Alert;

        public function Search(event:Event):void
        {
          var uv:URLVariables = new URLVariables();

          uv.q = q.text;//検索文字
			    
          search.request = uv;
          search.send();
        }

        public function handlePlain(event:ResultEvent):void
        {
          result.data = event.result.toString();
        }
	
        public function handleFault(event:FaultEvent):void
        {
          Alert.show(event.fault.faultString, "Error");
        }
		]]> 
    </mx:Script>
    <mx:HTTPService
      id="search"
      url="http://www.google.co.jp/search"
      method="GET"
      result="handlePlain(event)" 
      fault="handleFault(event)"
      resultFormat="text" />
	
    <mx:TextInput id="q" 
      x="130" y="32" 
      width="160" height="22" />
    <mx:Button x="130" y="95" 
      label="検索" 
      click="Search(event)" 
      width="160" height="22" />
    <mx:HTML id="result" />
  </mx:WindowedApplication>



[PR]Spreeの情報を集めています。

ECを持ちたい方、仕事でECを使いたい方向けのコミュニティサイトです。
このサイトでは世界で最も使用されているECの1つであるSpreeについての情報を提供しています。
http://spreecommerce.jp/