I am trying to get a slideshow to run on my page which draws from several groups (categories) of images which are included in the slideshow if a particular checkbox (one for each category) on the page is checked. I successfully coded this with two categories, but am trying to make the code more easily customizable. I had the brilliant idea to use custom objects instead of arrays. I figure this approach would probably also get me closer to my final goal of using an xml document in the process.
I am fairly new to object oriented programming, especially with javascript. I have successfully created a declaration of objects for use in a slideshow page with the following code:
function picsobj(description,length,indivpicarray){
this.description=description;
this.length=length;
this.indivpicarray=indivpicarray;
}
and elsewhere the following code to make an array of picsobj objects
for(i=0;i<2;i++){ //change i< integer to number of picture arrays
picarrays[i]=new picsobj();}
the plan is to use the description property for captions or to describe elements on the page, to use the length property to help determine how many pictures to cycle through, and to use (here’s where my question comes…) the object property called indivpicarray to store an ARRAY of image names (the length of the array would change from picsobj to picsobj). I do not know if this is possible, and if it is I need help with the syntax please. Thank you for reading my question. again, sorry if there are any misused words i’m a bit of a n00b and have pretty much learned through “view source, copy, paste, alter”
This is perfectly fine. The technique of objects having properties that are arrays is quite common. Arrays are treated just like any other variable. Just add this to your constructor:
see here if you’re not sure what a constructor is