【问题标题】:Flash sharedobject flush helpFlash 共享对象刷新帮助
【发布时间】:2011-05-21 17:01:27
【问题描述】:

在我的网站上,我有一个 Flash 横幅,当用户更改页面时它会保存其框架位置,以便在用户每次浏览网站时继续播放而不是重新启动。这是使用共享对象实现的。它很好用,除了一件事:cookie 持续时间太长。即使当天晚些时候我回到该网站,它仍然会重新加载我的最后一个位置。当用户离开域名时,我想刷新共享对象,但我不确定如何实现它。有人可以帮忙吗!

好的,感谢您的回复拉斯。这是我得到的:

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 以检查它是否有效,但它没有。我做错了什么?

【问题讨论】:

    标签: flash flush shared-objects


    【解决方案1】:

    SharedObject 不是 cookie,它永不过期。

    假设这个问题与this previous question 的情况大致相同,我想您可以从 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;
    }
    

    【讨论】:

    • 谢谢拉尔斯。我不想让你觉得我在滥用你的技能来谋取私利,而没有学到任何东西。我只是有很多事情要做,没有很多空闲时间。除了这个问题,我真的不需要知道动作脚本,所以试图为这件事学习所有内容很烦人。我在上面添加了一些代码,这对我来说似乎很有意义,但它不起作用。有什么想法吗?
    猜你喜欢
    • 2012-08-05
    • 2014-10-27
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2010-10-18
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多