Im using several swf files on one page and instead of displaying a random swf on refresh or the next visit I want to display a swf for a certain number of days also I want to be able to choose what swfs will show up more depending on some sort of priority setting. Has anyone pulled this off or has any code to show?
Well, you can use the getDay method to check the day of the week (it returns 0 for sunday, 1 for monday, 2 for tuesday…).
//array containing 7 swfs, one for each day of the week
swfArray = ["sun.swf", "mon.swf", "tue.swf", "wed.swf", "thu.swf", "fri.swf", "sat.swf"];
day = new Date().getDay();
container_mc.loadMovie(swfArray[day]);//if you are loading into an empty movie clip
loadMovieNum(swfArray[day], 1000);//if you are loading into level
I can think of several ways to do this.
The simplest is probably to calculate which movie should be show based on what date it is.
You could calculate how many days has passed since January 1st 2003. Then if you want your movie to change every 3 days, you divide the number by 3.
Then you use the number to select which movie to show. You could have the movie names in an array and use the number as an index (after massaging it so it won’t go out of bounds).
You can scatter multiple entries of the same movie through your array if you want to show a special movie more than others.
Another option could be to make a server-side script that selects the current movie and passes the name along as a parameter.
All this assumes that you want the movie to be the same on any given day for all your visitors.
Hope that helps.
Cheers,
Hans
I’ve whipped together a bit of code for you:
[AS]
favorite = “favorite.swf”;
movies = new Array(“movie1.swf”, “movie2.swf”, “movie3.swf”);
now = new Date();
days = Date.UTC(now.getYear() + 1900, now.getMonth(), now.getDate()) / (1000 * 60 * 60 * 24);
index = days / 3; // <- no. of days between change
if ((index % 2) == 0) { // <- every other movie chosen should be my favorite
play = favorite;
} else {
play = movies[index % movies.length];
}
trace(play);
[/AS]
Cheers,
Hans