Have Your Banners Update Themselves: The AS2 Date Detector
I do a lot of banner ads for video games. These banner ads very often run both pre-launch (before the game is released) and post-launch (after the game is released). The trick is the banners need to include a release date before the game is released (e.g. “Available November 18th”) and then a different message AFTER the game is released (e.g. “Available Now!”). You don’t want to have to build a completely different set of banners with a new message on them, so what do you do? Add a date detector.
All you need to do is build a movie clip with at least two frames, one which holds all the art for the “pre-launch” message and one which holds all the art for the “post-launch” message. Then you have a simple script which takes the cutoff date, checks it against the current date, and if it’s after launch, go to the “post-launch” frame. Here’s the script that I use:
// Remember months start from 0 (january=0, feb=1, etc.)
var launchDate:Date = new Date(2008,10,18);
function checkDate()
{
// Check to see if this after the launch date
var thisDate:Date = new Date();
if (thisDate >= launchDate)
{
gotoAndStop("launch");
}
}
checkDate();
It’s as easy as that! The only trick is to remember that in Flash, months start at 0. So November is number 10, instead of 11 (seems simple but it’s funny how ingrained month numbers are in ones mind!).
Here’s an example FLA which shows how the code above functions: dateSelector.zip
