【问题标题】:how can I access the elements of this xml in Actionscript 3?如何在 Actionscript 3 中访问此 xml 的元素?
【发布时间】:2010-08-22 15:31:02
【问题描述】:

我在繁琐的 AS2 中使用 xml 没有问题,但显然在 AS£ 中更容易,但是我在从这篇文章中获取数据时遇到了问题。

基本上我需要能够访问 id 和 src。任何帮助表示赞赏 谢谢

【问题讨论】:

  • 可能忘记了什么?

标签: actionscript-3 actionscript


【解决方案1】:

检查 XML 类并查看页面底部的示例: http://www.adobe.com/livedocs/flash/9.0/ActionScriptLangRefV3/

【讨论】:

    【解决方案2】:

    ActionScript 3 内置了 e4x - 示例:

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

    您可以在 Google 上搜索“as3 e4x”...很多人都编写了示例代码。

    【讨论】:

      【解决方案3】:

      在 ActionScript 3 中,您有几种不同的选择来遍历和操作 XML,但我强烈建议使用 E4X。

      开始学习 E4X 的最佳地点无疑是本教程:Kirupa.com - Using XML in Flash CS3/AS3

      如果您有此示例 XML:

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

      然后要从“item”节点获取 id,您可以执行以下操作:

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

      【讨论】:

        猜你喜欢
        • 2016-11-20
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2015-12-29
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多