Symmetri Developer Blog

February 5, 2008

XML parsing in AS3

General, Flash/Flex, XML, Javascript - By Shourov Bhattacharya

Parsing XML documents in Actionscript 2 was never much fun. It had the flash.xml.XMLDocument class which did your standard XML DOM traversing and manipulation, but it was always a tedious task to do any sort of complex parsing that way. What a developer really wants is to convert the XML to objects, which would allow us to deal with the parsed data using native data structures such as arrays. I found an excellent AS2 solution written by a guy called Shane MacCartney called Flash XML Remoting which did exactly that, and I have used it successfully in Flash 8 projects which deal with XML data returned from web services.

However, AS3 has made things much easier. We now have access to ECMAScript for XML (E4X), a programming language that makes manipulating XML much more intuitive and appealing. Essentially, it means that we can refer to nodes and attributes within the XML using standard object dot notation without any extra effort. For example, the following example looks up the title attribute of the second book in the BookXml document:

var title:String = BookXml.book[2].@title;

Yet another example of why AS3 is a quantum improvement over AS2. Incidentally, this makes pulling XML data from the server a far more profitable exercise in AS3 than before. It used to be the case that JSON was the preferred method of passing data structures back to Flash, as it took no extra effort to parse JSON in AS. Now, both the JSON and XML options are very close in terms of programming effort. Of course, there may be other valid reasons for choosing one over the other.

December 2, 2007

jQuery radio button bug

Javascript - By Shourov Bhattacharya

This is especially relevant if you use the excellent jQuery treeview code to create client-side tree controls. I’ve been using it to create an input control that uses radio buttons, and I have found a weird bug - opening and closing the tree clears all radio button selections inside that branch of the tree! I tore my hair out for a while trying to work it out, then hunted it down to a known bug on the jQuery site http://dev.jquery.com/browser/trunk/jquery/src/core.js?rev=3839. Either get the new version of jQuery or copy the code into your existing version (I had to do the latter, as the latest version of jQuery breaks the treeview code which is yet to be updated).

November 7, 2007

parentElement and parentNode

Ajax, Javascript - By Shourov Bhattacharya

I’ve been using parentElement to work my way up the DOM in Javascript, but it completely slipped my mind until recently that it doesn’t work in Firefox. The reason is that parentElement is one of those non-standard little add-ons that Microsoft so love to give us when releasing browser support. The better alternative is parentNode, which is part of the W3C standard.   

Get free blog up and running in minutes with Blogsome
Theme designed by Janis Joseph