Xml 如何在AS3中访问根目录?

Xml 如何在AS3中访问根目录?,xml,flash,actionscript-3,Xml,Flash,Actionscript 3,因此,在花了几个小时试图找出我的代码没有编译的原因后,我发现这段代码与AS3不兼容: function loadXML(loaded) { if (loaded) { _root.inventor = this.firstChild.childNodes[0].childNodes[0].firstChild.nodeValue; _root.comments = this.firstChild.childNodes[0].childNodes[1].firstChild.nodeValue;

因此,在花了几个小时试图找出我的代码没有编译的原因后,我发现这段代码与AS3不兼容:

function loadXML(loaded) {
if (loaded) {
_root.inventor = this.firstChild.childNodes[0].childNodes[0].firstChild.nodeValue;
_root.comments = this.firstChild.childNodes[0].childNodes[1].firstChild.nodeValue;
name_txt.text = _root.inventor;
comment_txt.text = _root.comments;
} else {
  trace("file not loaded!");
}
}

xmlData = new XML();
xmlData.ignoreWhite = true;
xmlData.onLoad = loadXML;
xmlData.load("http://localhost/connect.php");

有人知道如何在AS3中访问根目录吗?谢谢

如果你指的是电影的根
Sprite
MovieClip
(文档类),你可以在舞台上使用任何
DisplayObject
的属性
root

以下是我最后做的:

var myXML:XML = new XML();
var XML_URL:String = "http://localhost/connect.php";
var myXMLURL:URLRequest = new URLRequest(XML_URL);
var myLoader:URLLoader = new URLLoader(myXMLURL);
myLoader.addEventListener("complete", xmlLoaded);

function xmlLoaded(event:Event):void
{
    var finalXML:XML = XML(myLoader.data);
    //trace(finalXML);
    trace("Data loaded.");
    //trace(finalXML.triviaQuestion[0].answer1[0]);
    //questionBox.text = (finalXML.triviaQuestion[0].question[0]).toString();
}
使用
MovieClip(root)
而不仅仅是
\u root
,它可以工作
像这样:

function loadXML(loaded){
 if (loaded) {
  MovieClip(root).inventor = this.firstChild.childNodes[0].childNodes[0].firstChild.nodeValue;
  MovieClip(root).comments = this.firstChild.childNodes[0].childNodes[1].firstChild.nodeValue;
  name_txt.text = MovieClip(root).inventor;
  comment_txt.text = MovieClip(root).comments;
 } else {
  trace("file not loaded!");
 }
}

xmlData = new XML();
xmlData.ignoreWhite = true;
xmlData.onLoad = loadXML;
xmlData.load("http://localhost/connect.php");

我可能错了,但他们没有删除AS3中的根变量吗?如果我知道,我就不会问了:)你知道我是如何访问XML树的吗?这段代码是100%AS2(不仅仅是根部分),谢谢你的提醒…取得了一些进展。在使用E4X时发现了一些东西,我认为它可能会起作用,但为了弄清楚如何让它做我想做的事情,还有很多废话要看。()那么你是说这是你自己问题的答案还是说这是一个更新?如果这是一个更新,你应该把它添加到你的问题中,可能在[update]标签下面,然后删除这个答案。这看起来不错。最好避免在AS3中使用root作为存储数据的位置,因为它违反了OOP原则。