在FLEX中通过HTTPService将XML数据检索到ArrayCollection时出错

时间:2012-09-17 11:18:30

标签: xml flex flex4 flash-builder

我是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>

0 个答案:

没有答案