# XML Gallery with category

**URL:** https://forum.kirupa.com/t/xml-gallery-with-category/263513
**Category:** flash
**Created:** [June 16, 2008, 7:50pm UTC](https://forum.kirupa.com/t/xml-gallery-with-category/263513 "2008-06-16T19:50:41Z")
**Posts on this page:** 11
**Page:** 1

<div class="post-metadata">

### Author: ![ndableg](https://avatars.discourse-cdn.com/v4/letter/n/d78d45/32.png) [@ndableg](https://forum.kirupa.com/u/ndableg)
#### Post date: [June 16, 2008, 7:50pm UTC](https://forum.kirupa.com/t/xml-gallery-with-category/263513/1 "2008-06-16T19:50:41Z")

</div>

Hi,

I made a gallery with some categories. For example: 4 photo’s in category 1, 2 photo’s in category 2, etc. Therefore, I make the xml like this:

```auto
<?xml version="1.0" encoding="UTF-8"?>
<gallery>
	<picture category="Category 1">
		<image thumbs="thumbs/img1.jpg"/>
		<image thumbs="thumbs/img2.jpg"/>
		<image thumbs="thumbs/img3.jpg"/>
		<image thumbs="thumbs/img4.jpg"/>
	</picture>
	<picture category="Category 2">
		<image thumbs="thumbs/img5.jpg"/>
		<image thumbs="thumbs/img6.jpg"/>
	</picture>
</gallery>

```

And I simply attach the category button:

```auto
var category:Array = new Array();
var myXML:XML = new XML();
myXML.ignoreWhite = true;
myXML.load("images.xml");

myXML.onLoad = function(success) {
	if (success) {
		for (j=0; j<myXML.firstChild.childNodes.length; j++) {
			var btns:Object = catholder_mc.attachMovie("cat_btn", "cat_btn"+j, j, {_y:(j*110)});
			category.push(myXML.firstChild.childNodes[j].attributes.category);
			btns.cat_txt.text = category[j];
			btns.Value = j;
			var cat = this.firstChild.childNodes[j];
			btns.onRelease = viewLinks;
		}
	} else {
		trace("failed");
	}
};

```

Then the viewLinks function, when a category button is pressed

```auto
function viewLinks() {
	i = this.Value-1;
	if (i<myXML.firstChild.childNodes.length-1) {
		i++;
		allthelinks = myXML.firstChild.childNodes*.childNodes;
		for (k=0; k<allthelinks.length; k++) {
			var img_btn:MovieClip = imgholder_mc.attachMovie("img_btn", "img_btn"+k, k, {_y:(k*30)});
			**img_btn.thumb_holder.loadMovie("myXML.firstChild.childNodes*.childNodes[k].attributes.thumbs");**
			img_btn.Value = k;
			img_btn.onRelease = released;
		}
	}
}

```

So far, the gallery is working. If one of the category button is pressed, the thumbnails of this category appear. However, I have a little bug that I can never solve.

As the example above, if I press on category 1 button, I get 4 thumbnails as it is stated on the xml. However, if I pressed category 2, the 2 thumbnails of category 2 appear, but the 2 thumbnails from category 1 do not disappear. So instead of 2 thumbnails as it is expected, I’ve got 4 thumbnails.

The question is how can I remove those movieclips? I hope it’s clear.

Thank you,  
ndableg

---

<div class="post-metadata">

### Author: ![ndableg](https://avatars.discourse-cdn.com/v4/letter/n/d78d45/32.png) [@ndableg](https://forum.kirupa.com/u/ndableg)
#### Post date: [June 17, 2008, 7:24am UTC](https://forum.kirupa.com/t/xml-gallery-with-category/263513/2 "2008-06-17T07:24:54Z")

</div>

anyone?

---

<div class="post-metadata">

### Author: ![ndableg](https://avatars.discourse-cdn.com/v4/letter/n/d78d45/32.png) [@ndableg](https://forum.kirupa.com/u/ndableg)
#### Post date: [June 17, 2008, 11:30am UTC](https://forum.kirupa.com/t/xml-gallery-with-category/263513/3 "2008-06-17T11:30:08Z")

</div>

Hmm… it’s kinda idea… But how can I generate frames dynamically?

Perhaps create different empty movieclip for each category?

firewalker: salam kenal

---

<div class="post-metadata">

### Author: ![randomagain](https://avatars.discourse-cdn.com/v4/letter/r/35a633/32.png) [@randomagain](https://forum.kirupa.com/u/randomagain)
#### Post date: [June 17, 2008, 11:36am UTC](https://forum.kirupa.com/t/xml-gallery-with-category/263513/4 "2008-06-17T11:36:13Z")

</div>

how I did it, though not advise able, is have an xml for each cat

the swf loads in the main xml, counts through it regards to cats

creates MCs, and sends an XML link to each MC

the individual MC, then loads the cat XML

_now all pretend like what I just said doesn’t make sense_

[http://hermes.hud.ac.uk/c0568903/carousel14.html](http://hermes.hud.ac.uk/c0568903/carousel14.html)

---

<div class="post-metadata">

### Author: ![bnns](https://avatars.discourse-cdn.com/v4/letter/b/5e9695/32.png) [@bnns](https://forum.kirupa.com/u/bnns)
#### Post date: [June 18, 2008, 6:30am UTC](https://forum.kirupa.com/t/xml-gallery-with-category/263513/5 "2008-06-18T06:30:57Z")

</div>

“myXML.firstChild.childNodes\*.childNodes[k].attributes.thumbs”

you’ve converted this to a string which means it looking for a file in that location… which is probably not there.

what you want to say is: img\_btn.thumb\_holder.loadMovie(myXML.firstChild.childNodes\*.childNodes[k].attributes.thumbs);

or you can try this as well:  
img\_btn.thumb\_holder.loadMovie(new String(myXML.firstChild.childNodes\*.childNodes[k].attributes.thumbs));

instead of reloading the xml, you could try storing the nfo into an Object.

var obj:Object = new Object();  
obj[img] = “location”;

then remove them and reload them when necessary…

---

<div class="post-metadata">

### Author: ![ndableg](https://avatars.discourse-cdn.com/v4/letter/n/d78d45/32.png) [@ndableg](https://forum.kirupa.com/u/ndableg)
#### Post date: [June 18, 2008, 7:24am UTC](https://forum.kirupa.com/t/xml-gallery-with-category/263513/6 "2008-06-18T07:24:44Z")

</div>

[QUOTE=firewalker;2344744]ndableg: salam kenal juga 😛

Yes, kinda like that, creating movie clip for each xml load event. And to destroy the previous one made…[/QUOTE]

Would you explain to me how to detect the previous one?

---

<div class="post-metadata">

### Author: ![ndableg](https://avatars.discourse-cdn.com/v4/letter/n/d78d45/32.png) [@ndableg](https://forum.kirupa.com/u/ndableg)
#### Post date: [June 18, 2008, 7:28am UTC](https://forum.kirupa.com/t/xml-gallery-with-category/263513/7 "2008-06-18T07:28:32Z")

</div>

[QUOTE=bnns;2344751]instead of reloading the xml, you could try storing the nfo into an Object.

var obj:Object = new Object();  
obj[img] = “location”;

then remove them and reload them when necessary…[/QUOTE]

Do you mean obj[img] = img\_btn.thumb\_holder.loadMovie(myXML.firstChild.ch ildNodes\*.childNodes[k].attributes.thumbs);?

Do you mean remove with img\_btn.removeMovieClip?

---

<div class="post-metadata">

### Author: ![randomagain](https://avatars.discourse-cdn.com/v4/letter/r/35a633/32.png) [@randomagain](https://forum.kirupa.com/u/randomagain)
#### Post date: [June 18, 2008, 8:41am UTC](https://forum.kirupa.com/t/xml-gallery-with-category/263513/8 "2008-06-18T08:41:09Z")

</div>

erm I replied to the wrong thread 😛

you have to go through and delete/remove any MC there as well as reset and arrays =[] if used

---

<div class="post-metadata">

### Author: ![bnns](https://avatars.discourse-cdn.com/v4/letter/b/5e9695/32.png) [@bnns](https://forum.kirupa.com/u/bnns)
#### Post date: [June 18, 2008, 3:34pm UTC](https://forum.kirupa.com/t/xml-gallery-with-category/263513/9 "2008-06-18T15:34:49Z")

</div>

[quote=ndableg;2344765]Do you mean obj[img] = img\_btn.thumb\_holder.loadMovie(myXML.firstChild.ch ildNodes\*.childNodes[k].attributes.thumbs);?

Do you mean remove with img\_btn.removeMovieClip?[/quote]

i was referring to the fact that you could store the location for later use of the images rather than reloading the xml, but either way works (that is loading the location via xml or the latter).

I you should be able to remove with the .removeMovieClip method but, that’s pretty unimportant. it all depends on how you want to code it.

obj[img] =“images/random.png”;

---

<div class="post-metadata">

### Author: ![ndableg](https://avatars.discourse-cdn.com/v4/letter/n/d78d45/32.png) [@ndableg](https://forum.kirupa.com/u/ndableg)
#### Post date: [June 21, 2008, 11:37pm UTC](https://forum.kirupa.com/t/xml-gallery-with-category/263513/10 "2008-06-21T23:37:29Z")

</div>

Hey guys,  
just letting you know that I’ve solved the problem with for …in loop.

good luck!  
ndableg

---

<div class="post-metadata">

### Author: ![ndableg](https://avatars.discourse-cdn.com/v4/letter/n/d78d45/32.png) [@ndableg](https://forum.kirupa.com/u/ndableg)
#### Post date: [June 22, 2008, 7:27am UTC](https://forum.kirupa.com/t/xml-gallery-with-category/263513/11 "2008-06-22T07:27:31Z")

</div>

Firewalker,

In my case, when the category button is pressed, I add this code (in viewLinks function):

```auto
for(var obj:String in imgholder_mc)
{
   if(imgholder_mc[obj] instanceof MovieClip)
   {
      imgholder_mc[obj].removeMovieClip();
   }
}

```

sukses deh…

ndableg
