How do I insert XML data into an ArrayCollection
in AS3?
views:
101answers:
2
A:
If possible use an XMLListCollection. Assuming you have some XML like
var xml:XML =
<doc>
<node/>
<node/>
<node/>
</doc>
You can create an XMLListCollection of nodes like so:
var xmllist:XMLListCollection = new XMLListCollection(xml.node);
If you really need an ArrayCollection you have to iterate over each item in xmllist and add it to your ArrayCollection. There is no build in API to do this for you.
Josh Knauer
2010-04-13 16:48:09
A:
There is several options to convert XML data to Array. But i choose to use this one.
At first to create xmlNode instance of XML class.
var xml:XML =
<doc>
<node/>
<node/>
<node/>
</doc>
public var xmlNode:XML;
public function init():void
{
var myPanel:Panel = new Panel();
var myTree:Tree = new Tree();
myTree.dataProvider = xml;
myTree.addEventListner(Event.CHANGE,onChange);
this.addChilt(myPanel);
myPanel.AddChild(myTree);
trace(xmlNode);
}
public function onChange(e:Event):void
{
xmlNode = Tree(e.target).selectedItem as XML;
}
Vadim Slutsky
2010-04-21 18:59:44