0 Replies Latest reply on Apr 15, 2007 3:45 AM by portuguesedanny

    Binding ArrayCollection to HTTPService method="POST" xml result

    portuguesedanny
      Hi All,


      Firstly apologies for posting all this code!
      I have the following app that adds & displays in a datagrid the data from a mysql db, works fine so far.

      #########################<START SNIP>##########################

      <?xml version="1.0" encoding="utf-8"?>
      <mx:Application xmlns:mx=" http://www.adobe.com/2006/mxml" xmlns="*" layout="absolute" backgroundGradientColors="[#0080ff,#80ffff]" creationComplete="send_data()">


      <!-- This is the Script to SetUp Functions-->
      <mx:Script>
      <![CDATA[
      private function youveClicked():void {
      mx.controls.Alert.show('You Clicked!!!');
      }
      private function send_data():void {
      staffcodeRequest.send();
      }
      ]]>
      </mx:Script>


      <!-- This is the HTTPService-->
      <mx:HTTPService id="staffcodeRequest" url=" http://192.168.0.84/amfphp/services/staffcode.php" useProxy="false" method="POST">
      <mx:request xmlns="">
      <firstname>{firstname.text}</firstname><surname>{surname.text}</surname><staffcode>{staff code.text}</staffcode><emailaddress>{emailaddress.text}</emailaddress><department>{departm ent.text}</department>
      </mx:request>
      </mx:HTTPService>

      ###########################<END SNIP>##########################




      I'm thinking of Binding the the xml formated results into an arrayCollection & then use the filterFunction to allow a user to filter the data (is this possible?).
      (Below is some code that I found in a thread & am using to work from as an example)

      #########################<START SNIP>##########################

      <mx:Application xmlns:mx=" http://www.adobe.com/2006/mxml" layout="vertical" creationComplete="initData()">
      <mx:Script>
      <![CDATA[
      import mx.collections.ArrayCollection;
      [Bindable]
      private var dataList:ArrayCollection ;

      private function initData():void{
      dataList= new ArrayCollection([
      {name:"school A", city:"Dartford"},
      {name:"school B", city:"Pomona "},
      {name:"School C", city:"Phillipsburg"}
      ])
      }

      private function filterDemo():void{
      dataList.filterFunction = searchDemo;
      dataList.refresh();
      }

      private function searchDemo(item:Object):Boolean{
      var isMatch:Boolean = false
      if(item.name.toLowerCase().search(search.text.toLowerCase()) != -1){
      isMatch = true
      }
      return isMatch;
      }

      private function clearSearch():void{
      dataList.filterFunction = null;
      dataList.refresh();
      search.text = '';
      }
      ]]>
      </mx:Script>

      ###########################<END SNIP>##########################



      If it is possible, I need some help in integrating the following code, (I've tried but keep getting {1151: A conflict exists with definition staffcodeRequest in namespace internal.})

      #########################<START SNIP>##########################

      <?xml version="1.0" encoding="utf-8"?>
      <mx:Application xmlns:mx=" http://www.adobe.com/2006/mxml" xmlns="*" layout="absolute" backgroundGradientColors="[#0080ff,#80ffff]" creationComplete="send_data()">


      <!-- This is the Script to SetUp Functions-->
      <mx:Script>
      <![CDATA[

      private function youveClicked():void {
      mx.controls.Alert.show('You Clicked!!!');
      }
      private function send_data():void {
      staffcodeRequest.send();
      }

      <!--Can I just Bind the arrayCollection here-->

      import mx.collections.ArrayCollection;
      [Bindable]
      private var staffcodeRequest:ArrayCollection;

      private function filterDemo():void{
      staffcodeRequest.filterFunction = searchDemo;
      staffcodeRequest.refresh();
      }
      private function searchDemo(item:Object):Boolean{
      var isMatch:Boolean = false
      if(item.staffcode.toLowerCase().search(search.text.toLowerCase()) != -1){
      isMatch = true}
      return isMatch;
      }
      private function clearSearch():void{
      staffcodeRequest.filterFunction = null;
      staffcodeRequest.refresh();
      search.text = '';
      }
      ]]>
      </mx:Script>


      <!-- This is the HTTPService-->
      <mx:HTTPService id="staffcodeRequest" url=" http://192.168.0.84/amfphp/services/staffcode.php" useProxy="false" method="POST">
      <mx:request xmlns="">
      <firstname>{firstname.text}</firstname><surname>{surname.text}</surname><staffcode>{staff code.text}</staffcode><emailaddress>{emailaddress.text}</emailaddress><department>{departm ent.text}</department>
      </mx:request>
      </mx:HTTPService>

      ###########################<END SNIP>##########################

      What I am strugling with is BINDING the returned xml formated results to an arrayCollection, and changing from the static xml file example to mxl formated txt received from the mysql db on the fly.
      Help would be grate ;-)

      TIA
      Danny