if i have several instances of a mc with names such as BR1, BR2… BR10 or whatever, how do i write a for loop that will cycle through them all?
You can something like this:
for(i = 1; i <= 10; i++)
{
mc = this["BR" + i];
trace(mc._x);
}
Or something like this, if you dont have an instance name:
for(obj in this) // get all objects
{
if(obj instanceof MovieClip) // only movieclip
{
trace(this[obj]._x);
}
}
what if i wanted give a set of variables a value using a for loop?
This is a notation and can be used to access variables much the way you do with your standard dot notation. So you can essentially do it the same as with dot notation. Just making sure that you are using subscript correctly…
var myVar0:Number;
var myVar1:Number;
var myVar2:Number;
var myVar3:Number;
var myVar4:Number;
for (var i:Number=0; i<5; i++)
{
this["myVar"+i] = Math.random() * 10;
}
If you have any questions feel free to ask.
TakeCare
_Michael