在我的应用程序上有一个按钮,用于加载位于服务器上的XML文件。 XML文件包含31条信息,每天根据日期编号发送一条。用户触摸按钮重新加载信息,因此每天都会更改。
这是我坚持的事情。当应用程序从后台恢复并触摸按钮时,它将不会提取新的一天的信息;它继续显示昨天的信息。如果我强制该应用程序退出(在手机上),然后再次启动它,它将正确加载新的一天的信息。
我的问题 - 如何在每次按键触摸时强制重新加载?
感谢您的协助。这是我的ActionScript 3代码。
2012年10月12日更新:我在几个24小时的时间段内对此进行了测试,发现它在Flash 5.5模拟器中每天都无法正确更新。所以问题可能不在手机上。我会对代码做更多的工作并回报,希望有一些改进。
// Main 'Today!' button function
var myDateDay:Date = new Date();
var dayNumber:int = myDateDay.day;
myButton.addEventListener(MouseEvent.CLICK, fl_MouseClickHandler);
function fl_MouseClickHandler(event:MouseEvent):void {
// Opens previously saved text file to read XML URL
var file:File = File.applicationStorageDirectory;
file = file.resolvePath("qstURL.txt");
var fileStream:FileStream = new FileStream();
fileStream.open(file, FileMode.READ);
var QSTURL:String = fileStream.readUTFBytes(fileStream.bytesAvailable);
trace("QST URL:" + " " + QSTURL);
fileStream.close();
// Load, process main XML file
var qst:XML;
var qstLoader:URLLoader = new URLLoader();
qstLoader.load(new URLRequest(QSTURL));
qstLoader.addEventListener(Event.COMPLETE, processQST);
function processQST(e:Event):void {
qst = new XML(e.target.data);
isProcessed();
}
//Wait until the XML is finished being processed
function isProcessed():void{
trace("QST is processed and ready for use");
//Clear welcome message before adding new content
if(contains(textWelcomeMessage)){
removeChild(textWelcomeMessage);
removeChild(imageNoAudio);
removeChild(textProductKeyMessage);
trace("Welcome items removed");
}
else{
trace("textWelcomeMessage not onStage");
}
//Text Section
// Text field formating
var myTextFormat1:TextFormat = new TextFormat();
myTextFormat1.align = TextFormatAlign.LEFT;
myTextFormat1.size = 20;
myTextFormat1.font = "Verdana";
myTextFormat1.color = "0x333333";
myTextFormat1.bold = true;
var myTextFormat2:TextFormat = new TextFormat();
myTextFormat2.align = TextFormatAlign.LEFT;
myTextFormat2.size = 30;
myTextFormat2.font = "Verdana";
myTextFormat2.color = "0x333333";
// Text field to display title
var title:XMLList = qst.title;
var myText1:TextField = new TextField();
myText1.text = title;
myText1.autoSize = TextFieldAutoSize.NONE;
myText1.border = false;
myText1.width = 315;
myText1.multiline = false;
myText1.wordWrap = false;
myText1.y = 125;
myText1.x = 5;
myText1.setTextFormat(myTextFormat1);
// Text field to display question of the day
var question:XMLList = qst.question.(@day == dayNumber).text;
var myText2:TextField = new TextField();
myText2.text = question;
myText2.autoSize = TextFieldAutoSize.CENTER;
myText2.border = false;
myText2.width = stage.stageWidth - 60;
myText2.multiline = true;
myText2.wordWrap = true;
myText2.y = 180;
myText2.x = 30;
myText2.setTextFormat(myTextFormat2);
// Text field to display clearing statement
var cs:XMLList = qst.clearingStatement;
var myText3:TextField = new TextField();
myText3.text = cs;
myText3.autoSize = TextFieldAutoSize.CENTER;
myText3.border = false;
myText3.width = stage.stageWidth - 60;
myText3.multiline = true;
myText3.wordWrap = true;
myText3.y = myText2.y + myText2.height + 10;
myText3.x = 30;
myText3.setTextFormat(myTextFormat2);
//Remove existing text field to stop overlaying when button touched repeatdly
while (numChildren > 3) removeChildAt(3);
/Add text to stage
addChild(myText1);
addChild(myText2);
addChild(myText3);
other code ....
}//Close function "isProcessed" - load & process main XML file
} //Close function fl_MouseClickHandler - 'Today!' button
答案 0 :(得分:0)
我认为操作系统正在缓存您的xml文件。
如果是这种情况,请尝试在网址末尾添加随机字符串。类似的东西:
url + "?v=" + Math.ceil(Math.random()*10000)
答案 1 :(得分:0)
我终于发现了这个,发现了一个保存日期的变量,超出了主按钮的范围。因此,当单击按钮时,要重新加载所有内容,它不会重新加载日期并更新此变量。因此,日期编号未更新,此用于检索每天的信息。
它如何变得更好?