3 Replies Latest reply on Mar 19, 2008 1:36 AM by s.lanton

    Can't get adobe example to work

    s.lanton Level 1
      At http://www.adobe.com/devnet/flex/quickstart/using_data_providers/#external there is an example of using an HTTPService control to read in an XML file and then uses the read-in data as the data provider for a List control.
      but I can't get it to work. The only thing I have changed is the httpservice url from
      url="data/bloggers.xml" to
      url=" http://www.mysite.com/bloggers.xml but every time I try to run the application I get an error message. The problem is related to the binding because if I take out the code ... dataProvider="{bloggersCol}" on the list component the application will run but obviously not as intended. Can any one see what the problem is?
      The xml is

      <bloggers>
      <blogger>
      <name>Andy Budd</name>
      <url> http://andybudd.com</url>
      </blogger>

      <blogger>
      <name>Grant Skinner</name>
      <url> http://gskinner.com</url>
      </blogger>
      <blogger>

      <name>Paul Booth</name>
      <url> http://paulbooth.com</url>
      </blogger>
      </bloggers>
      and the application code is

      <?xml version="1.0" encoding="utf-8"?>
      <mx:Application
      xmlns:mx=" http://www.adobe.com/2006/mxml"


      width="350" height="220"
      creationComplete="bs.send();"
      >
      <mx:Script>

      <![CDATA[
      import mx.managers.CursorManager;
      import mx.rpc.events.InvokeEvent;
      import mx.controls.Alert;
      import mx.rpc.events.FaultEvent;
      import mx.rpc.events.ResultEvent;
      import mx.collections.ArrayCollection;

      [Bindable]

      private var bloggersCol:ArrayCollection;

      // Gets called when HTTPService is invoked to
      // request the XML.
      private function bsInvokeHandler(event:InvokeEvent):void

      {
      // Display the busy cursor
      CursorManager.setBusyCursor();
      }

      // Gets called when the XML is successfully loaded.
      private function bsResultHandler(event:ResultEvent):void

      {
      // Save a reference to the list of bloggers
      bloggersCol = event.result.bloggers.blogger;

      // Hide the busy cursor
      CursorManager.removeBusyCursor();
      }


      private function bsFaultHandler(event:FaultEvent):void
      {

      // There was an error in loading the XML
      Alert.show (event.fault.message);

      // Hide the busy cursor
      CursorManager.removeBusyCursor();
      }
      ]]>

      </mx:Script>

      <!-- Service to load in XML -->
      <mx:HTTPService
      id="bs"
      url="data/bloggers.xml"

      invoke="bsInvokeHandler(event);"
      result="bsResultHandler(event);"
      fault="bsFaultHandler(event);"

      />

      <mx:Panel title="Bloggers we love!" width="100%">

      <mx:List
      id="bloggersList" width="100%" rowCount="4"

      dataProvider="{bloggersCol}"
      labelField="name"
      />

      <mx:ControlBar horizontalAlign="center">

      <mx:Button
      label="Add a blogger!"
      click="bloggersCol.addItem({name:'Pete-Barr Watson', url:' http://petebarrwatson.com/'});"

      />
      </mx:ControlBar>

      </mx:Panel>
      </mx:Application>