PDA

View Full Version : Incrementing problem?


betamax
01-10-2005, 01:25 PM
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:
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

CyanBlue
01-10-2005, 01:54 PM
Howdy and Welcome... :)

You could try to assign another variable and use that one instead...

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.num = i;
tnIcon._y = i * 35;
///// THE PROBLEM IS WTH THE FOLLOWING BIT /////
tnIcon.onPress = function()
{
trace(this.num);
};
}

betamax
01-10-2005, 03:08 PM
Thanks for that CyanBlue, it works fine. Im having a little trouble applying this to my project though.
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

CyanBlue
01-10-2005, 03:15 PM
What about this???

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);
};
}

betamax
01-10-2005, 09:24 PM
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.

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

CyanBlue
01-10-2005, 09:25 PM
Well... I don't know, but you could try this thread to get more information...

http://www.actionscript.org/forums/showthread.php3?t=59554

betamax
01-10-2005, 09:37 PM
Thanks I'll have a look.

betamax
01-10-2005, 11:26 PM
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.

CyanBlue
01-11-2005, 11:06 AM
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... ;)

betamax
01-11-2005, 12:14 PM
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. :confused:

CyanBlue
01-11-2005, 01:58 PM
Well... Post the changed code then... ;)

betamax
01-11-2005, 02:16 PM
I was hoping you would say that :)
I think I need to post the whole script, sorry its a bit long.
count = 0;
var thumbImage = new Array();
var thumbClip = new Array();
var jpegImage = new Array();
//Thumbnail preloader
function ThumbLoadingEnterFrame() {
var lod = this.loader_mc.getBytesLoaded();
var tot = this.loader_mc.getBytesTotal();
if (lod && tot) {
var percent_loaded = lod/tot;
this.progress_mc._xscale = 100*percent_loaded;
if (percent_loaded == 1) {
LoadNextThumb();
delete this.onEnterFrame;
}
}
}
//Load next thumbnail
function LoadNextThumb() {
if (count<thumbImage.length) {
var imgURL = thumbImage[count];
thumbClip[count].loader_mc.loadMovie(imgURL);
thumbClip[count].onEnterFrame = ThumbLoadingEnterFrame;
count++;
}
}
var gallery_xml = new XML();
gallery_xml.ignoreWhite = true;
gallery_xml.load("test.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++) {
//Populate Arrays
thumbImage.push(mySection.childNodes[i].attributes.thumbURL);
jpegImage.push(mySection.childNodes[i].attributes.jpegURL);
//create thumb holder MC
tnHolder = _root.attachMovie("thumb_container", "tc"+i+"_mc", i);
//tnIcon = tnIcon.tnHolder;
thumbClip.push(tnHolder);
//Loader bar
tnHolder.progress_mc._xscale = 0;
tnHolder._x = i*75;
//create thumbnail icon
tnIcon.num = i;
tnIcon = _root.attachMovie("tn_icon", "icon"+i+"_mc", i+100);
tnIcon._y = 100+i*25;
tnIcon.onRollOver = function() {
trace(this.tnHolder);
this.tnHolder._x = 400;
};
}
LoadNextThumb();
} else {
trace("Error loading XML file");
}
};
Cheers

CyanBlue
01-11-2005, 02:27 PM
Uh... I am not following what you are trying to do with this line...
trace(this.tnHolder);

betamax
01-11-2005, 02:32 PM
Hmm sorry, I think thats a bit of old stuff. I'm was wanting to trace the relevant thumbnail MC. That is the bit I'm having the problem with.

CyanBlue
01-11-2005, 02:34 PM
Uh... You could try this...
tnIcon.tnHolder = _root.attachMovie("thumb_container", "tc"+i+"_mc", i);
so that you can say this.tnHolder...

betamax
01-11-2005, 02:47 PM
Aye thanks for that,

I had already tried that though, it solves the problem in question but then messes up the preloader and the images don't load in. I'm guessing its because the paths have changed. tnHolder is pushed into the array thumbclip to be accessed by the preloader functions so adding tnIcon effects this.

Thanks again CyanBlue for your time and help, you've been really helpful and its much appreciated.

CyanBlue
01-11-2005, 02:50 PM
Well... If you could post the sample file that I can play with, I'll take a look at it over the lunch break... ;)

betamax
01-11-2005, 03:02 PM
Thanks!!
here is the file.

CyanBlue
01-11-2005, 03:22 PM
Um... I am not still sure where you are going with that '400' deal, but this should get you going abit further...

gallery_xml.onLoad = function(success) {
if (success) {
//change [number] to access different sections
var mySection = gallery_xml.firstChild.childNodes[2];
var picCount = mySection.childNodes.length;
trace("picCount = " + picCount);
for (var i = 0; i< picCount; i++) {
//Populate Arrays
thumbImage.push(mySection.childNodes[i].attributes.thumbURL);
jpegImage.push(mySection.childNodes[i].attributes.jpegURL);
//create thumb holder MC
tnHolder = _root.attachMovie("thumb_container", "tc"+i+"_mc", i + 1);
tnIcon.tnHolder = "tc"+i+"_mc";
//tnIcon = tnIcon.tnHolder;
thumbClip.push(tnHolder);
//Loader bar
tnHolder.progress_mc._xscale = 0;
tnHolder._x = i*75;
//create thumbnail icon
tnIcon = _root.attachMovie("tn_icon", "icon"+i+"_mc", i+100);
tnIcon.num = i;
trace("tnIcon.num = " + tnIcon.num + " i = " + i);
tnIcon._y = 100+i*25;
tnIcon.onRollOver = function() {
tmb = this._parent["tc" + this.num + "_mc"];
trace(tmb);
tmb._x = 400;
};
}
LoadNextThumb();
} else {
trace("Error loading XML file");
}
};