22 September 2008

The Power of Flex's resultFormat E4X

While researching how to bind XML data to a Flex AdvancedDataGrid, I saw various examples that had the data converted to array objects. That might have been the only way to work with XML prior to ActionScript 3.0. Now however, a new set of classes and functionality, known as E4X (ECMAScript-for-XML), make life easier for developers.

Playing around, I discovered that, on the HTTPService object, a simple property allows the data to be accessible via simple XML calls,

service.resultFormat = "e4x";

This enables your datagrid's columns' dataField to simply have your XML element or attribute name as its value. For example, to read an id attribute off of the root element of your XML, you'd use dataField="@id".

1 comment:

Derek Basch said...

Thanks for the tip. Just what I needed.