'For' loop not changing ._y variable

I have the following code:


on (release) {
	cNum = cNum+1;
	for (b=1; b<8; b++) {
		trace(["box"+b]);
		["btn"+b]._y = ["btn"+b]._y+25;
		["txt"+b]._y = ["txt"+b]._y+25;
		["box"+b]._y = ["box"+b]._y+25;
		trace(["box"+b]);
		trace(["box"+b]._y);
	}
}

on release, the objects labeled btn1, txt1, box1, btn2… should all be shifting 25pxs. It doesnt do anything. I cant see why.

Does anyone see the problem?

Thanks so much

~ Lacuna aka Seretha :love:

What are the traces returning?


box1
box1
undefined
box2
box2
undefined
box3
box3
undefined
box4
box4
undefined
box5
box5
undefined
box6
box6
undefined
box7
box7
undefined

when the ._y is added to the equation, it shows as undefined…

[] does two things, makes arrays and provides array access of properties of objects

as [] it makes an array
as object[“property”] it retrieves a property (or an object defined as property in object).

What you are making are arrays. What you want are references to your btn, txt and box objects to which you can then reference the _y property of them. To do this, you need the object in which they live object[property]. In your case, its probably this.

this[“box”+b]._y = this[“box”+b]._y+25;
or
this[“box”+b]._y += 25;

thank you senocular!! you have yet again prooved to be amazing :wink:

Thanks again, works great. Thank you also for you excellent explaination of why it was not functioning.

~ Lacuna aka Seretha :love:

welcome Seretha :pleased: