views:

19

answers:

1

Hey,

I've a XMLList like:

<parent>
    <one>
        <child id="1" />
        <child id="2" />
    </one>
    <two>
        <child id="3" />
        <child id="4" />
    </two>
</parent>

And I want to do something like this:

trace(_LIST._loc_1.child[0].@id);

Where the _loc_1 would be "one" or "two". Is this possible with the getDefinitionByName() to do this?

+1  A: 

getDefinitionByName will not help you here, use only square bracket [] to get the node you want using it's name :

var myNodeNameInAVariable:String="two";
myXML[myNodeNameInAVariable]...

Working example based on your question:

var _LIST:XML=
<parent>
    <one>
        <child id="1" />
        <child id="2" />
    </one>
    <two>
        <child id="3" />
        <child id="4" />
    </two>
</parent>;

var _loc_1:String="two";

trace(_LIST[_loc_1].child[0].@id);
Patrick