1 Reply Latest reply on Nov 21, 2006 6:01 AM by Garenne

    From HTTPService to ArrayCollection

    Garenne
      Hi all,

      I've been practicing on Flex for several weeks, and I really appreciate it. I especially use it to display data from MySQL BD. One thing I can't clearly find out is how to pass data from an XML file (acessed by an HTTPService) to an ArrayCollection. I've tried several methods, it never works.

      Here's my last try :



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

      <mx:Script>
      <![CDATA[
      import mx.collections.ArrayCollection;
      import mx.utils.ArrayUtil;
      ]]>
      </mx:Script>

      <mx:HTTPService id="Liste_XML" url=" http://www.hereismyXMLfile.com/file.php" useProxy="false" method="POST"/>

      <mx:ArrayCollection id="arrayfilms" source="{mx.utils.ArrayUtil.toArray(Liste_XML.lastResult.liste.affiche)}" />

      <mx:DataGrid dataProvider="{arrayfilms}" creationComplete="Liste_XML.send()" width="500"/>
      </mx:Application>



      The datagrid doesn't display anything at all.
      Does this code look correct ? I've seen other methods to "fill" an ArrayCollection using event, but was not able to make it work... :(

      Thanks by advance for your help,
      Garenne ./.
        • 1. Re: From HTTPService to ArrayCollection
          Garenne Level 1
          Hi, this post to say i found a solution, using ResultEvent method :

          <mx:Script>
          <![CDATA[
          import mx.collections.ArrayCollection;
          import mx.rpc.events.ResultEvent;

          [Bindable]
          private var arrayfilms:ArrayCollection;
          private function resultHandler(event:ResultEvent):void {
          arrayfilms = event.result.liste.affiche;
          }
          ]]>
          </mx:Script>

          <mx:HTTPService id="ListeXML" url=" http://www.hereismyXMLfile.com/file.php" result="resultHandler(event)"/>

          So Admin can consider this topic is closed. Thank you.