views:

38

answers:

3

Hi, I had no problem working with xml in cumbersome AS2, but apparently it's menat to be easier in AS£, however I'm having a problem getting the data from this piece.

Basically I need to be able to access the id & src. any help appreciated Thanks

A: 

Check the XML class & have a look at the examples at the bottom of the page: http://www.adobe.com/livedocs/flash/9.0/ActionScriptLangRefV3/

PatrickS
A: 

ActionScript 3 has e4x built-in - example:

var demoXml:XML = <demo id="1" />; // you can define inline xml
var theId:int = demoXml.@id; // access attributes using '@'

You can google for 'as3 e4x' ... lots of people have written example code.

Simon Groenewolt
Cool, thank you both
Jack
if this answers your question please accept it as the answer (click the check mark)
Simon Groenewolt
A: 

In ActionScript 3 you have a few different choices for traversing and manipulating XML, but I strongly recommend using E4X.

The best place to start learning E4X is definitly this tutorial: Kirupa.com - Using XML in Flash CS3/AS3.

If you had this sample XML:

<data>
  <item id="1" src="one">
    This is item one.
  </item>
  <item id="2" src="two">
    This is item two.
  </item>
<data>

Then to get the id from an "item" node, you might do something like this:

function xmlLoadHandler(e:Event):void {
  var xmlData:XML = new XML(e.target.data);
  var items:XMLList = xmlData.item;

  for each (var item:XML in items) {
    trace(item.@id);
    trace(item.@src);
    trace(item.text());
  }
}
TandemAdam