views:

144

answers:

1

I am trying to implement a find feature on a list.

In the action script method to implement the find, I'm trying to loop over the contents of the list.dataProvider and get the contents of the labelField which is dynamic. Is there a way to use the contents of a variable to get the field out of a ObjectProxy. I see that ObjectProxy has a getProperty method, but it's protected.

Code snippet:

<mx:Canvas>
  <mx:Script>
  <![CDATA[
    [Bindable]public var data:ArrayCollection;
    [Bindable]public var name:String;

    private function findItem_():void
    {
      for (var ii:int = 0; ii < data.length; ii+)
      {
        // how do I do this????
        if (data[ii].<contents of name>.indexOf(findTI_.text) >= 0)
        {
          list.selectedIndex = ii;
          break;
        }
      }
    }
   ]]>
  </mx:Script>

  <mx:List id="list" dataProvider="{data}" labelField="{name}"; />
  <mx:TextInput id="findTI" change="findItem_"/>

</mx:Canvas>

Thanks for any help.

A: 

An array collection is an array of objects. So at any index of data there is going to be an object. You can then access it like any other object with the dot or square bracket syntax.

for(var i:uint = 0 ; i < data.length; ++i)
{
  var tempObject:Object = data[i];
  if(tempArray[name] == findTI.text)
  {
    //you have found a column named `name` that matches the ontents of `findTI`
  }
}
greg
Doug
you're right, its actually a collection of objects not arrays. i changed the code above to reflect that.
greg