Morphing Objects in PV3D →← AIR resource links

E4X: A better way to deal with XML.

I’m not writing anything that hasn’t already been documented out there before, but I did want to mention one of my favorite things about AS3 - E4X. E4X is ECMAScript for XML. You can read more about it here. http://en.wikipedia.org/wiki/E4X.

XML is implemented natively into ActionScript 3… no more parsing XML files form astrong. You can leverage this to traverse XML files for specific pieces of content without the need of running a for loop or converting the XML to an object or anything. The trick is mastering the syntax.

Daniel got me started on it, but here’s a great tutorial on E4x that I highly recommend to learn and experiment with. http://www.partlyhuman.com/blog/roger/as3-e4x-rundown

E4X can look pretty advanced at times… Stephen and I got a good laugh out of this line that I wrote yesterday:


return Constants.CONFIG.scenes.*.child(__BASESCENE).scene.(@id == $scene_id)[0].parent();

But it’s really not all that bad. And way better than the old firstChild.childNode.childNodes of yore.

April 23rd, 2008  by Jamie  /  5 Comments
actionscript, flash


Comments on “E4X: A better way to deal with XML.”

  1. for some reason the link has a in it and doesn’t correctly link. FYI

    Joshua Weatherspoon on April 23rd, 2008 at 6:14 pm
  2. Whoops. All fixed.

    Jamie Kosoy on April 23rd, 2008 at 6:24 pm
  3. E4X is now the backbone for a lot of my models. Using E4X to retrieve the xml data inside of it and cache it in a dictionary is the way to go. Thats a really good link BTW…

    Jesse Freeman on April 23rd, 2008 at 7:29 pm
  4. I really love E4X to. No more childNode, parentNode, firstChild crap. The funny thing is that I learned the basics from the same website that you are linking. Good stuff!

    Meinaart on April 24th, 2008 at 5:15 am
  5. Congratulations on winning your D&AD award for the HBO website

    rooster on May 16th, 2008 at 9:11 am