Friday, March 20, 2009

E is for E4X

E4X stands for ECMAScript for XML. (Remember that ActionScript is ECMAScript.)

E4X makes XML a first-class citizen in ActionScript.

   var xmlAlbum:XML =
<album name="Sky Blue Sky" artist="Wilco">
<tracks>
<track name="Either Way" seconds="187"/>
<track name="You Are My Face" seconds="278"/>
<track name="Impossible Germany" seconds="358"/>
<track name="Sky Blue Sky" seconds="203"/>
<track name="Side With The Seeds" seconds="256"/>
<track name="Shake It Off" seconds="342"/>
<track name="Please Be Patient With Me" seconds="199"/>
<track name="Hate It Here" seconds="273"/>
<track name="Leave Me (Like You Found Me)" seconds=""/>
<track name="Walken" seconds="267"/>
<track name="What Light" seconds="216"/>
<track name="On And On And On" seconds=""/>
</tracks>

Notice in the example that you are not wrapping the XML in quotes or treating it as a string. Just type the XML as a literal.

Learn more about Flex and ActionScript support for XML via E4X at Flex After Dark...