Notes on E4X in Actionscript3.0

by Ruben

Last tuesday I was working on the actionscript3.0 version of my calendar class. At a certain point I found myself in a situation where I needed to get data from a XML file and query it for events per date. This brought up a good excuse to get a bit more familiar with the new E4X feature, little did I know of the trouble I would have to go through to get it to work.

Although I hadn't read about this little nasty issue anywhere in the documentation, apparently when looking for a match between an attribute and a value, all nodes within the range should have that specific attribute declared..

[xml]myXML.horse.(@color=="black").@country;[/xml]

For the above example to work, all horse nodes need to have color attribute declared. If not, a runtime-error will be generated, whilst during compiletime everything will seem to be fine.
Although I can see the logic here,you still could've have told me, Adobe!

If you would like to get to know the ways of E4X a little better, check out Aral Balkan's awesome quickstart tutorials over at adobe.com.