3 Replies Latest reply on Aug 20, 2007 9:22 AM by lukemack

    sorting an XMLList

    lukemack
      Hi,

      Can someone please post an example of how to sort an XMLList? (Flex 2 AS3). The XML coming back looks like:

      <ship id="46">Mercury</ship>
      <ship id="48">Infinity</ship>
      <ship id="59">Sun Princess</ship>
      <ship id="60">Golden Princess</ship>
      <ship id="61">Coral Princess</ship>
      <ship id="62">Star Princess</ship>
      <ship id="68">Diamond Princess</ship>
      <ship id="105">Carnival Spirit</ship>
      <ship id="130">Island Princess</ship>
      <ship id="132">Sapphire Princess</ship>
      <ship id="133">Radiance of the Seas</ship>
      <ship id="134">Seven Seas Mariner</ship>
      <ship id="208">Norwegian Pearl</ship>

      I want to sort on the name of the ship but require the data tro stay intact as I use the ship id elsewhere. To clarify, this is an XMLList, not an XMLListCollection.

      I have tried:

      public function sortData(value : XMLList) : void
      {
      // Create the Sort instance.
      var sort:Sort = new Sort();

      sort.fields = [new SortField("ship", true)];

      value.sort = sort;

      }

      but get error - TypeError: Error #1089: Assignment to lists with more than one item is not supported.

      thanks!

      luke.