3 Replies Latest reply on Jan 31, 2007 12:25 AM by cardinalsupport

    How to build an ArrayCollection with Distinct values from an XMLListCollection?

    cardinalsupport Level 1
      Hello, I am really struggling with what seems like it should be a very simple task. I have an XML object of Courses which is made up of just Course Names. I just want to create a new ArrayCollection that is made up of only the DISTINCT/UNIQUE Course Names from the XML list to use in a combobox. I have been trying all sorts of things but nothing I try seems to work. I have some MXML listed below.

      Any Help would be much appreciated! Should be simple im sure, and once I understand this, it will make my app building a lot easier! The value for myDistinctData is the final ArrayCollection. For simplicity sake I left out my failed tests from the for each loop. THANKS TO ANYONE WHO CAN OFFER ASSISTANCE!

      MXML CODE:

      <?xml version="1.0" encoding="utf-8"?>
      <mx:Application xmlns:mx=" http://www.adobe.com/2006/mxml" layout="horizontal" initialize="go();">


      import mx.collections.ArrayCollection;

      public var myDataDistinct:ArrayCollection

      public function go():void{

      var myData:XML =

      <course cid="1">
      <name>Course 1</name>
      <course cid="2">
      <name>Course 1</name>
      <course cid="3">
      <name>Course 2</name>
      <course cid="4">
      <name>Course 3</name>
      <course cid="5">
      <name>Course 1</name>
      <course cid="6">
      <name>Course 3</name>

      for each(var thisCourse:XML in myData){



      <mx:Label text="Distinct Course Names: "/>
      <mx:ComboBox dataProvider="{myDataDistinct}" labelField=""/>