1

我是 FLEX 4 的新手和新手开发人员。

我正在尝试通过 usint HTTPService 将 XML 数据检索到 ArrayCollection 类中。但我收到一条错误消息“Http Request Error”

我想优雅地解决它。有什么推荐吗???

这是 XML 代码。

<?xml version="1.0" encoding="utf-8"?>
<products>
    <product id="p1">
        <name>1100</name>
        <manufacturer>Nokia</manufacturer>
        <price>2000</price>
        <imageURL>1100.jpg</imageURL>
        <description>Nokia 1100</description>
    </product>

    <product id="p2">
        <name>1110</name>
        <manufacturer>Nokia</manufacturer>
        <price>2100</price>
        <imageURL>1110.jpg</imageURL>
        <description>Nokia 1110</description>
    </product>
</products>

这是一个源文件:

<?xml version="1.0" encoding="utf-8"?>
<s:Application xmlns:fx="http://ns.adobe.com/mxml/2009" 
               xmlns:s="library://ns.adobe.com/flex/spark" 
               xmlns:mx="library://ns.adobe.com/flex/mx" minWidth="955" minHeight="600"
               creationComplete="httpService.send();">

    <fx:Declarations>
        <!-- Place non-visual elements (e.g., services, value objects) here -->

        <mx:HTTPService id="httpService"
                        url="assets/products.xml"
                        resultFormat="object"
                        fault="httpService_fault(event)"
                        result="httpService_result(event)" />

    </fx:Declarations>
    <fx:Script>
        <![CDATA[
            import mx.collections.ArrayCollection;
            import mx.controls.Alert;
            import mx.rpc.events.FaultEvent;
            import mx.rpc.events.ResultEvent;

            public var dataObj:ArrayCollection;
            public var alert:Alert;

            private function httpService_result(event:ResultEvent):void 
            {
                dataObj = new ArrayCollection(event.result.products.product);       
            }

            private function httpService_fault(event:FaultEvent):void 
            {

                Alert.show(event.fault.faultString, event.fault.faultCode);
            }
        ]]>
    </fx:Script>
</s:Application>
4

0 回答 0