Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How can I open a different flash banner on every visit to my site?

Status
Not open for further replies.

jamiebettles

Technical User
Dec 15, 2005
23
DE
Hello

I'm a java novice and I have a problem that hopefully somebody can help me with...
I have a website and have a flash movie banner that runs along the top. I have now designed several flash movies and want to rotate which one appears when the site is opened...ie. every time someone visits the site, a different movie appears at the top..and i've got 4 movies to rotate.
Any suggestions or further questions are very much welcome :) ,

thanks,

jamie
 
Do you want it to be different per person (in which case you'd either need to use cookies, or track IP addresses), or per hit? (regardless of person)?

Personally, I think you're far better off just serving one randomly - it's a whole lot less hassle, and unless you're really that worried about the possibility of someone seeing the same banner twice in a row, you should be set.

To serve one randomly, if you have server-side scripting available to you, I'd go that route. If not, then you could do it with JavaScript, yes.

Hope this helps,
Dan



[tt]Dan's Page [blue]@[/blue] Code Couch
[/tt]
 
Hi dan,

Cheers...yeah serving one up randomly is the way forward then if its gonna save me a lot of hassle. Ive got no experience with javascript at all, I've just made the flash movies and ive now got to get them to appear on the company website instead of the one lonely movie that currently appears every time. Ive made the site pages with html in GoLive and i know how to apply javascript to the pages, i just dont know what to write!
If you could give me some idea of the javascript i need to write or where i could find it, that would be awesome, thanks a lot,

jamie
 
This is not as simple to do using javascript as it would be using something like php, asp or jsp. Having said that, here is something I cooked up earlier:

This code goes into the body...
Code:
<script type="text/javascript">
	var swfArray = new Array;
	swfArray[swfArray.length] = 'flashmovie_1.swf';
	swfArray[swfArray.length] = 'flashmovie_2.swf';
	swfArray[swfArray.length] = 'flashmovie_3.swf';
	swfArray[swfArray.length] = 'flashmovie_4.swf';
	var randSWF = swfArray[Math.floor(Math.random()*swfArray.length)];
</script>
<object classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" codebase="[URL unfurl="true"]http://download.macromedia.com/pub/shockwave/[/URL] cabs/flash/swflash.cab#version=6,0,40,0" width="468" height="60" id="mymoviename">
[b]<script type="text/javascript">document.write('<param name="movie" value="'+randSWF+'" />');</script>[/b]
	<param name="quality" value="high" />
	<param name="bgcolor" value="#ffffff" />
	[b]<script type="text/javascript">document.write('<embed src="'+randSWF+'" quality="high" width="468" height="60" name="mymoviename" type="application/x-shockwave-flash" pluginspage="[URL unfurl="true"]http://www.macromedia.com/go/getflashplayer"></embed>');</script>[/URL][/b]
</object>
The bold lines are where javascript is writing dynamic content to the page as it loads.

Some of the specifics will vary for you, no doubt... but the idea is the same. Please follow up on Dan's suggestion of a server-side solution... it'll be so easy [smile]

Cheers,
Jeff

[tt]Jeff's Page @ Code Couch
[/tt]

What is Javascript? FAQ216-6094
 
Whoa, thanks a lot jeff, thats brilliant!

I will definitely follow up on the server side option, dan, ive read up a bit on it and it would be a lot easier and will probably make my life easier in the future when i come to edit the pages. However, my boss has 'ultimate control' over the website (im just the worker monkey who makes the content for the site!) so i will ask him about using server side scripting on our server.
Until then (the boss is on holiday now) i'll use the javascript you gave me jeff...changing the variables to match my movies.
Thanks a lot for the help, really really appreciated guys :)

jamie
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top