views:

101

answers:

2

How do I insert XML data into an ArrayCollection in AS3?

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
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