Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

XML Looping / variable strangeness 1

Status
Not open for further replies.

Leozack

MIS
Oct 25, 2002
867
0
0
GB
Hi all - been rather dumbfounded by the following behaviour in F6MX when looping through XML. My loop is similar to this
Code:
do {
	//trace ("nodename = "+itemNode.nodeName);
	if (itemNode.nodeName == "item") {
		itemType = itemX = itemY= itemTextID = itemImageID = itemURL = "";
		itemNum ++;
		itemType = Number(itemNode.attributes.type);
		itemX = Number(itemNode.attributes.x);
		itemY = Number(itemNode.attributes.y);
		//if (itemNode.attributes.textid != null) { itemTextID = Number(itemNode.attributes.textid); } else { itemTextID = ""; }
		itemTextID = Number(itemNode.attributes.textid);
		//if (itemNode.attributes.imageid != null) { itemImageID = Number(itemNode.attributes.imageid); } else { itemImageID = ""; }
		itemImageID = Number(itemNode.attributes.imageid);
		//if (itemNode.attributes.url != null) { itemURL = itemNode.attributes.url; } else { itemURL = ""; }
		itemURL = itemNode.attributes.url;
		//trace ("type: "+itemType+", x: "+itemX+", y: "+itemY+", textid: "+itemTextID+", imageid: "+itemImageID);
		switch(itemType){
			case 1: // Infopoint
				var thisItem_mc = imgItemsMC.attachMovie("info_mc", "Item_mc"+itemNum,itemNum);
				thisItem_mc._xscale = thisItem_mc._yscale = iconScale;
				thisItem_mc._alpha = iconAlpha;
				thisItem_mc._x = itemX;
				thisItem_mc._y = itemY;
				trace ("x : "+itemX+", y: "+itemY+", textid: "+itemTextID+", imageid: "+itemImageID);
				if (bInfoBox) {
					thisItem_mc.onRollOver = thisItem_mc.onDragOver = function(){
						SetText(infoMC.info_text, Text_arr[itemTextID], infoTF);
					}
					thisItem_mc.onRollOut = thisItem_mc.onDragOut = function(){
						SetText(infoMC.info_text, imageNode.firstChild.firstChild, infoTF);
					}
				}
			break;
If this line runs
//trace ("type: "+itemType+", x: "+itemX+", y: "+itemY+", textid: "+itemTextID+", imageid: "+itemImageID);
it successflly writes out all items in a list
When this line runs
trace ("x : "+itemX+", y: "+itemY+", textid: "+itemTextID+", imageid: "+itemImageID);
it successfully writes out the list of items as it goes through.
However ... when the onRollOver or onRelease actions fire off - they all use the variables associated with the final one. ie - if the final one was using textID 2 then all of them use textID 2. Text_Arr is just a number=value array of text entries to use. I've narrowed the problem down to it being the last one they always use, but nothing I do seems to make them use the right one. Any ideas? :/

_________________________________
Leozack
Code:
MakeUniverse($infinity,1,42);
 
I've tried to do what I think you're saying and I'm not getting any joy :/ Could you elaborate a little? (yes somedays I need the dummy's version) :p

_________________________________
Leozack
Code:
MakeUniverse($infinity,1,42);
 
Ok so I added the line
thisItem_mc.itemTextID = itemTextID;
after the line
thisItem_mc._y = itemY;
and then changed the line
SetText(infoMC.info_text, Text_arr[itemTextID], infoTF);
to be
SetText(infoMC.info_text, Text_arr[this.itemTextID], infoTF);
and ... it seems to be working!

That's great, thanks :) But ... I don't know why -_-' Without understanding it I'll probably have similar problems later, so an elaboration would be greatful :) I trace'd "this" at that point in the code and it said level0, rather than the thisItem_mc or anything I expected

_________________________________
Leozack
Code:
MakeUniverse($infinity,1,42);
 
The reason why your original code wasn't working is simple:

Say when you rollover the MovieClip [tt]Item_mc1[/tt], Flash looks for the variable [tt]itemTextID[/tt] in the current "scope". The current scope is the MovieClip [tt]Item_mc1[/tt] because this is a rollover script for that MovieClip. (This is different in AS3 by the way.) But Flash cannot find [tt]itemTextID[/tt] in [tt]Item_mc1[/tt], so it starts looking for one in parents. Eventually it finds [tt]itemTextID[/tt] in _root (or [tt]imgItemsMC[/tt] - I don't know where your code lives) and uses that value. But the value has changed long before, because the rollover happens after your loop has run. So the value Flash uses is the last value used in the loop.

Does this make sense?

Kenneth Kawamoto
 
So the point is the line I give saying
"on rollover - lookup VARIABLE contents here", the VARIABLE part isn't decoded until the rolloverhappens - I thought the VARIABLE would get translated to the urrent thing for each thingI made a rollover for, and thus the STORED value for the rollover would include the individual item, not a reference to it that gets looked up later once it's changed

o.o thank for the explanation ... now if only my other issues would go ...

_________________________________
Leozack
Code:
MakeUniverse($infinity,1,42);
 
Having said that, I don't see how this. helps. I tried thisItem_mc. instead but that didn't work. If I trace 'this' at the point I set the textID to be a variable of thisItem_mc, it traces "level0". And when the rollover is decoded later, "this" surely can't refer to thisITem_mc can it? Or does it, due to the fact that that is the MC we're rolling over - and thus - the this. works because it's in the code for that movieclips rollover and so will always decode later to that movieclip, nothing to do with designtime, but runtime?

Now I just gotta sort these :/


/sleep

_________________________________
Leozack
Code:
MakeUniverse($infinity,1,42);
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top