2

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

Ryan Guill
  • 13,558
  • 4
  • 37
  • 48
Dancer
  • 17,035
  • 38
  • 129
  • 206

2 Answers2

1

If the text boxes are in a container, you could loop over the containers children and set the visible property on each. Let me know if you need more information and ill try to whip up an example.

UPDATE:

If it is a movieclip, try something like this:

public function setAllChildrenAsInvisible ( mc:MovieClip ) : void
{
    for ( var i:int = 0; i < mc.numChildren; i++ )
    {
        var tempNewOverlibTxt:newOverlibTxt = mc.getChildAt(i) as newOverlibTxt;
        tempNewOverlibTxt.visible = false;
    }
}

Now I haven't been able to test this code, but the concept should work for you. If you do not want to set all of the children to invisible, you can add an if or switch statement and compare the tmpNewOverlibTxt's id to your list.

Ryan Guill
  • 13,558
  • 4
  • 37
  • 48
  • sounds good - but I'm not sure how to go about it really - They are all in a movieclip with a class of newOverlibTxt. – Dancer Nov 18 '10 at 14:04
0

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.

martineno
  • 2,623
  • 17
  • 14