1 Reply Latest reply on May 15, 2010 5:07 PM by Flex harUI

    Array recurse oddity

    CrazyMerlin Level 1

      I honestly could not think of a better title, so please excuse that.

       

      OK, I have a flex app that calls a PHP script to list the contents of a media folder. The result is returned in JSON format and once decoded looks like this:

       

      Object

         |- Array

              |- Object

              |- Object

         |- Array

              |-Object

              etc.

       

      I am parsing the data to convert it to a format I can use in a tree control, via this code (o is Object):

       

      var arr:Array = new Array({name: 'media', children: new Array()});

       

      for(var n:String in o) {

           arr[0].children.push({name: n, children: o[n]});

      }

       

      Very simple conversion. However, the data is return from PHP sorted, the first array is "audio", the second "images" and the third "video".

      When I get the data back from the above code it ia always in the order "audio", "video", "images".

      I have debugged the code and it does indeed read the first, then last, then second items in that order.

       

      Is there a logical reason for this, is it a bug, or do I have a code issue?

       

      Thanks,

      Paul