# Display Random swf after a certain amount of days

**URL:** <https://forum.kirupa.com/t/display-random-swf-after-a-certain-amount-of-days/33490>\
**Category:** flash\
**Created:** [October 20, 2003, 7:51am UTC](https://forum.kirupa.com/t/display-random-swf-after-a-certain-amount-of-days/33490 "2003-10-20T07:51:16Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![skaiwayne2](https://avatars.discourse-cdn.com/v4/letter/s/ad7895/32.png) [@skaiwayne2](https://forum.kirupa.com/u/skaiwayne2)\
**Post date:** [October 20, 2003, 7:51am UTC](https://forum.kirupa.com/t/display-random-swf-after-a-certain-amount-of-days/33490/1 "2003-10-20T07:51:16Z")

</div>

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?

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [October 20, 2003, 11:17am UTC](https://forum.kirupa.com/t/display-random-swf-after-a-certain-amount-of-days/33490/2 "2003-10-20T11:17:51Z")

</div>

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…).

```auto
//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

```

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [October 20, 2003, 11:22am UTC](https://forum.kirupa.com/t/display-random-swf-after-a-certain-amount-of-days/33490/3 "2003-10-20T11:22:34Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [October 20, 2003, 1:10pm UTC](https://forum.kirupa.com/t/display-random-swf-after-a-certain-amount-of-days/33490/4 "2003-10-20T13:10:46Z")

</div>

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
