3 Replies Latest reply on Dec 2, 2009 7:14 PM by kglad

    Returning an Array of Items from PHP using URLLoader

    kowboy_koder

      Hi all. I'm trying to return a whole bunch of items (in an Array) from PHP using the following code:

       

      var req:URLRequest = new URLRequest("http://mysite.com/somescript.php")

       

      var loader:URLLoader = new URLLoader();
      loader.dataFormat = URLLoaderDataFormat.VARIABLES
      loader.load(req);

       

      loader.addEventListener(Event.COMPLETE, loader_load);

       

      function loader_load(e:Event)
      {
          trace(e.target.data.Items[0]);
      }

       

       

      But basically I just get:

       

      TypeError: Error #1010: A term is undefined and has no properties.
          at downloads_fla::MainTimeline/loader_load()
          at flash.events::EventDispatcher/dispatchEventFunction()
          at flash.events::EventDispatcher/dispatchEvent()
          at flash.net::URLLoader/onComplete()

       

      However, when I try to trace "e.target.data", I can see that the array name and values are actually there (with some Hexadecimal addressing in there as well).

       

      On the server side, I'm outputting the array as per normal (Never tried outputting an array before), like so:

       

              for(.....)
              {
                  $row = mysql_fetch_assoc($result);
                  $items[$i] = $row['ItemNo'];
              }

       

             $returnVars['Items'] = $items;

             $returnString = http_build_query($returnVars);

       

      I know that http_build_query creates a key / value array out of the items within ReturnVars, and wasn't sure how it would handle creating a nested array sort of thing (an array within an array). Is this at all possible or would I need to output the values one dimension at a time more or less in seperate http queries?

       

      Thanks all.