Forum Moderators: open
for (i=0; i<numimages; i++) {
this.picHolder = this.firstChild.childNodes[i];
this.thumbHolder = image_tn.createEmptyMovieClip("thumbnail"+i, i);
this.thumbHolder._y = i*spacing;
this.picNo = Number(i);
this.thumbLoader = this.thumbHolder.createEmptyMovieClip("thumbnail_image", 0);
this.thumbLoader.loadMovie(this.picHolder.attributes.tn);
this.thumbHolder.onRelease = function() {
ssp.loadImageNumber(picNo);
}
};
I don't think you need to know that much about SlideShowPro to answer this question, just need to know how I can get the loop numbers in place of picNo (eg. ssp.loadImageNumber(1, 2, 3, etc...));
Any help would be great. Thanks!
However, assuming the concept is right, picNo must be declared elsewhere as a global variable. You should assign to that in the loop rather than this.picNo. Also, i is already a number, there is no need to use a typecast for this assignment.
Kaled.
What this script does is create thumbnails from an XML file that lists the image locations, and aligns the thumbnails vertically next to the main image. When you click on a thumbnail the main image changes. (It's basically feeding a program called SlideShowPro the info via the ssp.loadImageNumber(picNo); command.)
Everything works fine, except the link. As long as I can get the picNo assigned a number it will work great.
Thanks a lot for your help!
I still have doubts about the concept of assigning an event handler this way - it doesn't make any sense to me. But what I've suggested might work.
Kaled.
<script type="text/javascript" src="yahoo.js"></script>
<script type="text/javascript" src="event.js"></script>
<script type="text/javascript">
for (i=0; i<numimages; i++) {
this.picHolder = this.firstChild.childNodes[i];
this.thumbHolder = image_tn.createEmptyMovieClip("thumbnail"+i, i);
this.thumbHolder._y = i*spacing;
this.thumbLoader = this.thumbHolder.createEmptyMovieClip("thumbnail_image", 0);
this.thumbLoader.loadMovie(this.picHolder.attributes.tn);
YAHOO.util.Event.addListener( this.thumbHolder, "release", function(){ssp.loadImageNumber(i);} );
}
</script>
I *think* that would work for you.
Hope that helps.
Daniel Brockman wrote a pretty good article on it [brockman.se...]
I'm guessing you would just need to add this js to enable binding in your script:
/* binding */
Function.prototype.bindEventListener = function (object) {
var method = this;var preappliedArguments = withoutFirst(arguments);
return function (event) {return method.apply(object, cons(event ¦¦ window.event, preappliedArguments));};
}
Function.prototype.bind = function(object){
var method = this;var preappliedArguments = withoutFirst(arguments);
return function(){return method.apply(object,concat(preappliedArguments,arguments));};
}
function concat(){
var result = [];for (var i=0;i<arguments.length;i++)for (var j=0;j<arguments[i].length;j++)result.push(arguments[i][j]);
return result;
}
function withoutFirst(sequence){
result = [];for (var i=1;i<sequence.length;i++)result.push(sequence[i]);
return result;
}
function cons(element, sequence) {
return concat([element], sequence);
}
/* /binding */
you should then be able to replace this:
this.thumbHolder.onRelease = function() {
ssp.loadImageNumber(picNo);
}
with this:
this.thumbHolder.onrelease = ssp.loadImage.bind(this,picNo);
and magically picNo should be associated with the thumbHolder object that fired the event.
if you can get the yahoo utils to work, i'd recommend that method as it has a number of other nice features build into it.
So the first thumbnail image will have this as its onrelease function:
ssp.loadImageNumber(0);
And the second thumbnail will have this as its onrelease function:
ssp.loadImageNumber(1);
If you bind the variable, or pass the variable like this:
ssp.loadImageNumber(picNo);
Then the links for all of the thumbnails are effectively the same. Whatever the value of picNo (if it exists) happens to be will apply to every thumbnail.
Also since the function is being fired by a link, doing this code:
ssp.loadImageNumber(this.picNo);
will not work - because when it fires, this will evaluate to the link itself, which does not have a picNo property.
Thanks a lot for everyone's help. Here's the code that finally worked:
myPhoto = new XML();
myPhoto.ignoreWhite = true;
myPhoto.onLoad = function(success) {
//portfolioTag = this.firstChild;
numimages = this.firstChild.childNodes.length;
spacing = 40;
for (i=0; i<numimages; i++) {
this.picHolder = this.firstChild.childNodes[i];
this.thumbHolder = image_tn.createEmptyMovieClip("thumbnail"+i, i);
this.thumbHolder._y = i*spacing;
this.thumbHolder.picNo=i;
this.thumbLoader = this.thumbHolder.createEmptyMovieClip("thumbnail_image", 0);
this.thumbLoader.loadMovie(this.picHolder.attributes.tn);
this.thumbHolder.onRelease = function() {
ssp.loadImageNumber(this.picNo);
}
};
};
myPhoto.load("xmlphoto.xml");
Here's the code that creates the thumbnails
myPhoto = new XML();
myPhoto.ignoreWhite = true;
myPhoto.onLoad = function(success) {
//portfolioTag = this.firstChild;
numimages = this.firstChild.childNodes.length;
spacing = 40;
for (i=0; i<numimages; i++) {
this.picHolder = this.firstChild.childNodes[i];
this.thumbHolder = image_tn.createEmptyMovieClip("thumbnail"+i, i);
this.thumbHolder._y = i*spacing;
this.thumbHolder.picNo=i;
this.thumbLoader = this.thumbHolder.createEmptyMovieClip("thumbnail_image", 0);
this.thumbLoader.loadMovie(this.picHolder.attributes.tn);
this.thumbHolder.onRelease = function() {
ssp.loadImageNumber(this.picNo);
}
};
};
myPhoto.load("xmlphoto.xml");
And here's the XML file
<?xml version="1.0" encoding="UTF-8"?>
<gallery>
<img src="images/Villa_Penasco1.jpg" tn="thumbnails/Villa_Penasco1.jpg"/>
<img src="images/Villa_Penasco7.jpg" tn="thumbnails/Villa_Penasco7.jpg"/>
<img src="images/Villa_Penasco3.jpg" tn="thumbnails/Villa_Penasco3.jpg"/>
<img src="images/Villa_Penasco4.jpg" tn="thumbnails/Villa_Penasco4.jpg"/>
<img src="images/Villa_Penasco5.jpg" tn="thumbnails/Villa_Penasco5.jpg"/>
<img src="images/Villa_Penasco6.jpg" tn="thumbnails/Villa_Penasco6.jpg"/>
<img src="images/Villa_Penasco7.jpg" tn="thumbnails/Villa_Penasco7.jpg"/>
<img src="images/Villa_Penasco8.jpg" tn="thumbnails/Villa_Penasco8.jpg"/>
<img src="images/Villa_Penasco9.jpg" tn="thumbnails/Villa_Penasco9.jpg"/>
<img src="images/Villa_Penasco10.jpg" tn="thumbnails/Villa_Penasco10.jpg"/>
<img src="images/Villa_Penasco11.jpg" tn="thumbnails/Villa_Penasco11.jpg"/>
<img src="images/Villa_Penasco12.jpg" tn="thumbnails/Villa_Penasco12.jpg"/>
<img src="images/Villa_Penasco13.jpg" tn="thumbnails/Villa_Penasco13.jpg"/>
<img src="images/Villa_Penasco14.jpg" tn="thumbnails/Villa_Penasco14.jpg"/>
</gallery>
Now I want to add a dynamic title field so I have a title for the "album."
If I change the XML file to this
<?xml version="1.0" encoding="UTF-8"?>
<gallery>
<album title="Villa Penasco">
<img src="images/Villa_Penasco1.jpg" tn="thumbnails/Villa_Penasco1.jpg"/>
<img src="images/Villa_Penasco7.jpg" tn="thumbnails/Villa_Penasco7.jpg"/>
<img src="images/Villa_Penasco3.jpg" tn="thumbnails/Villa_Penasco3.jpg"/>
<img src="images/Villa_Penasco4.jpg" tn="thumbnails/Villa_Penasco4.jpg"/>
<img src="images/Villa_Penasco5.jpg" tn="thumbnails/Villa_Penasco5.jpg"/>
<img src="images/Villa_Penasco6.jpg" tn="thumbnails/Villa_Penasco6.jpg"/>
<img src="images/Villa_Penasco7.jpg" tn="thumbnails/Villa_Penasco7.jpg"/>
<img src="images/Villa_Penasco8.jpg" tn="thumbnails/Villa_Penasco8.jpg"/>
<img src="images/Villa_Penasco9.jpg" tn="thumbnails/Villa_Penasco9.jpg"/>
<img src="images/Villa_Penasco10.jpg" tn="thumbnails/Villa_Penasco10.jpg"/>
<img src="images/Villa_Penasco11.jpg" tn="thumbnails/Villa_Penasco11.jpg"/>
<img src="images/Villa_Penasco12.jpg" tn="thumbnails/Villa_Penasco12.jpg"/>
<img src="images/Villa_Penasco13.jpg" tn="thumbnails/Villa_Penasco13.jpg"/>
<img src="images/Villa_Penasco14.jpg" tn="thumbnails/Villa_Penasco14.jpg"/>
</album>
</gallery>
The javascript mistakes the <album title="Villa Penasco"> for an image, and doesn't show any of the thumbnails.
Question: How can I get the javascript loop to skip <album title="Villa Penasco"> but read the rest of the images? I think it has something to do with which childNode it starts at, correct?
Any help will be deeply appreciated!
myPhoto = new XML();
myPhoto.ignoreWhite = true;
myPhoto.onLoad = function(success) {
//portfolioTag = this.firstChild;
numimages = this.firstChild.childNodes[0].childNodes.length;
spacing = 40;
for (i=0; i<numimages; i++) {
this.picHolder = this.firstChild.childNodes[0].childNodes[i];
this.thumbHolder = image_tn.createEmptyMovieClip("thumbnail"+i, i);
this.thumbHolder._y = i*spacing;
this.thumbHolder.picNo=i;
this.thumbLoader = this.thumbHolder.createEmptyMovieClip("thumbnail_image", 0);
this.thumbLoader.loadMovie(this.picHolder.attributes.tn);
this.thumbHolder.onRelease = function() {
ssp.loadImageNumber(this.picNo);
}
};
};
myPhoto.load("xmlphoto.xml");
numgalleries = this.childNodes.length;
this.galleryHolder = this.childNodes;
for (g=0; g<numgalleries; g++) {
numalbums = this.childNodes[g].childNodes.length;
this.galleryHolder[g].albumHolder = this.childNodes[g].childNodes;
for (a=0; a<numalbums; a++) {
numimages = this.childNodes[g].childNodes[a].length;
this.galleryHolder[g].albumHolder[a] = this.childNodes[g].childNodes[a].childNodes;
for (i=0; i<numimages; i++) {
this.galleryHolder[g].albumHolder[a] = this.childNodes[g].childNodes[a].childNodes[i]picHolder = this.childNodes[g].childNodes[a].childNodes[i];
}//end images
}//end albums
}//end galleries
This allows you to support an XML file that contains galleries of albums of images.
- JS