Friday, April 28, 2006

Working with XML data in Flex and Flash

I have been playing around with a new feature of Flex 2.0 (actually it is a new part of ActionScript 3.0). It is called E4X or ECMAScript for XML. It allows Flex developers to very simply and quickly write down and dirty bindings from XML data to Flex objects.

I will be teaching a 4 hour tutorial at the upcoming Geoweb in Vancouver July 24-28 2006. My good friends at Galdos host this conference and do a great job every year. This year the course will be a hands on developer course with Flex 2.0 and a ton of ActionScripting and even a finale of using the Flex API to Yahoo maps.

Okay – so I am not going to repeat the entire tutorial module here (it is not even complete), but I will share the *.mxml file with you. It is commented to be relatively clear what is going on. For clarity, I put the GML XML sample inline. To work with XML in ActionScript, you simply declare the XML data as an object, then you can use the various XPath like filters and queries against it. While it is not as robust as the full blown JAXB, it is very effective. Here is the sample file – just cut and paste it into your Flex 2.0 project and start playing around by un-commenting the various lines that demonstrate the functionality. The actual file can be downloaded from http://www.nickull.net/blogimages/GML.mxml to avoid retyping.

Enjoy!

1 comment:

  1. couple that with the abilities of Ruby on rails :o) http://coenraets.com/tutorials/flexonrails/flexonrails.html

    ReplyDelete

Do not spam this blog! Google and Yahoo DO NOT follow comment links for SEO. If you post an unrelated link advertising a company or service, you will be reported immediately for spam and your link deleted within 30 minutes. If you want to sponsor a post, please let us know by reaching out to duane dot nickull at gmail dot com.