I have a problem with my project where I try to fill a list with my xml data that I get out of an php file. I call the php file with a httpservice and this file returns xml data. Now it seems that there is a problem, but I don't get any error. I just know after debugging that my XMLListCollection remains null.
Here is my code :
<?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"
xmlns:components="components.*"
creationComplete="httpService.send()">
<s:layout>
<s:VerticalLayout paddingTop="20" gap="20"
horizontalAlign="center" />
</s:layout>
<fx:Script>
<![CDATA[
import mx.rpc.events.ResultEvent;
import mx.collections.ArrayCollection;
import mx.collections.XMLListCollection;
import mx.rpc.events.FaultEvent;
import mx.controls.Alert;
private var alert:Alert;
private function httpService_fault(evt:FaultEvent):void {
var title:String = evt.type + " (" + evt.fault.faultCode + ")";
var text:String = evt.fault.faultString;
alert = Alert.show(text, title);
Bezoekers.removeAll();
}
private function httpService_result(evt:ResultEvent):void {
var xmlList:XMLList = XML(evt.result).bezoekers.bezoeker;
Bezoekers = new XMLListCollection(xmlList);
}
]]>
</fx:Script>
<fx:Declarations>
<s:HTTPService id="httpService"
url="http://localhost/projectnieuw/src/data/bezoekersList.php"
resultFormat="e4x"
fault="httpService_fault(event);"
result="httpService_result(event)" />
<!--<fx:Model id="lijstAlleLeden" source="httpAlleLeden" />-->
<!--<s:ArrayCollection id="acBezoekers" source="{Bezoekers}"/>-->
<s:XMLListCollection id="Bezoekers"/>
</fx:Declarations>
<components:Heading/>
<s:HGroup gap="50">
<components:BezoekersList bezoekerList="{Bezoekers}" />
<components:ReservationForm/>
</s:HGroup>
</s:Application>
I don't seem to get what's wrong.
Thanks in advance
Greetings from Belgium
your XMLListCollection remains null means
Bezoekers = new XMLListCollection(xmlList);
gives to it null. so first of all try to trace that result was not null from server-side. To test server-side response, you have one trick is that, open your HTTPService's URL in web-browser and get XML data in Web-browser. if get success then tryresultFormat="xml"
instead ofresultFormat="e4x"
and read documentation of HTTPService's result Type to know how to use it. it has also some case-to-case basis solution for XML.May this will help you...