XML to ArrayCollections
How 开发者_如何学运维do I insert XML data into an ArrayCollection
in AS3?
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.
There are several options to convert XML data to Array, but I choose to use this one.
First 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;
}
精彩评论