1 Reply Latest reply on Aug 29, 2011 12:07 PM by saisri2k2

    Having trouble reading in xml file as list dataprovider

    DavidWilsonNI

      I'm trying to read in an xml file using HTTPService and then assign the results as a dataprovider to a list. Here's what I have, but I'm getting the following error when I debug.

       

      TypeError: Error #1009: Cannot access a property or method of a null object reference.
      at ProofConcept/processResult()[C:\Users\user\Adobe Flash Builder 4.5\ProofConcept\src\ProofConcept.mxml:22]
      at ProofConcept/__serviceObj_result()[C:\Users\user\Adobe Flash Builder 4.5\ProofConcept\src\ProofConcept.mxml:28]
      at flash.events::EventDispatcher/dispatchEventFunction()
      at flash.events::EventDispatcher/dispatchEvent()
      at HTTPOperation/http://www.adobe.com/2006/flex/mx/internal::dispatchRpcEvent()[E:\dev\4.5.1\frameworks\pro jects\rpc\src\mx\rpc\http\HTTPService.as:993]
      at mx.rpc::AbstractInvoker/http://www.adobe.com/2006/flex/mx/internal::resultHandler()[E:\dev\4.5.1\frameworks\projec ts\rpc\src\mx\rpc\AbstractInvoker.as:318]
      at mx.rpc::Responder/result()[E:\dev\4.5.1\frameworks\projects\rpc\src\mx\rpc\Responder.as:5 6]
      at mx.rpc::AsyncRequest/acknowledge()[E:\dev\4.5.1\frameworks\projects\rpc\src\mx\rpc\AsyncR equest.as:84]
      at DirectHTTPMessageResponder/completeHandler()[E:\dev\4.5.1\frameworks\projects\rpc\src\mx\ messaging\channels\DirectHTTPChannel.as:451]
      at flash.events::EventDispatcher/dispatchEventFunction()
      at flash.events::EventDispatcher/dispatchEvent()
      at flash.net::URLLoader/onComplete()

       

      Here is my code. If anyone has any help it would be greatly appreciated.

       

      <?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="init()" width="955" height="600" initialize="init()">

      <fx:Script>
      <![CDATA[
      import mx.collections.XMLListCollection;
      import mx.rpc.events.ResultEvent;
      import mx.rpc.http.HTTPService;               

      [Bindable] private var myList:XMLListCollection = new XMLListCollection();

      private function init():void {                    
      serviceObj.send();
      }               

      public function processResult(response:ResultEvent):void{
      var xmlList:XMLList = response.result as XMLList;
      myList = new XMLListCollection(xmlList);
      lst.dataProvider = myList;
      }
      ]]>
      </fx:Script>

      <fx:Declarations>
      <mx:HTTPService id="serviceObj" url="content/contentConfig.xml" useProxy="false" resultFormat="e4x" method="GET" result="processResult(event)"/>
      </fx:Declarations>

      <s:states>
      <s:State name="INTRO" />
      <s:State name="MAIN" />
      <s:State name="END" />
      </s:states>
      <s:VGroup width="800" height="400">
      <s:Label text="INTRO" includeIn="INTRO" />
      <s:Label text="MAIN" includeIn="MAIN" />
      <s:Label text="END" includeIn="END" />

      <s:HGroup>
      <s:Button label="MAIN" click="{this.currentState = 'MAIN'}" />
      <s:Button label="END" click="{this.currentState = 'END'}" />
      <s:Button label="INTRO" click="{this.currentState = 'INTRO'}" />
      </s:HGroup>

      <s:SkinnableContainer width="800" height="400" skinClass="ShadowPanelSkin" includeIn="MAIN" >               
      <s:layout>
      <s:BasicLayout />
      <!--<s:HorizontalLayout horizontalAlign="center" gap="10"/>
      <s:VerticalLayout verticalAlign="middle"  gap="10"/>
      <s:TileLayout rowAlign="top" />-->
      </s:layout>
      <s:Rect width="100" height="100" depth="999" >
      <s:fill>
      <s:SolidColor color="#FFFFFF"  />
      </s:fill>
      </s:Rect>
      <s:Rect width="100" height="100" >
      <s:fill>
      <s:SolidColor color="#FFF00F" />
      </s:fill>
      </s:Rect>
      <s:Rect width="100" height="100" >
      <s:fill>
      <s:SolidColor color="#FF0CFF" />
      </s:fill>
      </s:Rect>
      <s:Rect width="100" height="100" >
      <s:fill>
      <s:SolidColor color="#FF0000" />
      </s:fill>
      </s:Rect>

      <s:List id="lst" width="500" height="500"/>

      </s:SkinnableContainer>
      </s:VGroup>

      </s:Application>