For loop problem and property assignment of object

Related to my other thread on retrieving object names from an array, I’m running into an issue where clips that are dynamically assigned names and attached to a “container” along with a _type property are getting caught up in for… loop being used to sort through all of the clips attached to “container”.


function collectAndSort() {
	for (var obj in container) {
		if (typeof container[obj] == "movieclip") {
			whichType = container[obj]._type;
			whichItem(whichType);
			trace(whichType);
		}
	}
}

the whichItem function looks like this (nothing fancy):


function whichItem (whichType){
	//trace("whichItem function was called");
	if (whichType == "1mc"){
		unitItem.item_id = whichType;
		unitItem.item_name = "Double Door Display";
		unitItem.item_desc = "80 x 96 Display Frame"
		unitItem.item_dimensions = "80 x 96";
		unitItem.unit_price = 100;
	}else if (whichType == "2mc"){
		unitItem.item_id = whichType;
		unitItem.item_name = "Single Door Display";
		unitItem.item_desc = "42 x 96 Display Frame"
		unitItem.item_dimensions = "42 x 96";
		unitItem.unit_price = 85;
	}else if (whichType == "3mc"){
		unitItem.item_id = whichType;
		unitItem.item_name = "Side Window Right";
		unitItem.item_desc = "Side Window Panel With Right Window"
		unitItem.item_dimensions = "30 x 96";
		unitItem.unit_price = 150;
	}else if (whichType == "4mc"){
		unitItem.item_id = whichType;
		unitItem.item_name = "Beam";
		unitItem.item_desc = "Vertical Connector Beam"
		unitItem.item_dimensions = "12 x 96";
		unitItem.unit_price = 75;
	}else if (whichType == "5mc"){
		unitItem.item_id = whichType;
		unitItem.item_name = "Side Window Left";
		unitItem.item_desc = "Side Window Panel With Left Window"
		unitItem.item_dimensions = "30 x 96";
		unitItem.unit_price = 150;
	}else if (whichType == "6mc"){
		unitItem.item_id = whichType;
		unitItem.item_name = "Shelf";
		unitItem.item_desc = "Brochure Display Shelf"
		unitItem.item_dimensions = "24 x 48";
		unitItem.unit_price = 100;
	}else if (whichType == "7mc"){
		unitItem.item_id = whichType;
		unitItem.item_name = "Poster Panel lg";
		unitItem.item_desc = "Large Top Mounted Poster Panel"
		unitItem.item_dimensions = "80 x 24";
		unitItem.unit_price = 40;
	}else if (whichType == "8mc"){
		unitItem.item_id = whichType;
		unitItem.item_name = "Poster Panel sm";
		unitItem.item_desc = "Small Top Mounted Poster Panel"
		unitItem.item_dimensions = "0 x 24";
		unitItem.unit_price = 40;
	}
	_root.purchaseArray.push(unitItem);
}

And just for reference, here’s how those pesky clips got there (again, posted in a previous thread):


for (k=1; k<9; k++) {
	this["btn"+k].kvar = k;
	this["btn"+k].onPress = function() {
		getclips(this.kvar);
		trash.enabled = true;
		btn_trash_all.enabled = true;
	};
}


/******************************************************************************
   Clip handling: attaching, dragging and also tracking (via "reportMe")	
******************************************************************************/   
function getclips(l) {
	clip = container.attachMovie(l+"mc", "mc"+i, i);
	clip._type = l+"mc";// "_type" property used for clip type comparisons
	reportMe = clip;
	myType = reportMe._type;
	//trace(reportMe._type);
	addSubtotal(myType);
	clip.k = l;
	clip._x = 180;
	clip._y = 180;
	clip.onPress = doDrag;
	clip.onRelease = clip.onReleaseOutside=noDrag;
	cliparray.push(clip);
	clip.ivar = i;
	i++;
}

Now when I run it and attach a few clips, I get their proper _type, but whichType is assigned the same thing for each(?). Here’s what I get in a trace after dragging out 3 clips and calling the collectAndSort function:


6mc
4mc
2mc
Single Door Display
Single Door Display
Single Door Display

clip 6mc, 4mc, and 2mc are correct but the matching for a text output via whichItem isn’t and it’s called in that for… loop. They shouldn’t each be matched to “Single Door Display”.
I’m thinking this needs to be approached differently but I don’t have the option of writing out (php or whatever) and then reading back in to to split etc. (was reading the “best of” archives as saw a great one on this).

So, here’s my tangled mess. I know that it is at least getting that far which is encouraging, just that the final sorting through to populate a text field as a purchase list gives me a match for the first clip attached (ie “Single Door Display”).

Later edit…sorry forgot to mention that “Single Door Display” string comes from the unitItem.item_name property matched in the whichItem function (also shown above).

Can anybody help out a guy in over his head? :huh: