Search code examples
flashrefreshreloadflashvarsbanner

Flashvars to stop flash movie reloading on page reload


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


Solution

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