April 17th, 2007 by Kyle
Tags: ActionScript, as3, e4x, Flex, mxml, xml
Posted in: ActionScript, Flex
E4X is a very powerful and easy way to manipulate xml data in Flex.
Of course something so p[powerful can sometimes be confusing when it produces unexpected results.
<order>
<item id=‘1′>
<menuName>burger</menuName>
<price>3.95</price>
</item>
<item id=‘2′>
<menuName>fries</menuName>
<price>1.45</price>
</item>
</order>
</mx:XML>
If you wanted to retrieve the price of the burger menuitem above, it is easily done with the e4x expression:
<order>
<item id=’1′>
<menuName>burger</menuName>
<menuName>burger</menuName>
<price>3.95</price>
</item>
<item id=’2′>
<menuName>fries</menuName>
<price>1.45</price>
</item>
</order>
</mx:XML>
Then if you used the same expression, you actually would not get a value returned.
It is not obvious as to why this happens, but of course there is more than one way to skin a cat…
Here is an expression that will work:
Here is a link to a Flex Builder 2.0.1 project (compiled with SDK hotfix1) containing a sample demonstrating the solution described above.
No Comments »










