I want to pass external XML a variable. How do I do this?
WHAT I'M AFTER
- update my variable with COUNT XMLWHAT I'M NOT GETTING
- The integer to String values - How to pass XML to a variablelink http://videodnd.weebly.com/
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);
}
output window 'traces to the output window correctly'
//zero should read -77777 if tracing correctly
0
-77777
<SESSION>
<COUNT TITLE="starting position">-77777</COUNT>
</SESSION>
errors
coercion errors and null references with anything I attempt.A little fuzzy on what you're asking, but here is how you can pull the data from the XML as either a String or integer:
//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);
}
精彩评论