3 Replies Latest reply on Nov 27, 2009 4:50 AM by RK...

    Looping through an arrayCollection

    dgwillia1982

      I need to:

      1. loop through an array collection,

      2. select a specific string from that collection

      3. extract a url from that string

      4. insert an additional string to the array with that extracted url

       

      The code I am using so far is:

       

      <mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute" minWidth="1024" minHeight="768">
          <mx:Script>
              <![CDATA[
                  import mx.collections.ArrayCollection;
                  import mx.rpc.events.ResultEvent;
                 
                  [Bindable]
                  private var resultArrayCollection:ArrayCollection;
                 
                  private function doSearch (e:MouseEvent):void
                  {
                      twitterSearch.url = "http://search.twitter.com/search.atom?q=LDN";
                      twitterSearch.send();
                  }
                 
                  private function onResult (e:ResultEvent):void
                  {
                      resultArrayCollection = e.result.feed.entry as ArrayCollection;
                  }
                 
              ]]>
          </mx:Script>
                 
         
          <mx:HTTPService id = "twitterSearch"
                          result="onResult(event)" />

       

      .....

       


      the HTTP service pulls in data from Twitter search for example http://search.twitter.com/search.atom?q=LDN.

       

      All help would be greatfully received.

        • 1. Re: Looping through an arrayCollection
          ShankarFlex3

          Hi

           

          I use this method to find objects in an ArrayCollection, you could probably modify accordingly.

           

           

          public function findObjInArry(arryRef:ArrayCollection, objId:int):Object
               {
                   if(arryRef.length == 0)
                       return null;
                      
                   for(var i:int=0; i<arryRef.length; i++)
                   {                       
                       var arryObj:Obejct = arryRef.getItemAt(i) as Object;
                          
                       if(objId == arryObj.id)
                           return arryObj;
                      
                   }
                   return null;
               }

           

          Regarding adding items to ArrayCollection you can use the addItem methods.

          1 person found this helpful
          • 2. Re: Looping through an arrayCollection
            dgwillia1982 Level 1

            I really need something like this, but this throws an error:

             

                for(var count:int = 0; count < resultArrayCollection.length; count++)
                            {
                                trace(resultArrayCollection"[count]".title);
                            }

            • 3. Re: Looping through an arrayCollection
              RK... Level 3

              Please remove the double quotes -- "[count]"

               

               

              for(var count:int = 0; count < resultArrayCollection.length; count++) {
                   trace(resultArrayCollection[count].title);     
              }