I am having a AS code problem!? eek!

I have a Flash movie that is displaying “results” that are based on data loaded in from an XML file. Based on the data from the XML file it iterates through the “brands” and attaches a movie clip based on how many of that brand exist and how many are in each row.

I want the movie to display like this::

if 3 brands exist for instance lets say the first brand has 4 results, the second brand has 2 results, and the third brand has 3 results.

brand1 # # #
brand1 #
brand2 # #
brand3 # # #

Notice I only can have 3 across for any particular brand, so there will be a tag that reads “brand1” on both the first AND second row.

Here is my code that iterates through the nodes and ATTEMPTS (lol) to place the correct brandTag in the correct row::


  // rowCount is based on the num of rows req.  ie.11
	b = 0;
	inLoop = 1;
	while (b<rowCount) {
		newTag();
		if (inLoop == 1 && b == 0) {
			brand = this.couponNode.childNodes[0].attributes.name;
			this.brandTag.gotoAndStop(brand);
		} else if (inLoop == 1 && this.couponNode.childNodes**.childNodes.length<3) {
			brand = this.couponNode.childNodes**.attributes.name;
			this.brandTag.gotoAndStop(brand);
		}
		if (this.couponNode.childNodes**.childNodes.length>3) {
			if (inLoop == 0) {
				inLoop == 1;
				trace("GOT HERE");
			}
			if (inLoop == 1) {
				brand = this.couponNode.childNodes**.attributes.name;
				this.brandTag.gotoAndStop(brand);
				trace("ITS LONG");
				inLoop = 0;
			}
		}
		if (inLoop == 0) {
			b--;
			brand = this.couponNode.childNodes**.attributes.name;
			this.brandTag.gotoAndStop(brand);
			b++;
		}
		this.brandTag.gotoAndStop(brand);
		trace("Compare Brand =="+brand);
		trace("B=="+b);
		b++;
		newCounter++;
	}


Here is the code for that newTag() function::


function newTag(brand) {
	brandTag = this.brandHolder_mc.attachMovie("brand", "brand"+newCounter, newCounter);
	if (loop == 0) {
		brandY = 0;
	} else {
		brandY += 180;
	}
	brandTag._y = brandY;
	loop++;
}

This code works in all instances EXCEPT for when 2 or more brands exist that contain more than 3 results.

I am not sure if any other code is necessary for help with this, if so please let me know!!!

Thanks in advance for any help!
:b: