4 Replies Latest reply on Jun 10, 2011 11:31 AM by Daniel Pride

    ArrayCollection GetItemAt

    Daniel Pride Level 1

      I want to return the index of an item in an ArrayCollection to set the selected index property of a combo box

       

      [Bindable] public var times:ArrayCollection = new ArrayCollection(
                      [ {label:"1:00", data:"01:00:00"}, {label:"1:15", data:"01:15:00"},{label:"1:30", data:"01:30:00"} ]);

       

      The Following does not work.

       

      var item:Object = new Object();
      item = {data:"01:15:00"};
      this.RepairBySelected = times.getItemIndex(item);

       

      Given a string value of "01:15:00"

      How do I return the value of 1 from the times ArrayCollection (the index of that value)?

       

      Thanks

       

      Dan

        • 1. Re: ArrayCollection GetItemAt
          pauland Level 4

          Daniel Pride wrote:

           

          I want to return the index of an item in an ArrayCollection to set the selected index property of a combo box

           

          [Bindable] public var times:ArrayCollection = new ArrayCollection(
                          [ {label:"1:00", data:"01:00:00"}, {label:"1:15", data:"01:15:00"},{label:"1:30", data:"01:30:00"} ]);

           

          The Following does not work.

           

          var item:Object = new Object();
          item = {data:"01:15:00"};
          this.RepairBySelected = times.getItemIndex(item);

           

          Given a string value of "01:15:00"

          How do I return the value of 1 from the times ArrayCollection (the index of that value)?

           

          Thanks

           

          Dan

          You're going to have to search for it. Your code example can't work for two reasons:

           

          1) your item Object is not in the array collection - it refers to a differrent object altogether

          2) your item Object was only partof the data held in the Array collection entries (but it makes no differrence due to the first point;

           

          // find entry that has the same time string as item

          for (var i:int=0;  i< times.length; i++){

               if ( item.data == getItemAt(i).data){

                    return i;

               }

          }

          • 2. Re: ArrayCollection GetItemAt
            Daniel Pride Level 1

            Give the ArrayCollection

            [Bindable] public var times:ArrayCollection = new ArrayCollection(
                            [ {label:"1:00", data:"01:00:00"}, {label:"1:15", data:"01:15:00"},{label:"1:30", data:"01:30:00"} ]);

             

            Give me a use of GetitemIndex that would return the index of the second item listed. (i.e. 1)

             

            Thanks

            Dan

            • 3. Re: ArrayCollection GetItemAt
              pauland Level 4

              Daniel Pride wrote:

               

              Give the ArrayCollection

              [Bindable] public var times:ArrayCollection = new ArrayCollection(
                              [ {label:"1:00", data:"01:00:00"}, {label:"1:15", data:"01:15:00"},{label:"1:30", data:"01:30:00"} ]);

               

              Give me a use of GetitemIndex that would return the index of the second item listed. (i.e. 1)

               

              Thanks

              Dan

               

              Yes, Sir!

               

               

              public var _entry:Object = {label:"1:15", data:"01:15:00"};

              public var _entry2:Object = {label:"1:15", data:"01:15:00"};

              [Bindable] public var times:ArrayCollection = new ArrayCollection([ {label:"1:00", data:"01:00:00"}, _entry ,{label:"1:30", data:"01:30:00"} ]);

               

              trace(""+times.getItemIndex(_entry)+",  "+times.getItemIndex(_entry2));

              • 4. Re: ArrayCollection GetItemAt
                Daniel Pride Level 1

                Thanks !

                Made you work for your chit that time