[FLASH] Setting your flash headers/swfs to play only once an hour

PIN

Sources: httphttps://www.laflash.org/forum/archive/index.php/t-2521.html
Author: David Stiller

Setting your flash headers/swfs to play only once an hour



I’m popping this code into my hybrid flash/html pages in order to stop my flash header animations from playing every time someone visits the page or any other pages with the same swf. which can be very irritating to site visitors after a while, plus distract from the main content. It plays the anim and then maintains state for an hour (starting at the time the swf was first viewed), upon which it’ll play the anim/action again. Make sure the function is invoked on the second frame and/or after the preloader.

I didn’t write the original code (lazy mario) but i have tweaked it out quite a bit and added comments for “easy” modding.

Just thought it might be useful to people doing this kind of work.

[CODE]

//sets the header animation to play only once every hour.
//dependent on the users computer time.
//placed on a frame after initial preloader

Now = new Date();

//to set the anim to pay only once per minute add Now.getMinutes()
//in front of the getHours method
//to play only once per day remove the getHours method
//note – getMonth starts on zero for January, minutes are 0-59,
//getYear is getFullYear method minus 1900, thus 2001 is 101
headerTimeSet = Now.getHours() + “/” + Now.getDate() + “/” + Now.getMonth() + “/” + Now.getYear();
headerCookie = SharedObject.getLocal(“HourTime”);

//demos if the object is working – create corresponding text fields
//this.savedDate_txt.text = headerCookie.data.headerTimeSet;

if(headerCookie.data.headerTimeSet == headerTimeSet) {
this.content_mc.anim_mc.gotoAndStop(“end_lbl”); //action taken based on cookie
} else {
this.content_mc.anim_mc.play(); //default action
}

headerCookie.data.headerTimeSet = headerTimeSet;
headerCookie.flush();

//demos if the object is working – create corresponding text fields
//this.dater_txt.text = headerTimeSet;
‘;’ type=’text/javascript’>

Leave Your Comment