开发者

how can I access the elements of this xml in Actionscript 3?

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 t开发者_C百科he data from this piece.

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


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/


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.


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

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜