Dynamically acessing items in a ObjectProxy using AS3
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开发者_StackOverflow中文版 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.
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`
}
}
You can create an extension of the Proxy class in flash.utils and have it keep a list of property names for the values you've added to the object. This would essentially be an OrderedObject class. If you google that, you should be able to find code snippets to show you how it works. Then, if you wanted to look up the name of an assigned property, you have the methods to do so.
精彩评论