我正在尝试设置计时器功能,因此XML中的数据会每5秒刷新一次闪存?使用从互联网上找到的一些exaples并不像它缓存XML文件那样工作。
这是我的代码:
var xmlData:XML = new XML();
var theURL_ur:URLRequest = new URLRequest("data.xml");
var loader_ul:URLLoader = new URLLoader(theURL_ur);
loader_ul.addEventListener("complete", fileLoaded);
function fileLoaded(e:Event):void
{
xmlData = XML(loader_ul.data);
line1.text = xmlData.line1;
time1.text = xmlData.time1;
}
答案 0 :(得分:1)
让它工作(早上从晚上好起来)。这是代码:
var my_xml_loader:URLLoader;
var timerRefreshRate:Number = 5000;
var fatherTime:Timer = new Timer(timerRefreshRate, 0);
fatherTime.addEventListener(TimerEvent.TIMER, processXML);
fatherTime.start();
processXML();
function processXML(event:Event = null):void{
my_xml_loader = new URLLoader();
var cacheBuster:String = "?"+(new Date()).time.toString();
my_xml_loader.load(new URLRequest("your_url"+cacheBuster))
my_xml_loader.addEventListener(Event.COMPLETE, loadvars);
}
function loadvars (e:Event = null):void{
var my_xml:XML = new XML(e.target.data);
line1.text = my_xml.line1;
time1.text = my_xml.time1;
}