开发者

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 = "newOverli开发者_运维技巧bTxt."+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


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.


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜