I have variable names stored in an array, and I want to loop through array and set the visible property of that instance to false. However, I’m getting error;
Error #1056: Cannot create property visible on String.
Here is my code:
package {
import flash.events.TouchEvent;
import flash.ui.Multitouch;
import flash.ui.MultitouchInputMode;
import flash.display.MovieClip;
import flash.events.MouseEvent;
public class touch extends MovieClip
{
public function touch()
{
var menuitems:Array = new Array("menu_One", "menu_Two", "menu_Three", "menu_Three", "menu_Four", "menu_Five");//array with instance names
for(var i:int=0;i<6;i++){
var tempName = menuitems[i];
bsF_txt.text = tempName;
trace(tempName);
tempName.visible = false;
//menu_One.visible = false;
}
}
}
}
Is. what I’m trying to do possible in AS3?
Try using the following code (I just noticed you said those are instance names…)
The main change is that you need to tell flash that the string in your array is an instance name. So use
getChildByNameassuming they are added to to the stage.The reason your current code is failing is because you are trying to access the visible property on a String, but
Stringdoes not have avisibleproperty. But the actually instance of that string name might.