Tutorial :use instance names in array, #1010 error, as3


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;  


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;  



var pink:Array = [this.boxInstance1, this.boxInstance2];  for each(var box:Sprite in pink)      box.visible = false;  


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;  }  

Note:If u also have question or solution just comment us below or mail us on toontricks1994@gmail.com
Next Post »