Giorgio Gelardi Giorgio Gelardi - 4 months ago 26
ActionScript Question

How to find an ArrayCollection item with a specific property value?

I have some XML structures like this:

var struct:XML = <mh>
<mi id="1" stuff="whatever"/>
<mi id="2" stuff="whatever"/>
<mi id="3" stuff="whatever"/>
</mh>;


I know I can access a subnode by "id", in this way:

var stuff:Object = struct.(hasOwnProperty('@id') && @id == '2').@stuff;


Now I have some similar ArrayCollection structure:

private var cmenu:ArrayCollection = new ArrayCollection([
{id:"1", stuff:"whatever"},
{id:"2", stuff:"whatever"},
{id:"3", stuff:"whatever"}
]);


I wonder if items can be accessed in a similar way, like this:

var stuff:Object = cmenu['id == 2'].stuff;


Is it possible?

Answer

No, you can't. struct.mi.(@id == "2").@stuff is E4X which is short for ECMA Script for XML. You can't use e4x on other AS objects.

Comments