Oct
10
2011
Converting an XMLList to an Array in AS3
Posted by: Keith H in ActionScript 3, Flex, XML, tags: xmllistToArray XMLList Array StringI wanted to create a list of Strings from only the attributes of an XMLList, and I wanted them separated with carriage returns.
The "toXMLString()" method does this automatically on attributes.
Attributes are typed as XMLList.
var myXmlList:XMLList=XMLList(<B><P name="Orange"/><P name="Grape"/><P name="Pear"/></B>).P; trace(myXmlList..@name.toXMLString()); //Outputs multiple values of all "name" attributes separated with carriage returns automatically. Orange Grape Pear
Putting the values of an XMLList as an Array might be useful also.
Being separated by carriage returns makes it easy to convert to an Array by using the String "split" method.
Wrap this into a function for easy use.
function xmllistToArray(list:XMLList):Array { return list.toXMLString().split("\n"); }
Entries (RSS)
Thanks a lot
Thanks !!!