0

我想在 flex 中获取 Yahoo 天气信息我想获取图像我想获取所有当前条件我的代码是:::

<fx:Declarations>
    <!-- Place non-visual elements (e.g., services, value objects) here -->
    <s:HTTPService id="weatherService"
                   url="{BASE_URL}"
                   resultFormat="object"
                   result="weatherService_resultHandler(event)"
                   fault="weatherService_faultHandler(event)"
                   showBusyCursor="true">
        <s:request xmlns="">
            <w>{woeidInput.text.toString()}</w>             
        </s:request>
    </s:HTTPService>
</fx:Declarations>


<s:TextInput id="woeidInput" x="10" y="10" width="207" text="12744805"/>
<s:Button id="searchBtn" x="220" y="10" width="90" height="36" label="Search"/>
<s:Label id="cityName" x="134" y="82" height="17" fontSize="20" fontWeight="bold" text="Label"/>


<fx:Script>
    <![CDATA[
        import mx.rpc.events.FaultEvent;
        import mx.rpc.events.ResultEvent;
        private static const BASE_URL:String="http://weather.yahooapis.com/forecastrss?";
        private static const WOEID:String="615702";

        protected function weatherService_resultHandler(event:ResultEvent):void
        {
            // TODO Auto-generated method stub
            var result_weather_data:Object = event.result;

            cityName.text=result_weather_data.title;


        }

        protected function weatherService_faultHandler(event:FaultEvent):void
        {
            // TODO Auto-generated method stub

        }

    ]]>
</fx:Script>

请给我一个解决方案,我是 flex 开发的新手

4

1 回答 1

0

好的,我知道如何从 yahoo weather rss 获取一些信息。在脚本块中我改变了

<fx:Declarations>
    <!-- Place non-visual elements (e.g., services, value objects) here -->
    <s:HTTPService id="weatherService"
                   url="{BASE_URL}"
                   resultFormat="e4x"
                   result="weatherService_resultHandler(event)"
                   fault="weatherService_faultHandler(event)"
                   showBusyCursor="true">
        <s:request xmlns="">
            <w>{woeidInput.text.toString()}</w>             
        </s:request>
    </s:HTTPService>
</fx:Declarations>

现在在脚本块 II 中是这样的:

            protected function weatherService_resultHandler(event:ResultEvent):void
        {
            // TODO Auto-generated method stub
            var result_weather_data_xml:XML = new XML(event.result);
            var cityNameData:XMLList = result_weather_data_xml.descendants().attribute("city");
            var countryNameData:XMLList = result_weather_data_xml.descendants().attribute("country");
            var tempCData:XMLList = result_weather_data_xml.descendants().attribute("temp");
            var descripData:XMLList = result_weather_data_xml.descendants().attribute("text");
            var humidData:XMLList = result_weather_data_xml.descendants().attribute("humidity");

            var image:String;
            cityName.text=cityNameData + ", "+ countryNameData;
            tempData.text = tempCData+"\u00B0"+"F";
            descData.text = descripData[0];
            HumidityData.text = humidData+"%";
        }

并且对于您想要在您的应用程序中的每一件事是给属性(“事物名称”)

于 2012-10-06T13:54:59.587 回答