01-10-2005, 01:25 PM
|
#1
|
|
Registered User
Join Date: Oct 2003
Location: UK
Posts: 110
|
Incrementing problem?
I'm working on an XML driven photo gallery. I have a number of icons which need to correspond to the relevant thumbnail image so when the user clicks on the icon the relevant thumbnail is displayed. The problem i have is to do with incrementing I think.
Heres the code:
Code:
for (var i = 0; i<picCount; i++) {
thumbImage = mySection.childNodes[i].attributes.thumbURL;
jpegImage = mySection.childNodes[i].attributes.jpegURL;
tnHolder = _root.tnLoader.attachMovie("thumb_container", "tc"+i+"_mc", i);
tnHolder.loadMovie(thumbImage);
tnHolder._x = i*75;
tnIcon = _root.testHolder.attachMovie("tn_icon", "tnIcon"+i+"_mc", i);
tnIcon._y = i*35;
///// THE PROBLEM IS WTH THE FOLLOWING BIT /////
tnIcon.onPress = function() {
trace(tnIcon);}
}
At the moment all tnIcons trace the same value when clicked, I need them to trace the corresponding value.
tnIcon 1 - traces Icon1
tnIcon 2 - traces Icon2
tnIcon 3 - traces Icon3
Any help much appreciated.
Cheers
|
|
|
01-10-2005, 01:54 PM
|
#2
|
|
Super Moderator
Join Date: Jan 2002
Location: Centreville, VA
Posts: 26,666
|
Howdy and Welcome...
You could try to assign another variable and use that one instead...
ActionScript Code:
for (var i = 0; i < picCount; i++)
{
thumbImage = mySection.childNodes[i].attributes.thumbURL;
jpegImage = mySection.childNodes[i].attributes.jpegURL;
tnHolder = _root.tnLoader.attachMovie("thumb_container", "tc" + i + "_mc", i);
tnHolder.loadMovie(thumbImage);
tnHolder._x = i * 75;
tnIcon = _root.testHolder.attachMovie("tn_icon", "tnIcon" + i + "_mc", i);
[B]tnIcon.num = i;[/B]
tnIcon._y = i * 35;
///// THE PROBLEM IS WTH THE FOLLOWING BIT /////
tnIcon.onPress = function()
{
trace([B]this.num[/B]);
};
}
|
|
|
01-10-2005, 03:08 PM
|
#3
|
|
Registered User
Join Date: Oct 2003
Location: UK
Posts: 110
|
Thanks for that CyanBlue, it works fine. Im having a little trouble applying this to my project though.
Code:
tnIcon.num = i;
tnIcon._y = i*35;
tnIcon.onRollOver = function() {
trace(this.num);
testOver.loadMovie(thumbImage);
};
Any ideas how i can get the corresponding thumbnail to appear when I roll over the icon.
Much appreciated
|
|
|
01-10-2005, 03:15 PM
|
#4
|
|
Super Moderator
Join Date: Jan 2002
Location: Centreville, VA
Posts: 26,666
|
What about this???
ActionScript Code:
for (var i = 0; i < picCount; i++)
{
jpegImage = mySection.childNodes[i].attributes.jpegURL;
tnHolder = _root.tnLoader.attachMovie("thumb_container", "tc" + i + "_mc", i);
tnHolder.loadMovie(thumbImage);
tnHolder._x = i * 75;
tnIcon = _root.testHolder.attachMovie("tn_icon", "tnIcon" + i + "_mc", i);
tnIcon.num = i;
tnIcon.thumbImage = mySection.childNodes[i].attributes.thumbURL;
tnIcon._y = i * 35;
///// THE PROBLEM IS WTH THE FOLLOWING BIT /////
tnIcon.onRollOver = function() {
trace(this.num);
testOver.loadMovie(this.thumbImage);
};
}
|
|
|
01-10-2005, 09:24 PM
|
#5
|
|
Registered User
Join Date: Oct 2003
Location: UK
Posts: 110
|
Thank you for your time and help CyanBlue that works great, I just shifted a few things around. I've got a new problem now, I don't think the preloader is working. As it stands I am loading the thumbnails into a MC which has a preloader behaviour attached. I think this would work fine with one file but as there are multiple files its causing problems. I think I need some kind of sequential preloader.
In simple terms I want to preload the thumbnails 'behind the scenes' to be accessed instantly by the rollovers.
ActionScript Code:
var gallery_xml = new XML();
gallery_xml.ignoreWhite = true;
gallery_xml.load("photo.xml");
gallery_xml.onLoad = function(success) {
if (success) {
var mySection = gallery_xml.firstChild.childNodes[2];
var picCount = mySection.childNodes.length;
for (var i = 0; i<picCount; i++) {
//create icons
tnIcon = _root.testHolder.attachMovie("tn_icon", "tnIcon"+i+"_mc", i);
tnIcon.thumbImage = mySection.childNodes[i].attributes.thumbURL;
//Preload thumbnails into tnHolder MC
tnHolder = _root.tnLoader.attachMovie("thumb_container", "tc"+i+"_mc", i);
tnHolder.loadMovie(tnIcon.thumbImage);
//Space icons
tnIcon._y = i*35;
//icon rollover > show thumbnail
tnIcon.onRollOver = function() {
testOver.loadMovie(this.thumbImage);
}
}
} else {
trace("Error loading XML file");
}
}
Cheers
|
|
|
01-10-2005, 09:37 PM
|
#7
|
|
Registered User
Join Date: Oct 2003
Location: UK
Posts: 110
|
Thanks I'll have a look.
|
|
|
01-10-2005, 11:26 PM
|
#8
|
|
Registered User
Join Date: Oct 2003
Location: UK
Posts: 110
|
Cheers for the links
Luckily I had a play with Senocular's 'load consecutive jpgs' a while back so i didn't find it too daunting.
I've got my thumbnails preloading in sequence and I have my icons (buttons) loading in too.
What i need to do now is give the icons a rollover function to show the relevant thumbnail, what is the best way to do this? Show/Hide the relevant thumbnail, change depth ie. bring the relevant thumbnail to the top??
Any thoughts appreciated.
|
|
|
01-11-2005, 11:06 AM
|
#9
|
|
Super Moderator
Join Date: Jan 2002
Location: Centreville, VA
Posts: 26,666
|
Quote:
|
I've got my thumbnails preloading in sequence and I have my icons (buttons) loading in too.
|
I'd probably load the thumbnails into the 1000x1000 location which is an off stage area, and change the _x/_y of the thumbnail to display it whenever you roll over the icon... Just a thought...
|
|
|
01-11-2005, 12:14 PM
|
#10
|
|
Registered User
Join Date: Oct 2003
Location: UK
Posts: 110
|
That sounds like a good plan! cheers
After implementing the sequencial preloader with my thumbnails and icons I'm now back to my original problem - associating the rollover icons with the thumbnail MCs. I'm not sure how to go about this as the code has changed a bit, it now uses arrays.
|
|
|
| Thread Tools |
|
|
| Display Modes |
Rate This Thread |
Linear Mode
|
|
Posting Rules
|
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is Off
|
|
|
All times are GMT. The time now is 03:29 PM.
///
|
|