Personal tools

Views

Talk:ActionScript 3:resources:apis:E4X:overview

From Adobe Labs

It appears that every E4X access is returned as an XMLList object. I can see the power and the reasoning, but my problem/question is then how to get a simple value or String data type from the list? Given the following XML (from Flickr):

<rsp> <photos> <photo id="1234" server="abc" /> <photo id="5678" server="xyz" /> </photos> </rsp>

You can trace as shown:

trace( "ID: " + flickr..photo[0].@id );

Which will result in:

ID: 1234

However if you take that the next step and assign it to a String you get an error that xmlList cannot be converted to String:

var id:String = flickr..photo[0].@id;

In the case of Flickr, an image is referenced by assembling a URL from XML data. In assembling the URL, the conversion from XMLList to String raises an error and no URL can be created:

var url:String = "http://static.flickr.com/" + flickr..photo[0].@server;

The above will error when the implicit cast to a String occurs. A review of the XMLList object shows no way to obtain the simple String value. How then does one assemble actual String objects from XML data using E4X?

The trick is to use the toString() method on the XMLList object when requiring the String representation of the data.

Retrieved from "http://labs.adobe.com/wiki/index.php/Talk:ActionScript_3:resources:apis:E4X:overview"