AS3重置UrlLoader缓存 [英] AS3 Resetting UrlLoader Cache
问题描述
美好的一天,
我在Actionscript 3中遇到了UrlLoader缓存的问题. 我向php网站发出UrlRequest以获得时间戳.
I’ve encountered problems with the cache of the UrlLoader in Actionscript 3. I make a UrlRequest to a php site to get a timestamp.
当我第二次调用初始化类(包含函数)时,结果是相同的. 我必须关闭该应用程序并重新启动它才能获得新的请求.
When I call initiate the class (which contains the function) a second time, the result is the same. I have to close the application and restart it to get a new request.
我尝试过"loader = new loader".并使用标题.
I have tried "loader = new loader." and also using headers.
为每个请求创建唯一URL的选项 like here ,对我不起作用,因为它会破坏我的php操作..
The option of creating a unique URL for every request like here , does not work for me since it would sabotage my php action..
loader = new URLLoader();
var request:URLRequest = new URLRequest("http://www.mySite.com/getTime.php?action=getTime");
loader.load(request);
推荐答案
向请求中添加随机参数不会以任何方式破坏您的php:
Adding a random parameter to your request will not sabotage your php in any way:
loader = new URLLoader();
var request:URLRequest =
new URLRequest(
"http://www.mySite.com/getTime.php?action=getTime&bogus="+(Math.random() * 10000));
loader.load(request);
您的php代码将获取action
参数,并且将忽略bogus
参数,而对您的代码没有任何影响.
Your php code will GET the action
parameter, and will ignore the bogus
parameter without any effect on your code.
您还可以使用基于时间的随机数来避免太不幸,并且两次获得相同的值.
You can also use a time based random number to avoid being too unlucky and get the same value twice.
这篇关于AS3重置UrlLoader缓存的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!