Flashvars 在页面重新加载时停止 Flash 影片重新加载

发布于 2024-11-07 17:40:05 字数 631 浏览 5 评论 0原文

我网站的每个页面上都有一个 Flash 横幅。我希望它在用户更改页面时继续播放而不是重新加载。我读到这可以使用 flashvars 来实现,但是,我已经有一段时间没有进行任何动作脚本了。我尝试查找教程但无济于事。有人可以指出我正确的方向吗?

已更新

感谢您的评论。我现在在 fla 文件的第 1 帧上有这个:

var mySharedObject:SharedObject = SharedObject.getLocal("displayCookie");
if(mySharedObject.data.displayed == true){
gotoAndPlay(currentFrame); 
    trace("cookie found");
}else{
    trace("cookie not found, setting it now");
    //do whatever if NOT already been played
    mySharedObject.data.displayed = true;
    mySharedObject.flush();
}

但我不知道如何为 currentFrame 提供刷新页面时的值。我怎样把它放在那里?

对不起我的菜鸟

I have a flash banner on every page in my site. I want it to continue playing rather than reloading when users change pages. Ive read that this can be achieved using flashvars, however, its been quite some time since I did any actionscripting. I've tried looking up tutorials to no avail. Can someone point me in the right direction please.

UPDATED

Thanks for your comments. I have this on frame 1 of my fla file now:

var mySharedObject:SharedObject = SharedObject.getLocal("displayCookie");
if(mySharedObject.data.displayed == true){
gotoAndPlay(currentFrame); 
    trace("cookie found");
}else{
    trace("cookie not found, setting it now");
    //do whatever if NOT already been played
    mySharedObject.data.displayed = true;
    mySharedObject.flush();
}

But I don't know how to give the currentFrame the value it had at the time the page was refreshed. How do I put that in there?

Sorry for my noobness

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

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

发布评论

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

评论(2

你怎么敢 2024-11-14 17:40:05

在 SharedObject 代码的基础上,您可以执行以下操作:

在第 1 帧上:

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

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;
}

Building on your SharedObject code, you could do something like this:

On frame 1:

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

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;
}
拥抱没勇气 2024-11-14 17:40:05

它可能比仅使用 FlashVars 稍微复杂一些。当用户导航到下一页时,您还需要使用一些外部接口来获取横幅的当前框架。 (注意:我使用的是 jQuery 和 swfobject)

首先,javascript 类似于:

var flashObj;

$(document).ready(function() {
     if (navigator.appName.indexOf("Microsoft") != -1) {
          flashObj = window["flash"];
     } else {
          flashObj = document["flash"];
     }
});

function embedPlayer() {
     var flashvars = {};
     if (swfobject.getQueryParamValue("frame")) {
          flashvars.bannerframe = swfobject.getQueryParamValue("frame");
     } else {
          flashvars.bannerframe = 1;
     }
     var params = {};
     var attributes = {};
     swfobject.embedSWF("swf/Main.swf", "flash", "800", "600", "10.0.0", "swf/expressInstall.swf", flashvars, params, attributes);
}

function getBannerFrame() {
     return flashObj.checkCurrentFrame();
}

然后,在第 1 帧上的 FLA 中,您将拥有:

var frame:Number = Number(root.loaderInfo.parameters.bannerframe);
if (!isNaN(frame)) {
     gotoAndPlay(frame);
}

ExternalInterface.addCallback("checkCurrentFrame", checkCurrentFrame);

function checkCurrentFrame():int {
     return this.currentFrame;
}

现在,任何时候您导航到另一个页面,您只需添加当前帧即可使用 checkCurrentFrame(); 到查询字符串;

It'll probably be a little more complicated than just using FlashVars. You'll also need to use a little ExternalInterface to get the current frame of the banner once the user navigates to the next page. (Note: I'm using jQuery and swfobject)

First, the javascript would be something like:

var flashObj;

$(document).ready(function() {
     if (navigator.appName.indexOf("Microsoft") != -1) {
          flashObj = window["flash"];
     } else {
          flashObj = document["flash"];
     }
});

function embedPlayer() {
     var flashvars = {};
     if (swfobject.getQueryParamValue("frame")) {
          flashvars.bannerframe = swfobject.getQueryParamValue("frame");
     } else {
          flashvars.bannerframe = 1;
     }
     var params = {};
     var attributes = {};
     swfobject.embedSWF("swf/Main.swf", "flash", "800", "600", "10.0.0", "swf/expressInstall.swf", flashvars, params, attributes);
}

function getBannerFrame() {
     return flashObj.checkCurrentFrame();
}

Then, in your FLA on frame 1, you would have:

var frame:Number = Number(root.loaderInfo.parameters.bannerframe);
if (!isNaN(frame)) {
     gotoAndPlay(frame);
}

ExternalInterface.addCallback("checkCurrentFrame", checkCurrentFrame);

function checkCurrentFrame():int {
     return this.currentFrame;
}

Now, any time you navigate to another page, you just tack on the current frame to the query string using checkCurrentFrame();

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