我的计时器有三个变量,我可以追踪到输出窗口, 但不知道如何将它们传递给计时器。 如何将XML值传递给我的计时器?
目的
在尝试将其连接到XML套接字之前,我想使用XML文档进行测试。
myXML
<?xml version="1.0" encoding="utf-8"?>
<SESSION>
<TIMER TITLE="speed">100</TIMER>
<COUNT TITLE="starting position">-77777</COUNT>
<FCOUNT TITLE="ramp">1000</FCOUNT>
</SESSION>
myFlash
//COUNTER 'instance of mytext on stage'
/*
fields I want to change with XML
*/
//CHANGE TO 100
var timer:Timer = new Timer(10);
//CHANGE TO -77777
//var count:int = 0;
var myString:String = "-77777";
var count:int = int(myString);
//CHANGE TO 1000
//var fcount:int = 0;
var myStrg:String = "1000";
var fcount:int = int(myStrg);
//myXML.COUNT.text
timer.addEventListener(TimerEvent.TIMER, incrementCounter);
timer.start();
function incrementCounter(event:TimerEvent) {
count++;
fcount=int(count*count/1000);//starts out slow... then speeds up
mytext.text = formatCount(fcount);
}
function formatCount(i:int):String {
var fraction:int = i % 100;
var whole:int = i / 100;
return ("0000000" + whole).substr(-7, 7) + "." + (fraction < 10 ? "0" + fraction : fraction);
}
//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.*;
text.textColor = 0xFF0000;
addChild(text);
}
DID THIS“注释了我的var计数并做了这个
前点。
var count:int = Number(myXML.COUNT.text());
离。
var count:int = int(myXML。*。(@ TITLE =='起始位置'));
TypeError:错误#1009:无法访问空对象引用的属性或方法。 在numbersXMLtext_fla :: MainTimeline / frame1()
资源
OReilly的ActionScript 3.0 Cookbook,第12章字符串,第20章XML
答案 0 :(得分:0)
速度值:
var speed:int = int(myXML.*.(@TITLE == 'speed'));
对于起始位置值:
var startingPoint:int = int(myXML.*.(@TITLE == 'starting position'));
对于斜坡值:
var ramp:int = int(myXML.*.(@TITLE == 'ramp'));
这些代码段使用E4X来解析xml值。还应该注意,根据最终的xml看起来,这种方法可能需要相应地修改。祝你好运!