/    Sign up×
Community /Pin to ProfileBookmark

I have 3 small flash movies. I want to rotate them whenever a visitor refresh a page. So if you go to my website you watch the flash movie (banner) and when you go back again the next minute, hour or day, you’ll see a different movie.

I know there’s a a script to rotate swf files but I have searched for a month and can’t find one that will work!

My site is [url]http://www.braia.co.uk[/url]

You can see that banner at the top change each time you change page but that is because I have done it manually. I want to do it so it randonmly selects a swf on refresh/change page.

That way I can update the swf files alot more easily for holidays (valentines, easter, etc).

I can rename the swf files to movie1, movie2, movie3 if it makes it easier.

Please could you post a script and tell me where to place it and how to place it. I don’t even mind an external file that I can point to if it is easier to edit, but can you explain how I point to the file. I am using Dreamweaver CS.

THANK YOU!

to post a comment
JavaScript

1 Comments(s)

Copy linkTweet thisAlerts:
@nap0leonFeb 06.2008 — Where you currently have the christmas movie...

Create 3 Divs with "style="display:none;".

Each DIV has an id like "movie1", "movie2", and "movie3" and contains the code that places that movie into that DIV.

At the bottom of your page, run a javascript function (e.g., "displayNextMovie()).

The function displayNextMovie() checks a cookie value to see which movie the user saw last (e.g., "movie_value=1"). If no answer is found in the cookie, presume the user has never seen a movie and set the value to "1" and then set the display for div id="movie1" to "block". If the cookie value is "1", then set it to "2" and display div with id="movie2", similar for 3. If the cookie says "3", then set it to "1" and show them "movie1".

I'm short on time this evening so can't write out the code to accomplish the above, but hopefully this gives you a straightforward approach that is easy to follow. There are lots of code libraries available for using javascript to read/write cookies as well as lots of examples on how to change the display of a DIV.

Yes, this will cause the page to load slower b/c it is going to load all 3 movies and only 1 of them will actually be displayed. To avoid this, you'd need to either use AJAX or a server-side language to control which item goes in the DIV. (e.g., if your pages support classic ASP, you can easily read the value of the cookie and use that value to decide which content to place into the DIV. or you could use a session variable and not worry about cookies.) but those are all server-side solutions and this is a JavaScript (client-side) forum.

Here's a sample of a function I use to toggle the display of DIVs on my site.


http://www.jasondahlin.com/WebSite2/CodeSnippets/JavaScript-HideShowDivs.aspx

<i>
</i>function safeToggleFieldDisplay(field, sVisibility){
try{
if((field) &amp;&amp; (field.style)){
if (sVisibility=='flip'){
if (field.style.display == 'none'){
sVisibility = 'block'; }
else {
sVisibility = 'none'; }
}
field.style.display = sVisibility;
}
}
catch(exception){
//no handling - just preventing page explosions
}
}
×

Success!

Help @thatitalian spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.4,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,

tipper: @Samric24,
tipped: article
amount: 1000 SATS,
)...