# AS3 with E4X / XML

**URL:** <https://forum.kirupa.com/t/as3-with-e4x-xml/295782>\
**Category:** flash\
**Created:** [September 4, 2009, 4:14am UTC](https://forum.kirupa.com/t/as3-with-e4x-xml/295782 "2009-09-04T04:14:38Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![johnsonw](https://avatars.discourse-cdn.com/v4/letter/j/f04885/32.png) [@johnsonw](https://forum.kirupa.com/u/johnsonw)\
**Post date:** [September 4, 2009, 4:14am UTC](https://forum.kirupa.com/t/as3-with-e4x-xml/295782/1 "2009-09-04T04:14:38Z")

</div>

[FONT=Arial]Hey guys,

I am working on a project that uses XML and up until this point, reading data from the XML file has been very easy. Unfortunately, I came across a problem that has me banging my head against a wall. So here is my issue.

I have a section of XML that I have setup as follows: (Note that I have removed some attributes for cleanliness)

\<avatar\>  
\<assets target=“hair”\>  
\<asset id=“1000” src="/assets/boy/hair/boy\_hair1.swf" gender=“m”/\>  
\<asset id=“1502” src="/assets/girl/hair/girl\_hair3.swf" gender=“f”/\>  
\<asset id=“1503” src="/assets/girl/hair/girl\_hair4.swf" gender=“f”/\>  
\</assets\>  
\<assets target=“head”\>  
\<asset id=“2000” src="/assets/boy/head/boy\_head.swf" gender=“m”/\>  
\<asset id=“2503” src="/assets/girl/head/girl\_head4.swf" gender=“f”/\>  
\</assets\>  
\</avatar\>

Pretty simple so far right? Now, I actually have many more sets of assets, but I am just showing 2 here to keep things simple. All I want to do is simply obtain the first node of each set by specifying a gender. For example, if I want the first node for a female in each set, I would expect to retrieve asset id’s 1502 and 2503 in my XmlList. As simple as this sounds, I can’t seem to figure this out… Here is what I currently have:

var clothingList:XMLList = \_avatarXml.assets.asset.(@gender == “f”);

This will give me all of the assets for each set that are female (1502, 1503, and 2503). However, I just want the first asset of each set based on the gender (1502, 2503). My initial thought was to do the following:

[/FONT][FONT=Arial]var clothingList:XMLList = \_avatarXml.assets.asset.(@gender == \_avatarVO.selectedGender)[0];

This returns an xml element though… the very first element period, and not the first element of each set. Please help me understand how I need to formulate this statement so that I get the first element of each set. Thanks!

Regards,

Will  
[/FONT]
