我想将外部XML传递给变量。我该怎么做?
我之后是什么
- 使用COUNT XML更新我的变量
我没有得到什么
- 整数到字符串值
- 如何将XML传递给变量
time.xml
<?xml version="1.0" encoding="utf-8"?>
<SESSION>
<COUNT TITLE="starting position">-77777</COUNT>
</SESSION>
xml.fla
//VARIABLES
/*CHANGE TO COUNT
MyString or count, I don't know if it was necessary to go from int to String
*/
var myString:String = "";
var count:int = int(myString);
trace(count);
//LOAD XML
var myXML:XML;
var myLoader:URLLoader = new URLLoader();
myLoader.load(new URLRequest("time.xml"));
myLoader.addEventListener(Event.COMPLETE, processXML);
//PARSE XML
function processXML(e:Event):void {
myXML = new XML(e.target.data);
trace(myXML.COUNT.*);
trace(myXML);
//TEXT
var text:TextField = new TextField();
text.text = myXML.COUNT.*;
addChild(text);
}
输出窗口'正确追踪到输出窗口'
//zero should read -77777 if tracing correctly
0
-77777
<SESSION>
<COUNT TITLE="starting position">-77777</COUNT>
</SESSION>
错误
我尝试的任何东西都有强制错误和空引用。
答案 0 :(得分:0)
您要问的内容有点模糊,但这里是如何将XML中的数据作为字符串或整数提取的:
//VARIABLES
var myString:String = "";
var count:int = 0;
//LOAD XML
var myXML:XML;
var myLoader:URLLoader = new URLLoader();
myLoader.load(new URLRequest("time.xml"));
myLoader.addEventListener(Event.COMPLETE, processXML);
//PARSE XML
function processXML(e:Event):void {
myXML = new XML(e.target.data);
trace(myXML.COUNT.text()); //-77777
//grab the data as a string
myString = myXML.COUNT.text();
//grab the data as an int
count = int(myXML.COUNT.text());
trace("String: ", myString);
trace("Int: ", count);
trace(count - 1); //just to show you that it's a number that you can do math with (-77778)
//TEXT
var text:TextField = new TextField();
text.text = myString;
addChild(text);
}