Flashvars to stop flash movie reloading on page reload

家住魔仙堡 提交于 2019-12-20 05:49:42

问题


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


回答1:


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



回答2:


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();



来源:https://stackoverflow.com/questions/5994208/flashvars-to-stop-flash-movie-reloading-on-page-reload

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!