Another Flash - XML problem!

Hi experts :slight_smile:

OK, I’ve bought an XML portfolio from FlashDen and am trying to get it to work with my particular requirements.

However, my AS2 isn’t great. I’m halfway there - I can now get the categories to display correctly but when I click on one I can’t get the actual category to load and display the images. I’m not sure where my code is wrong - whether it’s the childNodes hierarchy or earlier on in the script…

Here’s a small snippet of the XML:
[SIZE=1][COLOR=darkred]<?xml version=“1.0” encoding=“iso-8859-1”?>[/COLOR][/SIZE]
[SIZE=1][COLOR=darkred]<gallery>[/COLOR][/SIZE]
[SIZE=1][COLOR=darkred]<category>[/COLOR][/SIZE]
[SIZE=1][COLOR=darkred]<title><![CDATA[CATEGORY ONE]]></title>[/COLOR][/SIZE]
[SIZE=1][COLOR=darkred]<image>[/COLOR][/SIZE]
[SIZE=1][COLOR=darkred]<title><![CDATA[Abstract image 1]]></title>[/COLOR][/SIZE]
[SIZE=1][COLOR=darkred]<date><![CDATA[January 2008]]></date>[/COLOR][/SIZE]
[SIZE=1][COLOR=darkred]<description><![CDATA[Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Etiam sed urna. Vestibulum ante ipsum primis in faucibus orci luctus et ultrices posuere cubilia Curae; Mauris tempus luctus sem. Cras facilisis lectus. Aliquam nisi orci, imperdiet sed, tincidunt eget, rutrum at, urna. Praesent dolor nulla, lobortis varius, sodales sed, dictum in, odio]]></description>[/COLOR][/SIZE]
[SIZE=1][COLOR=darkred]<img>img/abstract2/img1.jpg</img>[/COLOR][/SIZE]
[SIZE=1][COLOR=darkred]</image>[/COLOR][/SIZE]
[SIZE=1][COLOR=darkred]</category>[/COLOR][/SIZE]

[SIZE=1][COLOR=darkred]<category> [/COLOR][/SIZE]
[SIZE=1][COLOR=darkred]<title><![CDATA[CATEGORY TWO]]></title>[/COLOR][/SIZE]
[SIZE=1][COLOR=darkred]<image>[/COLOR][/SIZE]
[SIZE=1][COLOR=darkred]<title><![CDATA[Abstract image 1]]></title>[/COLOR][/SIZE]
[SIZE=1][COLOR=darkred]<date><![CDATA[January 2008]]></date>[/COLOR][/SIZE]
[SIZE=1][COLOR=darkred]<description><![CDATA[Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Etiam sed urna. Vestibulum ante ipsum primis in faucibus orci luctus et ultrices posuere cubilia Curae; Mauris tempus luctus sem. Cras facilisis lectus. Aliquam nisi orci, imperdiet sed, tincidunt eget, rutrum at, urna. Praesent dolor nulla, lobortis varius, sodales sed, dictum in, odio]]></description>[/COLOR][/SIZE]
[SIZE=1][COLOR=darkred]<img>img/abstract3/img1.jpg</img>[/COLOR][/SIZE]
[SIZE=1][COLOR=darkred]</image>[/COLOR][/SIZE]
[SIZE=1][COLOR=darkred]<image>[/COLOR][/SIZE]
[SIZE=1][COLOR=darkred]<title><![CDATA[Abstract image 2]]></title>[/COLOR][/SIZE]
[SIZE=1][COLOR=darkred]<date><![CDATA[February 2008]]></date>[/COLOR][/SIZE]
[SIZE=1][COLOR=darkred]<description><![CDATA[Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Etiam sed urna. Vestibulum ante ipsum primis in faucibus orci luctus et ultrices posuere cubilia Curae; Mauris tempus luctus sem. Cras facilisis lectus. Aliquam nisi orci, imperdiet sed, tincidunt eget, rutrum at, urna. Praesent dolor nulla, lobortis varius, sodales sed, dictum in, odio]]></description>[/COLOR][/SIZE]
[SIZE=1][COLOR=darkred]<img>img/abstract3/img2.jpg</img>[/COLOR][/SIZE]
[SIZE=1][COLOR=darkred]</image>[/COLOR][/SIZE]
[SIZE=1][COLOR=darkred]</category>[/COLOR][/SIZE]

And here’s the AS2 which is calling up the above:
[SIZE=1][COLOR=darkslateblue]readCategory ();[/COLOR][/SIZE]
[SIZE=1][COLOR=darkslateblue]//[/COLOR][/SIZE]
[SIZE=1][COLOR=darkslateblue]function readCategory () {[/COLOR][/SIZE]
[SIZE=1][COLOR=darkslateblue]categoryContainer._x = categoryContainerPosX;[/COLOR][/SIZE]
[SIZE=1][COLOR=darkslateblue]categoryContainer._y = categoryContainerPosy;[/COLOR][/SIZE]
[SIZE=1][COLOR=darkslateblue]//[/COLOR][/SIZE]
[SIZE=1][COLOR=darkslateblue]System.useCodepage = true;[/COLOR][/SIZE]
[SIZE=1][COLOR=darkslateblue]var category:XML = new XML ();[/COLOR][/SIZE]
[SIZE=1][COLOR=darkslateblue]category.ignoreWhite = true;[/COLOR][/SIZE]
[SIZE=1][COLOR=darkslateblue]category.onLoad = function (success) {[/COLOR][/SIZE]
[SIZE=1][COLOR=darkslateblue]if (success) {[/COLOR][/SIZE]
[SIZE=1][COLOR=darkslateblue]var root:XMLNode = this.firstChild;[/COLOR][/SIZE]
[SIZE=1][COLOR=darkslateblue]totalItems = root.childNodes.length;[/COLOR][/SIZE]
[SIZE=1][COLOR=darkslateblue]for (i = 0; i < root.childNodes.length; i++) {[/COLOR][/SIZE]
[SIZE=1][COLOR=darkslateblue]var xCategory:String = root.childNodes*.childNodes[0].childNodes[0].nodeValue;[/COLOR][/SIZE]
[SIZE=1][COLOR=darkslateblue]var xCategoryId:Number = i;[/COLOR][/SIZE]
[SIZE=1][COLOR=darkslateblue]categoryContainer.attach.attachMovie (“category”,“category” + i,i);[/COLOR][/SIZE]
[SIZE=1][COLOR=darkslateblue]categoryContainer.attach[“category” + i]._y = i * ySpacerCategory;[/COLOR][/SIZE]
[SIZE=1][COLOR=darkslateblue]categoryContainer.attach[“category” + i].categoryMc.categoryTitle.text = xCategory;[/COLOR][/SIZE]
[SIZE=1][COLOR=darkslateblue]//[/COLOR][/SIZE]
[SIZE=1][COLOR=darkslateblue]categoryContainer.attach[“category” + i].bt.nodeInstance = xCategoryId;[/COLOR][/SIZE]
[SIZE=1][COLOR=darkslateblue]categoryContainer.attach[“category” + i].bt.onRelease = function () {[/COLOR][/SIZE]
[SIZE=1][COLOR=darkslateblue]nodeCategoryLoad = this.nodeInstance;[/COLOR][/SIZE]
[SIZE=1][COLOR=darkslateblue]openGallery ();[/COLOR][/SIZE]
[SIZE=1][COLOR=darkslateblue]};[/COLOR][/SIZE]
[SIZE=1][COLOR=darkslateblue]}[/COLOR][/SIZE]
[SIZE=1][COLOR=darkslateblue]if (totalItems > 10) {[/COLOR][/SIZE]
[SIZE=1][COLOR=darkslateblue]startMovement ();[/COLOR][/SIZE]
[SIZE=1][COLOR=darkslateblue]delete categoryContainer.onEnterFrame;[/COLOR][/SIZE]
[SIZE=1][COLOR=darkslateblue]}[/COLOR][/SIZE]
[SIZE=1][COLOR=darkslateblue]else {[/COLOR][/SIZE]
[SIZE=1][COLOR=darkslateblue]delete categoryContainer.onEnterFrame;[/COLOR][/SIZE]
[SIZE=1][COLOR=darkslateblue]Mouse.removeListener (mouseListener);[/COLOR][/SIZE]
[SIZE=1][COLOR=darkslateblue]}[/COLOR][/SIZE]
[SIZE=1][COLOR=darkslateblue]}[/COLOR][/SIZE]
[SIZE=1][COLOR=darkslateblue]};[/COLOR][/SIZE]
[SIZE=1][COLOR=darkslateblue]category.load (“gallery.xml”);[/COLOR][/SIZE]
[SIZE=1][COLOR=darkslateblue]}[/COLOR][/SIZE]
[SIZE=1][COLOR=darkslateblue]//************************************************************************************************************[/COLOR][/SIZE]
[SIZE=1][COLOR=darkslateblue]function readImage () {[/COLOR][/SIZE]
[SIZE=1][COLOR=darkslateblue]//[/COLOR][/SIZE]
[SIZE=1][COLOR=darkslateblue]System.useCodepage = true;[/COLOR][/SIZE]
[SIZE=1][COLOR=darkslateblue]var image:XML = new XML ();[/COLOR][/SIZE]
[SIZE=1][COLOR=darkslateblue]image.ignoreWhite = true;[/COLOR][/SIZE]
[SIZE=1][COLOR=darkslateblue]image.onLoad = function (success) {[/COLOR][/SIZE]
[SIZE=1][COLOR=darkslateblue]if (success) {[/COLOR][/SIZE]
[SIZE=1][COLOR=darkslateblue]var nodeImages:XMLNode = this.firstChild.childNodes[nodeCategoryLoad];[/COLOR][/SIZE]
[SIZE=1][COLOR=darkslateblue]for (i = 0; i < nodeImages.childNodes.length; i++) {[/COLOR][/SIZE]
[SIZE=1][COLOR=darkslateblue]totalImagesNavigation = i;[/COLOR][/SIZE]
[SIZE=1][COLOR=darkslateblue]}[/COLOR][/SIZE]
[SIZE=1][COLOR=darkslateblue]//read[/COLOR][/SIZE]
[SIZE=1][COLOR=darkslateblue]var xTitle:String = nodeImages.childNodes[cursorCategoryLoad].childNodes[1].childNodes[0].nodeValue;[/COLOR][/SIZE]
[SIZE=1][COLOR=darkslateblue]var xDate:String = nodeImages.childNodes[cursorCategoryLoad].childNodes[2].childNodes[0].nodeValue;[/COLOR][/SIZE]
[SIZE=1][COLOR=darkslateblue]var xDescription:String = nodeImages.childNodes[cursorCategoryLoad].childNodes[3].childNodes[0].nodeValue;[/COLOR][/SIZE]
[SIZE=1][COLOR=darkslateblue]var xImage:String = nodeImages.childNodes[cursorCategoryLoad].childNodes[4].childNodes[0].nodeValue;[/COLOR][/SIZE]
[SIZE=1][COLOR=darkslateblue]//write[/COLOR][/SIZE]
[SIZE=1][COLOR=darkslateblue]loadImage (xImage);[/COLOR][/SIZE]
[SIZE=1][COLOR=darkslateblue]info.contents.dateTxt.text = xDate;[/COLOR][/SIZE]
[SIZE=1][COLOR=darkslateblue]info.contents.titleTxt.text = xTitle;[/COLOR][/SIZE]
[SIZE=1][COLOR=darkslateblue]info.contents.descTxt.text = xDescription;[/COLOR][/SIZE]
[SIZE=1][COLOR=darkslateblue]}[/COLOR][/SIZE]
[SIZE=1][COLOR=darkslateblue]};[/COLOR][/SIZE]
[SIZE=1][COLOR=darkslateblue]image.load (“gallery.xml”);[/COLOR][/SIZE]
[SIZE=1][COLOR=darkslateblue]}[/COLOR][/SIZE]
[SIZE=1][COLOR=darkslateblue]//************************************************************************************************************[/COLOR][/SIZE]

As I say, the first bit of AS seems to be working fine - it pulls in the names of the categories and lists the correct amount of categories, but when I click on the category name it just stops, obviously not finding the XML data it’s expecting, and I just cannot work out where the problem is!

Can anyone help? I’m sure it’s obvious to an expert.

Cheers