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.displa开发者_StackOverflowyed == 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
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;
}
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();
精彩评论