The option to use JSON or XML with ActionScript is available. In order to use JSON you will need to include the Adobe corelib library. This library contains functionality to encode and decode JSON streams. In the example below, the pEvent object is of type Event and is supplied by the Flash runtime when the handler method is called. contains the response data stream. This stream is decoded into an Object. The sample iterates through the properties constructing an object for each name/value pair and then adds it to an ArrayCollection object.

var json:Object = JSON.decode(;
for (var propName:String in json)
 arrayCollection.addItem({name: propName, value: json[propName]});

The following sample uses XML input. Note that you could also take advantage of the ECMAScript for XML functionality once the XML object is created. The following sample does not use that approach, though it is an option.

var xml:XML = new XML(;
var xmlList:XMLList = pXML.elements();
if (xmlList.length() == 0)
 xmlList = new XMLList(pXML);
 var count:int = 0;
for each(var item:XML in xmlList) {
 if ( != "element")
 array.addItem({name:, value: item.text()});
 else if (item.hasComplexContent()) {
 var elementList:XMLList = item.child("element");
 if (elementList != null && elementList.length() > 0) {
 var count2:int = 0;
 for each (var el:XML in elementList)
 array.addItem({name: count2++, value: el.text()});
 array.addItem({name: item.key.text(), value: item.value.text()});
 array.addItem({name: count++, value: item.text()});

Copyright © 1997, 2013 Oracle and/or its affiliates. All rights reserved. Legal Notices