views:

39

answers:

3

Hello
I want to use instances in an array, but get an error. How do I use instances in an array? Thanks.

Error 1010 'A term is undefined and has no properties'

//I'm trying to make two array objects disappear
var pink:Array = ["boxInstance1","boxInstance2"];
/*
THIS WORKS
boxInstance1.visible = false;
boxInstance2.visible = false;
*/
//THIS DON'T 'or with one instance in the array it works'
this[pink].visible = false;
+2  A: 

With one instance in array, flash converts the array into string and you get boxInstance1 as the value; with multiple values array gets converted as boxInstance1,boxInstance2 (possibly) and hence the error. Use the value at correct index using []

this[pink[0]].visible = false;
//equivalent to
boxInstance1.visible = false; 

this[pink[1]].visible = false;
//equivalent to
boxInstance2.visible = false; 

for(var i:Number = 0; i < pink.length; i++)
  this[pink[i]].visible = false;
Amarghosh
How do I get everything to disappear. I tried this[pink[length]].visible = false;
VideoDnd
@Video Loop thru the array - see the update
Amarghosh
+1  A: 

You need to use getChildByName():

var mc:MovieClip = new MovieClip();
mc = getChildByName(pink[0]);
mc.visible = false;

mc = getChildByName(pink[1]);
mc.visible = false;

If you want to do something to all instances, use a for loop:

var mc:MovieClip;
for(var i:int = 0; i < pink.length; i++)
{
    mc = MovieClip(getChildByName(pink[i]));
    mc.visible = false;
}
letseatfood
@letseatfood, that works well
VideoDnd
+1  A: 

Alternately:

var pink:Array = [this.boxInstance1, this.boxInstance2];
for each(var box:Sprite in pink)
    box.visible = false;
Ender
That works great too, thanks:)
VideoDnd