Dynamically loading thumbnails

the below content was my original problem…but now i found out whats wrong! look go here [color=#22229c]http://cutshallow.com/test[/color] and go to the photos section…while your there look at the galleries…i made a test xml file with one gallery with one blank image…another gallery with three blank images and one images and then a third gallery with four blank images and one image…now take a look at what happens when you press on the third image and then the second…that one picture is still there…which means the images aren’t being deleted as they should…even though at the beginning of my functions in the code i have it unload the movies…so does anyone have any ideas as to why this is happening? and how i can fix it?


alright well i created this image gallery using xml…and well, thought it works…there are a few flaws that i can’t seem to fix…before i try to explain the problem, though, i will explain the way my gallery works…
in the library i have four exported movie clips:
imageMC(linkage id: "imageMC): a movie clip with two movie clips inside…one blank movie clip(“image”) and one movie clip with a box graphic (“box_mc”)
galleryMC(linkage id: “galleryMC”): a movie clip with 2 movie clips inside, blank movie clip(“image”) and a text button(“view”), and two dynamic text fields(“title” and “caption”);
txtButton(linkage id:txtButton): a movie clip with a dynamic text field inside(“text”)
titleCaption(linkage id:titleCaption): a movie clip with two dynamic text fields inside(“title” and “caption”)
on the stage i have two empty movie clips:
images_mc and galleries_mc
and here is my actionscript:

loadGalleries();
var galleries = [];
var images = [];
var m:Number;
function loadGalleries() {
images_mc.unloadMovie();
gXML = new XML();
gXML.ignoreWhite = true;
gXML.load("xml/photos.xml");
gXML.onLoad = function(success) {
if (success) {
parseXML(gXML);
}
function parseXML(xmlDoc) {
for (i in xmlDoc.firstChild.childNodes) {
file = xmlDoc.firstChild.childNodes*.attributes.file;
title = xmlDoc.firstChild.childNodes*.attributes.title;
caption = xmlDoc.firstChild.childNodes*.attributes.caption;
galleries* = [];
galleries* = [file, title, caption, i];
}
}
for (i in galleries) {
var k:MovieClip = galleries_mc.attachMovie("galleryMC", "gallery"+i+"_mc", galleries_mc.getNextHighestDepth(), {_y:i*70});
file = galleries*[0];
title = galleries*[1];
caption = galleries*[2];
which = galleries*[3];
k.title.htmlText = "<b><u>"+title+"</u></b>";
k.caption.text = "- "+caption;
k.image.loadMovie(file);
k.image._xscale = k.image._yscale=13;
k.which = which;
with (k) {
view.onRelease = function() {
_parent._parent.loadImages(which);
};
}
}
};
}
function loadImages(number) {
galleries_mc.unloadMovie();
iXML = new XML();
iXML.ignoreWhite = true;
iXML.load("xml/photos.xml");
iXML.onLoad = function(success) {
if (success) {
parseXML(iXML);
}
function parseXML(xmlDoc) {
for (i in xmlDoc.firstChild.childNodes[number].childNodes) {
file = xmlDoc.firstChild.childNodes[number].childNodes*.attributes.file;
title = xmlDoc.firstChild.childNodes[number].childNodes*.attributes.title;
caption = xmlDoc.firstChild.childNodes[number].childNodes*.attributes.caption;
images* = [];
images* = [file, title, caption];
}
}
c = images.length;
for (i in images) {
var p:MovieClip = images_mc.attachMovie("imageMC", "image"+i+"_mc", images_mc.getNextHighestDepth());
p._x = i*55;
if (p._x>3*55) {
p._y += 45;
p._x -= 4*55;
if (p._x>3*70) {
p._y += 45;
p._x -= 4*55;
}
if (p._x>3*70) {
p._y += 45;
p._x -= 4*55;
}
}
file = images*[0];
title = images*[1];
caption = images*[2];
p.image.loadMovie(file);
p.image._xscale = p.image._yscale=p.box_mc._xscale=p.box_mc._yscale=10;
p.url = file;
p.title = title;
p.caption = caption;
with (p) {
box_mc.onRollOver = function() {
_parent.titleCaption.title.htmlText = "<b><u>"+title+"</u></b>";
_parent.titleCaption.caption.text = "- "+caption;
};
box_mc.onRollOut = function() {
_parent.titleCaption.title.htmlText = "";
_parent.titleCaption.caption.text = "";
};
box_mc.onRelease = function() {
getURL("javascript:newWindow('"+url+"','','530','400','scrollbars=no','resize=no');");
};
}
}
var l:MovieClip = images_mc.attachMovie("titleCaption", "titleCaption", images_mc.getNextHighestDepth(), {_y:(c/4)*60, _x:130});
var t:MovieClip = images_mc.attachMovie("txtButton", "goBack", images_mc.getNextHighestDepth(), {_y:(c/4)*70+20});
t.text.text = "<< back to galleries";
t.onRelease = function() {
loadGalleries();
};
};
}

now to explain what i have happening here…there are two main functions in the movie…the first one to be called is the loadGalleries(); function…
and in that function i load the xml file “xml/photos.xml”:

<photos>
<gallery file="../photos/uploads/cssicck500.jpg" title="Awesomenessssssss" caption="we're cooler than you">
	<image file="../photos/uploads/51716042_l.jpg" title="Hawaii" caption="hawaiians are so hawaiian" />
	<image file="../photos/uploads/51801565_l.jpg" title="Wide-eyed wes" caption="what the..." />
	<image file="../photos/uploads/142391447_l.jpg" title="Mr. moves" caption="so flamboyant" />
	<image file="../photos/uploads/142391784_l.jpg" title="Rockin' danny" caption="wild and crazy is he" />
	<image file="../photos/uploads/142392907_l.jpg" title="Cut Shallow on tour" caption="not anymore" />
	<image file="../photos/uploads/142394266_l.jpg" title="The whole gang" caption="the only good one of nate...and you can still barely see him" />
	<image file="../photos/uploads/csmyspace.jpg" title="Good day sir..." caption="I SAID GOOD DAY!!" />
	<image file="../photos/uploads/cssicck500.jpg" title="Epitome of awesome" caption="you heard me, shoot" />
</gallery>
	<gallery file="../photos/uploads/cssicck500.jpg" title="Test" caption="this gallery is just a test" images="9">
	<image file="../photos/uploads/51716042_l.jpg" title="Hawaii" caption="hawaiians are so hawaiian" />
	<image file="../photos/uploads/51801565_l.jpg" title="Wide-eyed wes" caption="what the..." />
	<image file="../photos/uploads/142391447_l.jpg" title="Mr. moves" caption="so flamboyant" />
</gallery>
</photos>

and for each gallery item in the xml code…it defines the “gallery” array…each item in the array is one gallery…and inside that item is all the information for that gallery…here is what the array now looks like after this loop:
gallery[["…/photos/uploads/cssicck500.jpg", “Awesomenessssssss”, “we’re cooler than you”, 0]["…/photos/uploads/cssicck500.jpg", “Test”, “this gallery is just a test”, 1]]
so now…it attaches the gallery for every item in the gallery array and gives it the correct information for each gallery…(file, title, caption, and id);
and then it defines an onRelease = function for the “view” text button inside the gallery item… and inside this function it calles on the next main function in the movie “loadImages(number)” which in this case is loadImages(id);
so in the case that i pressed the first gallery item…id would be 0 and therefore “number” would be 0 which would make the next peice of code:

function parseXML(xmlDoc) {
for (i in xmlDoc.firstChild.childNodes[number].childNodes) {
file = xmlDoc.firstChild.childNodes[number].childNodes*.attributes.file;
title = xmlDoc.firstChild.childNodes[number].childNodes*.attributes.title;
caption = xmlDoc.firstChild.childNodes[number].childNodes*.attributes.caption;
images* = [];
images* = [file, title, caption];
}
}

be the following:

function parseXML(xmlDoc) {
for (i in xmlDoc.firstChild.childNodes[0].childNodes) {
file = xmlDoc.firstChild.childNodes[0].childNodes*.attributes.file;
title = xmlDoc.firstChild.childNodes[0].childNodes*.attributes.title;
caption = xmlDoc.firstChild.childNodes[0].childNodes*.attributes.caption;
images* = [];
images* = [file, title, caption];
}
}

but the problem is…it doesn’t do this correctly…for example…right now in the xml code i have two galleries…one have 8 images and the otehr has three…if you press on the gallery that has 3 images first…it’ll display three images like it should…and you go back…everything still working good…you press on the other gallery…it displays 8 images like it should…still all going good…but when you go back after pressing that gallery is where the problem starts…now no matter which gallery you press, it always displays the gallery with 8 images…and it always seems to do this…sticking with the gallery that has the most images in it…any idea as to why its doing this?

(oh and by the way…there are a few other flaws in the script like for instance, i can’t find any way to make it so that flash automatically detects when a new row of images needs to be started, so when i need a new row, i need to tell flash myself when to start a new row…so thats a flaw, and also the size of the images is a problem…when i make the thumbnails its always gonna scale the images down to 10% of the original size…which means if i upload a small image the thumbnail size will be extremely small…and there are a few others i can’t think of…so can someone please help me?)


that was my original problem…but now i found out whats wrong! look go here [color=#22229c]http://cutshallow.com/test[/color]

and go to the photos section…while your there look at the galleries…i made a test xml file with one gallery with one blank image…another gallery with three blank images and one images and then a third gallery with four blank images and one image…now take a look at what happens when you press on the third image and then the second…that one picture is still there…which means the images aren’t being deleted as they should…even though at the beginning of my functions in the code i have it unload the movies…so does anyone have any ideas as to why this is happening? and how i can fix it?