Click to See Complete Forum and Search --> : Trying to get two scripts to work on same page


Scribe
05-01-2003, 12:40 PM
I've been trying to get two instances of the same javascript to work on the same page. The script is a slideshow which displays a series of images.

I want to have each script display a different a set of images.

I've been able to get both working simultaneously but they are both displaying the same array. Eventually, they both reach for the same file and the scripts both hang.

I've tried naming the arrays differently within each script but it hasn't solved the problem.

The scripts are copied below. Any suggestions are gratefully appreciated. (Of course, it might not even be possible to do this but I figured I'd yell for help before I gave up.)

The page is at:
http://www.bobwallcontracting.com/sperber.htm

The main part of the script is below. There is also an onload command in the <body> tag and names attached to the <td> tag and <img> tags.

<SCRIPT LANGUAGE="JavaScript">

<!-- Begin slideshow
// Set slideShowSpeed (milliseconds)
var slideShowSpeed = 5000;
// Duration of crossfade (seconds)
var crossFadeDuration = 3;
// Specify the image files
var Pic = new Array();
// to add more images, just continue
// the pattern, adding to the array below

Pic[0] = 'photos/sperber/exteriorSM.jpg'
Pic[1] = 'photos/sperber/entrance2SM.jpg'
Pic[2] = 'photos/sperber/doorSM.jpg'
Pic[3] = 'photos/sperber/upper_landingSM.jpg'
Pic[4] = 'photos/sperber/bedroom4SM.jpg'

// do not edit anything below this line
var t;
var j = 0;
var p = Pic.length;
var preLoad = new Array();
for (i = 0; i < p; i++) {
preLoad[i] = new Image();
preLoad[i].src = Pic[i];
}
function runSlideShow() {
if (document.all) {
document.images.SlideShow.style.filter="blendTrans(duration=2)";
document.images.SlideShow.style.filter="blendTrans(duration=crossFadeDuration)";
document.images.SlideShow.filters.blendTrans.Apply();
}
document.images.SlideShow.src = preLoad[j].src;
if (document.all) {
document.images.SlideShow.filters.blendTrans.Play();
}
j = j + 1;
if (j > (p - 1)) j = 0;
t = setTimeout('runSlideShow()', slideShowSpeed);
}
// End -->
</script>

<SCRIPT LANGUAGE="JavaScript">

<!-- Begin slideshow2
// Set slideShowSpeed (milliseconds)
var slideShowSpeed = 5000;
// Duration of crossfade (seconds)
var crossFadeDuration = 3;
// Specify the image files
var Pic = new Array2();
// to add more images, just continue
// the pattern, adding to the array below

Pic[20] = 'photos/sperber/dock2SM.jpg'
Pic[21] = 'photos/sperber/dock3SM.jpg'
Pic[22] = 'photos/sperber/dock6SM.jpg'
Pic[23] = 'photos/sperber/exterior2SM.jpg'
Pic[24] = 'photos/sperber/baywindowsSM.jpg'

// do not edit anything below this line
var t;
var j = 20;
var p = Pic.length;
var preLoad = new Array2();
for (i = 20; i < p; i++) {
preLoad[i] = new Image();
preLoad[i].src = Pic[i];
}
function runSlideShow2() {
if (document.all) {
document.images.SlideShow2.style.filter="blendTrans(duration=2)";
document.images.SlideShow2.style.filter="blendTrans(duration=crossFadeDuration)";
document.images.SlideShow2.filters.blendTrans.Apply();
}
document.images.SlideShow2.src = preLoad[j].src;
if (document.all) {
document.images.SlideShow2.filters.blendTrans.Play();
}
j = j + 1;
if (j > (p - 1)) j = 20;
t = setTimeout('runSlideShow2()', slideShowSpeed);
}
// End -->
</script>

gil davis
05-01-2003, 01:38 PM
Originally posted by Scribe
var Pic = new Array2();
This is invalid syntax. There is no such thing as an Array2. It should have generated errors. It probably also wipes out the original Pic array that you established in the first script.

Scribe
05-01-2003, 01:52 PM
Thank you for your response.

Problem is ... it doesn't wipe out the first array or crash
the program.

I had renamed the array as a last resort to try and differentiate the two arrays.

Is there another way I should have done that?

The problem I have is that both versions of the script are running but they are pulling the images in the first array. I want the first script to pull the images from the first array and the second script to pull the images from the second array.

Any thoughts?

Keep well,
Scribe

Justin
05-01-2003, 03:05 PM
they don't have the same varibules.that is a comin error

khalidali63
05-01-2003, 03:11 PM
I am not sure how does your rest of the code looks,but here is the first glance errors

var Pic = new Array2();
there is noobject in JavaScript named Array2()
change this to
new Array()
I think you have to change it at multiple instances in your code