开发者

Converting a string into a CheckBox

I have a string which is ultimately the id of a CheckBox.

What I need to be able to do is to access the CheckBox's properties from the string

var myChec开发者_如何学JAVAkBox:Object; var myString:String;

myString = "checkbox_1"

myCheckBox = Object(myString); ?!?!

... and then I'd need to get to myCheckBox.selected, and myCheckBox.label etc


easier answer:

if(this.hasOwnProperty(myString) && this[myString] is CheckBox) {
    myCheckBox = this[myString] as CheckBox
}

It's a bit of overcoding (since the as keyword will return a null if it's not a checkbox and you could better handle it that way with potentially less code), but that should do ya. Best of luck.


If you know what DisplayObjectContainer (e.g. Sprite, MovieClip) the CheckBox is inside you can use getChildByName.

Unfortunately if you are using Flex containers (like Group) there is no function getElementByName(). There is getElementAt so you could write a loop that iterates over all of a Groups elements until it encounters one that matches the name you have.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜