Flash 共享对象刷新帮助

发布于 2024-11-09 01:55:10 字数 1523 浏览 0 评论 0原文

在我的网站上,我有一个 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

云归处 2024-11-16 01:55:10

SharedObject 不是 cookie,它永远不会过期。

假设这个问题与上一个问题< /a>,我想您可以从 SharedObject 切换到浏览器 cookie(具有过期机制),并使用 ExternalInterface,或者您可以在 SharedObject 上保存时间戳,如果它太旧,则忽略它/重置它。

编辑

我认为这可行,基本上删除代码的一些 if/else 逻辑,而是始终执行以下步骤:

  1. 重置/清除 SharedObject(如果有)
    已到期。
  2. 保存一个新的时间戳,用于
    下一次运行。
  3. 做原始检查
    mySharedObject.data.currentFrame 的
    (如果 SharedObject 被重置
    第 1 步,就像第一个
    跑步)。

-

var mySharedObject:SharedObject = SharedObject.getLocal("displayCookie");

var expiredate = mySharedObject.data.expires;

var timeobject = new Date();

var timestamp = timeobject.getTime();

// Reset/clear the SO if it has expired
if (expiredate != null && expiredate <= timestamp)
{
    for (var i in mySharedObject.data)
    {
        delete mySharedObject.data[i];
    }
    mySharedObject.flush();
}

// Make a new timestamp, for comparing the next run to this one

var oneday = 10000; // Test value, 10 seconds   

var expiresIn = 1;

var expiretimestamp = timestamp + expiresIn * oneday;

mySharedObject.data.expires = expiretimestamp;

mySharedObject.flush();

// Do the original check
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;
}

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:

  1. Reset/clear the SharedObject if it has
    expired.
  2. Save a new timestamp, for
    the next run.
  3. Do the original check
    of mySharedObject.data.currentFrame
    (if the SharedObject was reset in
    step 1, it will be like a first
    run).

-

var mySharedObject:SharedObject = SharedObject.getLocal("displayCookie");

var expiredate = mySharedObject.data.expires;

var timeobject = new Date();

var timestamp = timeobject.getTime();

// Reset/clear the SO if it has expired
if (expiredate != null && expiredate <= timestamp)
{
    for (var i in mySharedObject.data)
    {
        delete mySharedObject.data[i];
    }
    mySharedObject.flush();
}

// Make a new timestamp, for comparing the next run to this one

var oneday = 10000; // Test value, 10 seconds   

var expiresIn = 1;

var expiretimestamp = timestamp + expiresIn * oneday;

mySharedObject.data.expires = expiretimestamp;

mySharedObject.flush();

// Do the original check
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;
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文