Closed Thread Icon

Topic awaiting preservation: multiple ad image arrays on one page (Page 1 of 1) Pages that link to <a href="https://ozoneasylum.com/backlink?for=27410" title="Pages that link to Topic awaiting preservation: multiple ad image arrays on one page (Page 1 of 1)" rel="nofollow" >Topic awaiting preservation: multiple ad image arrays on one page <span class="small">(Page 1 of 1)</span>\

 
sward
Nervous Wreck (II) Inmate

From: North Carolina
Insane since: Jan 2006

posted posted 01-29-2006 23:37

Hey all just found this site and was hoping someone could answer what I'd think would be an easy task. I have one rotating script on my page for rotating pictures but I want to have two more running. I have my JavaScript in another folder for SEO reasons and want to keep it that way. I thought if I just named the scripts different I.e. " imagearray.js" is the first rotate script and "imagearray2.js" is the second .
Then name them differently Name="adBanner" for the first and Name="adBanner2" for the second that it would work but when I do that only the second one works. What am I doing wrong? Can it be done or does the last script cancel the previous?
thanks sward

Mountain land

Blue Ridge Mountain Real Estate

Tyberius Prime
Maniac (V) Mad Scientist with Finglongers

From: Germany
Insane since: Sep 2001

posted posted 01-30-2006 08:47

depends on the script... you might have to change the script to actually use the other adbanner place.

Unfortunatly, I can't say much without having a look at the script.

TwoD
Bipolar (III) Inmate

From: Sweden
Insane since: Aug 2004

posted posted 01-30-2006 12:58

All global variables in imagearray.js will be replaced by imagearray2.js if it is included last.
You will most likely have to rename each global variable in one of the scripts to be able to use them both.
But a smoother way to fix it is to rely on OOP. Basically use a constructor function to generate an object containing
all variables and methods needed by the image rotator. Then simply create two instances of that object, each with it's own list of images to rotate etc.

/TwoD

sward
Nervous Wreck (II) Inmate

From: North Carolina
Insane since: Jan 2006

posted posted 01-30-2006 14:44

Hey TwoD could you put that in English please?

the script i used is simple Here is the first named imagearray.js

code:
<!--
adImages = new Array("photos/118964asm.jpg" ,"photos/118964bsm.jpg" ,"photos/118964csm.jpg" , "photos/118964dsm.jpg", "photos/118964esm.jpg" , "photos/118964fsm.jpg" , "photos/118964gsm.jpg" )
thisAd = 0
imgCt = adImages.length 

function rotate() {
if (document.images) {
thisAd++
if (thisAd == imgCt) {
thisAd = 0
}
document.adBanner.src=
	adImages[thisAd]
	setTimeout("rotate()", 3 * 1000)
	}
}
//-->



and the second only changes the images named imagearray2.js Here

code:
<!--
adImages = new Array("photos/111014asm.jpg" ,"photos/111014bsm.jpg" ,"photos/111014csm.jpg" , "photos/111014dsm.jpg" )
thisAd = 0
imgCt = adImages.length 

function rotate() {
if (document.images) {
thisAd++
if (thisAd == imgCt) {
thisAd = 0
}
document.adBanner2.src=
	adImages[thisAd]
	setTimeout("rotate()", 3 * 1000)
	}
}
//-->



They are two diffrent scripts named in the head for each off page.

code:
<script language="JavaScript" Src="scripts/imagearray.js" TYPE="text/javascript"></script>


code:
<script language="JavaScript" Src="scripts/imagearray2.js" TYPE="text/javascript"></script>



and of coursed called up where i want the images like this

code:
<img src="photos/118964asm.jpg" alt="creek front cabin" width="150" height="97" border="4" Name="adBanner"></a>



code:
<img src="photos/111014asm.jpg" alt="floatplane hanger " width="150" height="94" border="4" Name="adBanner2" >



So with that said is one canceling out the other? If so where can i find some info on what you are saying TwoD ?
thanks sward

Mountain land

Blue Ridge Mountain Real Estate

bitdamaged
Maniac (V) Mad Scientist

From: 100101010011 <-- right about here
Insane since: Mar 2000

posted posted 01-30-2006 15:20

you need to rename the functions something like rotate and rotate2 and also change the call in the timeout.



.:[ Never resist a perfect moment ]:.

Tyberius Prime
Maniac (V) Mad Scientist with Finglongers

From: Germany
Insane since: Sep 2001

posted posted 01-30-2006 16:27

plus seperate the thisAds and the imgCts and the adImages... all those need a 2 at then end... but honestly this is patchwork,
and should be replaced by an object that you can simply tell what images into what spot....
let's see, give this a whirl, but you'll need to read up a lot on javascript...

code:
var addRotators = new Array();

function addRotator_Rotate()
{
  if (document.images) 
    {
        this.thisAd++;
        if (this.thisAd == this.imgCt) 
        {
            thisAd = 0;
        }         
        //alert('showing' + this.adImages[this.thisAd]);
        var els = document.getElementsByName(this.elementName)[0];
        if (els && els[0])
            els[0].src=   this.adImages[this.thisAd];
    }
}


function addAdRotator(adImages,elementName)
{
    this.adImages = adImages;
    this.elementName = elementName;
    this.thisAd = 0;
    this.imgCt = adImages.length ;
    this.rotate = addRotator_Rotate;
    addRotators.push(this);
}

function rotateAll()
{
    
   for (x in addRotators)
  {
       addRotators[x].rotate();
  }
  window.setTimeout('rotateAll()',3000);
}

addAdRotator(
    new Array("photos/111014asm.jpg" ,"photos/111014bsm.jpg" ,"photos/111014csm.jpg" , "photos/111014dsm.jpg" ),
    'adbanner');

rotateAll();



so you'll only need one photo, and one addAddRotator call per adbanner you wish to rotate.

so long,

->Tyberius Prime

sward
Nervous Wreck (II) Inmate

From: North Carolina
Insane since: Jan 2006

posted posted 01-30-2006 19:20

Okay wow! I tried to set up the code above but I'm not doing something right. prefer to "KISS" it.

I also tried adding "2's" for the rename for imagearray2.js it now looks like this

code:
<!--
adImages2 = new Array("photos/111014asm.jpg" ,"photos/111014bsm.jpg" ,"photos/111014csm.jpg" , "photos/111014dsm.jpg" )
thisAd2 = 0
imgCt2 = adImages2.length 

function rotate2() {
if (document.images) {
thisAd2++
if (thisAd2 == imgCt) {
thisAd2 = 0
}
document.adBanner2.src=
	adImages2[thisAd2]
	setTimeout("rotate2()", 3 * 1000)
	}
}
//-->




But now not sure how to do the on load did it this way:

code:
<body onLoad="rotate()" , "rotate2()">



I tried it with and without the comma. Now my first rotate is working which is great but not the second? anybody got an easy fix?
Thanks Guys you're great !

Mountain land

Blue Ridge Mountain Real Estate

bitdamaged
Maniac (V) Mad Scientist

From: 100101010011 <-- right about here
Insane since: Mar 2000

posted posted 01-30-2006 21:38
code:
<body onLoad="rotate();rotate2()">





.:[ Never resist a perfect moment ]:.

sward
Bipolar (III) Inmate

From: North Carolina
Insane since: Jan 2006

posted posted 01-31-2006 01:12

Great got that ... thanks but something's still not jiving in the code posted above I must be missing a "2" somewhere. Hate to be a pest but anybody see the problem?
Sward

Mountain land

Blue Ridge Mountain Real Estate

poi
Paranoid (IV) Inmate

From: Norway
Insane since: Jun 2002

posted posted 01-31-2006 01:41

Sorry to be a pest in my turn, but to me the problem is that somebody forgot to read the fucking manual :

DHTML/JavaScript
Javascript/DHTML
Google: multiple image rotation in javascript





(Edited by poi on 01-31-2006 01:42)

sward
Bipolar (III) Inmate

From: North Carolina
Insane since: Jan 2006

posted posted 01-31-2006 02:11

whoa! I was just trying to figure out what was wrong with my code. Didn't know I came across such an UNFRIENDLY place. Thanks to those that helped but obviously I'm not welcome here.! Don't worry I won't come back....

Mountain land

Blue Ridge Mountain Real Estate

poi
Paranoid (IV) Inmate

From: Norway
Insane since: Jun 2002

posted posted 01-31-2006 09:56

sward: You are welcome.

The thing is that usually ( or at least during the past years ) we prefer(ed) to teach people how to fish than giving them a fish. And this is exactly what we all did for the last 2 days, even me ( though in a more impatient way ). This is how unfriendly we are.

Add to that that there is a huge list Frequently Asked Questions here, including :
Hi I'm new here (at the Ozone Asylum) what do I need to know?
General advice for starting threads
Can you help me with my homework?
General advice for starting threads
I posted a question but no-one answered. Should I post it again to get people's attention?

TwoD
Bipolar (III) Inmate

From: Sweden
Insane since: Aug 2004

posted posted 02-03-2006 01:43

Whoa! This thread grew faster than I thought it would...
Anyway, what I meant is basically what TB wrote.

Poi has a good point, too few use the FAQ,s and it's better to learn by doing than to "learn" by copying and pasting...

(Edited by TwoD on 02-03-2006 01:44)

« BackwardsOnwards »

Show Forum Drop Down Menu