开发者

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;   
}
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜