Confusing 'for' loop results

Hey guys,

I’m a graphic designer who’s just dived headfirst into Flash, it’s only been a week and a bit, so no doubt this is very obvious, and probably a case of trying to run before I can walk!

I’m trying to import XML data into an MC to populate a menu… Kinda like the Portfolio XML sample tutorial on this site, but with a menu of different companies to choose from before their respective thumbnails appear.

So… I’ve been determined to do this myself, but I have admitted defeat on the following. Here’s my AS:

var description_lv = new LoadVars();
description_lv.onData = function(raw_text){
	descriptionText.text = raw_text;
}

var xPos = 0;
var yPos = 0;


function CreatePortMenu(port_xml){
	var portClients = port_xml.firstChild.childNodes;
	
	for ( var p = 0; p < portClients.length; p++ )
	{
		var currentClient = portClients[p];
		
		var xSpacing:Number = 90;
		var ySpacing:Number = 35;

		var portHold = portHolder_mc.attachMovie( "jobOption", "pb"+p, p, {_x:xPos, _y:yPos});
		
		portHold.jobTitle.jobText.text = currentClient.attributes.title;
		
		switch (p) {
			case 0:
			case 1:
			case 2:
			case 3:
			yPos = ySpacing * p;
			break;
			case 4:
			case 5:
			case 6:
			case 7:
			xPos = xSpacing * 2;
			yPos = ySpacing * (p - 4);
			break;
			case 8:
			case 9:
			case 10:
			case 11:
			xPos = xSpacing * 3;
			yPos = ySpacing * (p - 8);
		}
		
	}
	
}


var port_xml = new XML();
port_xml.ignoreWhite = true;
port_xml.onLoad = function(success) {
	if (success)
		CreatePortMenu(this);
		else trace("Error loading XML...");
}



//load the XML
port_xml.load("portfolio1.xml");

The main problem is that, altho the “pb” instances are all given the right number (ie, I currently have 6 clients listed in the XML, so I get “pb0” through to “pb5”), the positioning values (xPos, yPos) seem to be being multiplied by (“p” minus 1), eg - “pb1” has the xPos and yPos you’d expect of “pb0”, and likewise “pb4” that of what “pb3” should be.

So, how come, if the right value of “p” is being assigned to the mc’s, that it’s not being used in the rest of the loop?

BTW - The ‘switch’ part is designed to list them in columns of 4 (there will never be more than 12), which seems a bit unwieldy, but I couldn’t think of a more elegant solution as yet.

Thanks for your help,

Olly