Flash 共享对象刷新帮助
在我的网站上,我有一个 Flash 横幅,当用户更改页面时,它会保存其框架位置,以便它继续播放,而不是在用户每次浏览网站时重新启动。这是使用共享对象实现的。它的效果很好,除了一件事:饼干的保存时间太长了。即使当我当天晚些时候回到该网站时,它仍然会重新加载我的最后一个位置。我想在用户离开域名时刷新共享对象,但我不确定如何实现它。有人可以帮忙吗!
好的,谢谢您的回复,拉尔斯。这就是我得到的结果:
var mySharedObject:SharedObject = SharedObject.getLocal("displayCookie");
var expiredate = mySharedObject.data.expires;
var timeobject = new Date();
var timestamp = timeobject.getTime();
if (expiredate<=timestamp && expiredate != null) {
for (var i in mySharedObject.data) {
delete mySharedObject.data[i];
}
mySharedObject.flush();
} else if (expiredate == null) {
var oneday = 100;
var expiresIn = 1;
var expiretimestamp = timestamp+expiresIn*oneday;
mySharedObject.data.expires = expiretimestamp;
mySharedObject.flush();
}
if (mySharedObject.data.introcheck != 0) {
mySharedObject.data.introcheck = 0;
mySharedObject.flush();
gotoAndPlay(1);
} else {
addEventListener(Event.ENTER_FRAME, checkLoadedFrames);
function checkLoadedFrames(e:Event):void {
if(this.framesLoaded == this.totalFrames) {
removeEventListener(Event.ENTER_FRAME, checkLoadedFrames);
checkSharedObject();
}
}
function checkSharedObject():void {
if(mySharedObject.data.currentFrame){
gotoAndPlay(mySharedObject.data.currentFrame);
}
addEventListener(Event.ENTER_FRAME, saveCurrentFrame);
}
function saveCurrentFrame(e:Event):void {
mySharedObject.data.currentFrame = this.currentFrame;
}
}
我将 oneday var 更改为 100ms 以检查它是否有效,但它不起作用。我做错了什么?
On my site I have a flash banner that saves its frame position when the user changes pages so that it continues to play rather than restart every time a user navigates around the site. This was implemented using sharedobject. It works great except for one thing: the cookie lasts too long. Even when I come back to the site later on in the day it still reloads my last position. I want to flush the sharedobject when the user navigates away from the domain name but I'm unsure how to implement it. Could someone help please!
Ok thanks for your response Lars. Here's what I got:
var mySharedObject:SharedObject = SharedObject.getLocal("displayCookie");
var expiredate = mySharedObject.data.expires;
var timeobject = new Date();
var timestamp = timeobject.getTime();
if (expiredate<=timestamp && expiredate != null) {
for (var i in mySharedObject.data) {
delete mySharedObject.data[i];
}
mySharedObject.flush();
} else if (expiredate == null) {
var oneday = 100;
var expiresIn = 1;
var expiretimestamp = timestamp+expiresIn*oneday;
mySharedObject.data.expires = expiretimestamp;
mySharedObject.flush();
}
if (mySharedObject.data.introcheck != 0) {
mySharedObject.data.introcheck = 0;
mySharedObject.flush();
gotoAndPlay(1);
} else {
addEventListener(Event.ENTER_FRAME, checkLoadedFrames);
function checkLoadedFrames(e:Event):void {
if(this.framesLoaded == this.totalFrames) {
removeEventListener(Event.ENTER_FRAME, checkLoadedFrames);
checkSharedObject();
}
}
function checkSharedObject():void {
if(mySharedObject.data.currentFrame){
gotoAndPlay(mySharedObject.data.currentFrame);
}
addEventListener(Event.ENTER_FRAME, saveCurrentFrame);
}
function saveCurrentFrame(e:Event):void {
mySharedObject.data.currentFrame = this.currentFrame;
}
}
I changed the oneday var to 100ms to check if it works but it doesn't. What am I doing wrong?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
SharedObject 不是 cookie,它永远不会过期。
假设这个问题与上一个问题< /a>,我想您可以从 SharedObject 切换到浏览器 cookie(具有过期机制),并使用 ExternalInterface,或者您可以在 SharedObject 上保存时间戳,如果它太旧,则忽略它/重置它。
编辑:
我认为这可行,基本上删除代码的一些 if/else 逻辑,而是始终执行以下步骤:
已到期。
下一次运行。
mySharedObject.data.currentFrame 的
(如果 SharedObject 被重置
第 1 步,就像第一个
跑步)。
-
A SharedObject is not a cookie, it never expires.
Assuming this question is about the same case as this previous question, I guess you could either switch from a SharedObject to a browser cookie (that has mechanisms for expiring), and read/write to it using ExternalInterface, or you could save a timestamp on the SharedObject, and ignore it/reset it if it is too old.
Edit:
I think this could work, basically removing some of the if/else logic of your code and instead always do these steps:
expired.
the next run.
of mySharedObject.data.currentFrame
(if the SharedObject was reset in
step 1, it will be like a first
run).
-