Search code examples
actionscript-3flash-cs4

Flash AS3 - Loop - dynamically hide set of text boxes


I need a function to hide a group of text boxes, I wrote the following to do so -

var allTxtBoxes:Array = ["title_txt","l1_txt","l2_txt","l3_txt","l4_txt","l5_txt"]; 


for(var i:Number = allTxtBoxes.length - 1; i >= 0; i--) {


var hiddenT:String = "newOverlibTxt."+allTxtBoxes[i]
              hiddenT.visible=false;;

    }

I have tried the above in various ways including creating a variable but I just get errors to say that I cant apply visible=false to a string, although I want it to act like an object.

Any ideas please?

Cheers Paul


Solution

  • You could try something along the lines of:

    var allTxtBoxes:Array = ["title_txt","l1_txt","l2_txt","l3_txt","l4_txt","l5_txt"]; 
    for(var i:Number = allTxtBoxes.length - 1; i >= 0; i--) {
        newOverlibTxt[allTxtBoxes[i]].visible = false;
    }
    

    In your original code you are trying to set the visible property on a string, which of course doesn't have it. In the above code I am referencing the newOverlibTxt object and using the bracket syntax to pull out the property based on the name.

    This is a bit of a guess, as I am not sure what scope this snippet is in, so newOverlibTxt might not be available.