说我有以下的XML:
<?xml version="1.0" encoding="utf-8"?>
<language id="en" description="English">
<start>Start</start>
<instructions>some instructions</instructions>
</language>
如何调整此代码以在语言ID值之间切换?我收到错误时:错误#1069:在String上找不到属性语言且没有默认值。< / p>
private function xmlLoaded(e:Event):void {
switch (e.target.data.language.@id) {
case "en":
_en = new XML(e.target.data);
_en.ignoreWhitespace = true;
break;
case "de":
_de = new XML(e.target.data);
_de.ignoreWhitespace = true;
break;
}
}
答案 0 :(得分:2)
您必须在访问XML之前创建XML。此外,<language>
是您的根元素,因此您将找不到具有此名称的子项。
private function xmlLoaded(e:Event):void {
var xml:XML = new XML(e.target.data)
switch (xml.@id.toString()) {
case "en":
_en = xml;
_en.ignoreWhitespace = true;
break;
case "de":
_de = xml;
_de.ignoreWhitespace = true;
break;
}
}