pass a number value to a Timer, XML and AS3
I want to pass a number value to a Timer. How do I do this? My number and integer values for other variables work fine.
Error
I get null object reference and coercion of value, because I'm not passing to 'timer' properly. I don't want to say my variable's a number, I want to say it has a number value.Variable
//what I have now
var timer:Timer;
timer = new Timer(100);
Path
myXML.COUNT.text();
XML
<?xml version="1.0" encoding="utf-8"?>
<SESSION>
<TIMER TITLE="speed">100</TIMER>
</SESSION>
Parse and Load
//LOAD XML
var myXML:XML;
var myLoader:URLLoader = new URLLoader();
myLoader.load(new URLRequest("time.开发者_JAVA技巧xml"));
myLoader.addEventListener(Event.COMPLETE, processXML);
//PARSE XML
function processXML(e:Event):void {
myXML = new XML(e.target.data);
Working Variables if I had a value called 'COUNT' in my XML
var count:int = 0;//give it a value type
count = myXML.COUNT.text();//tell it what value to receive
Based on your XML above you can turn your value into a number like so:
var speed:Number = Number( myXML.TIMER.text() );
Now if you want to use that number to change the timer duration you can either do it like so:
var speed:Number = Number( myXML.TIMER.text() );
timer = new Timer( speed );
or you can do it after the timer was already created:
var speed:Number = Number( myXML.TIMER.text() );
timer.delay = speed;
精彩评论