MXMLTest04 External XML Read Test

by siouxcitizen forked from MXMLTest03 XML Read Test (diff: 29)
♥0 | Line 33 | Modified 2009-04-18 13:10:41 | MIT License
play

ActionScript3 source code

/**
 * Copyright siouxcitizen ( http://wonderfl.net/user/siouxcitizen )
 * MIT License ( http://www.opensource.org/licenses/mit-license.php )
 * Downloaded from: http://wonderfl.net/c/kQev
 */

<?xml version="1.0" encoding="utf-8"?>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml"  layout="absolute" width="500" height="300" backgroundColor="#FFFFFF">
    <mx:Script>
        <![CDATA[
            //Yahooショッピングから"出石そば"で検索した結果(XML)をテキストエリアに表示
            private var query:String = "出石そば";//検索キーワード 
            private var URL:String = "http://shopping.yahooapis.jp/ShoppingWebService/V1/itemSearch?appid=uQ_E1kmxg64.0fo1fkMwTnvcEmBn.foaHDXp0MF8WvUXD3jQcDaDIAuC0b6zRFmh3BT2umN6&query=" + escapeMultiByte(query); 
            private var loader:URLLoader;
            private var xmlData:XML;
                    
            private function testTextArea():void {
                //外部XML処理中はボタンを不活性化
                btnTest.enabled = false; 
                //外部XMLデータ取得
                var request:URLRequest = new URLRequest(URL);
                request.url = URL;
                loader = new URLLoader();
                loader.addEventListener(Event.COMPLETE, completeHandler);
                
                try {
                    loader.load(request);
                } catch (error:Error) {
                    trace("Unable to load requested document.");
                }
            }
            
            private function completeHandler(event:Event):void {
                xmlData = new XML(loader.data);
                //XMLデータをテキストエリアに表示
                txtData.text = "External XML Output ->" + xmlData;
                
                //btnTest.enabled = true; //外部XML処理後にボタンを活性化
            }
        ]]>
    </mx:Script>
    <mx:Button id="btnTest" click="testTextArea();" x="10" y="10" label="ボタン" enabled="true"/>
    <mx:TextArea id="txtData" x="10" y="46" width="363" height="126">
        <mx:text>
            <![CDATA[てすとテストてすとテスト]]>
        </mx:text>
    </mx:TextArea>
</mx:Application>

Forked