5 Replies Latest reply on Sep 10, 2010 3:47 PM by RKaster

    Excluding certain items in an XML file.

    RKaster

      I built a function which adds items to an array collection to be displayed in a s:list. I also built a funciton which does the same but only under the condition that its a specific item. Since it's pulling the data from and XML file, I wanted to tell the function to only add items with <genre>tan</genre>

       

      Function:

      protected function G1_clickHandler(event:MouseEvent):void
                  {
                      testData.removeAll()
                      var aData:pictureData;
                      for each (var apic:Object in realData)
                      {
                          if(apic.genre == "tan")
                          {
                              aData = new pictureData;
                              aData.genre = apic.genre;
                              aData.title = apic.title;
                              aData.info = apic.info;
                              aData.loc = apic.loc;
                              testData.addItem(aData);
                          }
                      }
                  }

       

      However, it doesn't work. I'm not sure what I'm doing wrong. Any suggestions? My objective, for reemphasis, is to build a s:list where I can make it display only certain items of a certain type, the type which is defined inside the XML under the <genre> tag.

       

      Help appreciated,

      RKaster.

        • 1. Re: Excluding certain items in an XML file.
          RUSH-ME Level 3

          Hi

           

          If you are fetching data from xml please try this.

          for each (var apic:XML in realData.children())
                          {
                              if(apic.(genre = "tan")
                              {
                                  aData = new pictureData;
                                  aData.genre = apic.genre;
                                  aData.title = apic.title;
                                  aData.info = apic.info;
                                  aData.loc = apic.loc;
                                  testData.addItem(aData);
                              }
                          }

           

          Hope this helps.

          Rush-me

          1 person found this helpful
          • 2. Re: Excluding certain items in an XML file.
            RKaster Level 1

            I had hopes for this, but sadly it didn't work. I'm fetching the information correctly, I'm just having a difficulat time filtering certain items through. When I went through, I continued encountering an error: "Error #1123: Filter operator not supported on type mx.utils.ObjectProxy."

             

            I'm guessing it's a result of the "." after the apic, which removing only causes other problems as you can imagine.

             

            Thanks though.

            • 3. Re: Excluding certain items in an XML file.
              RUSH-ME Level 3

              Hi

               

              If you have no problem can you give the sample xml you are using and how you are assigning it to realData.

               

              Rush-me

              • 4. Re: Excluding certain items in an XML file.
                rootsounds Level 4

                This is very easy with E4X.

                 

                Assuming apic is of type XML, you can filter it like this:

                 

                var filtered:XMLList = apic.(genre = "tan");

                 

                This gives you an XMLList of only entries with an element genre that has a value of "tan".

                1 person found this helpful
                • 5. Re: Excluding certain items in an XML file.
                  RKaster Level 1

                  I looked of E4X, and did a little study on that, but I concluded that would cause problems since List components wont accept that as a dataprovider and XML nor XMLList will be converted or loaded into an ArrayCollection. So I sort of gave up on that, although I do think it's an awesome suggestion. It's just not applicable to my situation. Perhaps E4X would be a better approach, but I did find a solution.

                   

                  I'm simply depending on the filterFunction and applying that to my arrayCollection.

                   

                  Here's the the code I used to resolve the problem:

                   

                  [as]

                   

                      [Bindable]
                              public var testData:ArrayCollection = new ArrayCollection();
                             
                              public var firstTime:Boolean = true;

                   

                              protected function upload_resultHandler(event:ResultEvent):void
                              {
                                  testData = event.result.Gallery.img;
                              }
                             
                             
                              private function filter():void
                              {
                                  testData.filterFunction = filterTheList;
                                  testData.refresh();
                              }
                             
                              private function filterTheList(item:Object):Boolean {
                                  var searchString:String = filInp.text.toLowerCase();
                                  var itemName:String = (item.genre as String).toLowerCase();
                                  return itemName.indexOf(searchString) > -1;
                              }
                             
                              private function clearMyTextInput():void {
                                 
                                  if (firstTime == true )
                                  {
                                      filInp.text = "";
                                      firstTime = false;
                                  }
                              }

                   

                  [/as]

                   

                  However, your comments did point me in the right direction of where to lookm in that I changed my question to better fit the answer. I should have been asking how to filter the items in my arrayCollection, instead of exluding items in the XML. So thank you both.